jenkins-bot has submitted this change and it was merged.

Change subject: Don't propagate permissions to older revisions
......................................................................


Don't propagate permissions to older revisions

Revisions are meant to be a standalone snapshot in time.
Instead of propagating changes in permissions, we should look at the
most recent revision to fetch the current revision state.
Otherwise, we lose track of history. E.g. we can't know if a certain
revision is/was suppressed and should be hidden from sight, if at a
later point, a later revision got restored.

Change-Id: I14f3ecc30cd003e40df110116a44474b6f424ecd
---
M Hooks.php
M includes/Block/Topic.php
M includes/Log/PostModerationLogger.php
M includes/Model/AbstractRevision.php
M includes/Model/Header.php
5 files changed, 25 insertions(+), 79 deletions(-)

Approvals:
  EBernhardson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Hooks.php b/Hooks.php
index 896de24..f1599a1 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -287,7 +287,7 @@
         * @return bool
         */
        public static function onUserGetReservedNames( &$names ) {
-               $permissions = array_keys( Flow\Model\AbstractRevision::$perms 
);
+               $permissions = Flow\Model\AbstractRevision::$perms;
                foreach ( $permissions as $permission ) {
                        $names[] = "msg:flow-$permission-usertext";
                }
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 095c011..f649010 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -30,7 +30,6 @@
        protected $topicTitle;
        protected $rootLoader;
        protected $newRevision;
-       protected $relatedRevisions = array();
        protected $notification;
        protected $requestedPost = array();
 
@@ -273,11 +272,7 @@
 
                $reason = $this->submitted['reason'];
 
-               if ( $post->needsModerateHistorical( $newState ) ) {
-                       $this->relatedRevisions = $this->loadHistorical( $post 
);
-               }
-
-               $this->newRevision = $post->moderate( $this->user, $newState, 
$action, $reason, $this->relatedRevisions );
+               $this->newRevision = $post->moderate( $this->user, $newState, 
$action, $reason );
                if ( !$this->newRevision ) {
                        $this->addError( 'moderate', wfMessage( 
'flow-error-not-allowed' ) );
                        return;
@@ -358,10 +353,6 @@
 
                        $this->storage->put( $this->newRevision );
                        $this->storage->put( $this->workflow );
-                       // These are moderated historical revisions of 
$this->newRevision
-                       foreach ( $this->relatedRevisions as $revision ) {
-                               $this->storage->put( $revision );
-                       }
                        $self = $this;
                        $newRevision = $this->newRevision;
                        $rootPost = $this->loadRootPost();
diff --git a/includes/Log/PostModerationLogger.php 
b/includes/Log/PostModerationLogger.php
index 4a56234..1b4cb34 100644
--- a/includes/Log/PostModerationLogger.php
+++ b/includes/Log/PostModerationLogger.php
@@ -60,7 +60,7 @@
 
                if ( ! $changeTypes ) {
                        $changeTypes = array();
-                       foreach( AbstractRevision::$perms as $perm => $info ) {
+                       foreach( AbstractRevision::$perms as $perm ) {
                                if ( $perm != '' ) {
                                        $changeTypes[] = "{$perm}-topic";
                                        $changeTypes[] = "{$perm}-post";
diff --git a/includes/Model/AbstractRevision.php 
b/includes/Model/AbstractRevision.php
index b49c53d..f471296 100644
--- a/includes/Model/AbstractRevision.php
+++ b/includes/Model/AbstractRevision.php
@@ -18,26 +18,15 @@
        const MODERATED_SUPPRESSED = 'suppress';
 
        /**
-        * Metadata relatied to moderation states from least restrictive
-        * to most restrictive.
+        * List of available permission levels.
+        *
+        * @var array
         **/
        static public $perms = array(
-               self::MODERATED_NONE => array(
-                       // Whether or not to apply transition to this 
moderation state to historical revisions
-                       'historical' => true,
-               ),
-               self::MODERATED_HIDDEN => array(
-                       // Whether or not to apply transition to this 
moderation state to historical revisions
-                       'historical' => false,
-               ),
-               self::MODERATED_DELETED => array(
-                       // Whether or not to apply transition to this 
moderation state to historical revisions
-                       'historical' => true,
-               ),
-               self::MODERATED_SUPPRESSED => array(
-                       // Whether or not to apply transition to this 
moderation state to historical revisions
-                       'historical' => true,
-               ),
+               self::MODERATED_NONE,
+               self::MODERATED_HIDDEN,
+               self::MODERATED_DELETED,
+               self::MODERATED_SUPPRESSED,
        );
 
        protected $revId;
@@ -223,11 +212,7 @@
                return $obj;
        }
 
-       /**
-        * $historical revisions must be provided when 
self::needsModerateHistorical
-        * returns true.
-        */
-       public function moderate( User $user, $state, $changeType, $reason, 
array $historical = array() ) {
+       public function moderate( User $user, $state, $changeType, $reason ) {
                if ( ! $this->isValidModerationState( $state ) ) {
                        wfWarn( __METHOD__ . ': Provided moderation state does 
not exist : ' . $state );
                        return null;
@@ -237,53 +222,31 @@
                if ( !$this->isAllowed( $user, $changeType ) ) {
                        return null;
                }
-               if ( !$historical && $this->needsModerateHistorical( $state ) ) 
{
-                       throw new InvalidInputException( 'Requested state 
change requires historical revisions, but they were not provided.', 
'invalid-input' );
-               }
 
-               $historical[] = $obj = $this->newNullRevision( $user );
-               $historical[] = $this;
-
+               $obj = $this->newNullRevision( $user );
                $obj->changeType = $changeType;
-
-               $timestamp = wfTimestampNow();
-               foreach ( $historical as $rev ) {
-                       if ( !$rev->isAllowed( $user, $changeType ) ) {
-                               continue;
-                       }
-                       $rev->moderationState = $state;
-                       list( $userId, $userIp ) = self::userFields( $user );
-                       if ( $state === self::MODERATED_NONE ) {
-                               $rev->moderatedByUserId = null;
-                               $rev->moderatedByUserIp = null;
-                               $rev->moderationTimestamp = null;
-                       } else {
-                               $rev->moderatedByUserId = $userId;
-                               $rev->moderatedByUserIp = $userIp;
-                               $rev->moderationTimestamp = $timestamp;
-                       }
-               }
 
                // This is a bit hacky, but we store the restore reason
                // in the "moderated reason" field. Hmmph.
                $obj->moderatedReason = $reason;
+               $obj->moderationState = $state;
+
+               list( $userId, $userIp ) = self::userFields( $user );
+               if ( $state === self::MODERATED_NONE ) {
+                       $obj->moderatedByUserId = null;
+                       $obj->moderatedByUserIp = null;
+                       $obj->moderationTimestamp = null;
+               } else {
+                       $obj->moderatedByUserId = $userId;
+                       $obj->moderatedByUserIp = $userIp;
+                       $obj->moderationTimestamp = wfTimestampNow();
+               }
 
                return $obj;
        }
 
        public function isValidModerationState( $state ) {
-               return isset( self::$perms[$state] );
-       }
-
-       public function needsModerateHistorical( $state ) {
-               if ( $this->isFirstRevision() ) {
-                       return false;
-               }
-               if ( !isset( self::$perms[$state]['historical'] ) ) {
-                       wfWarn( __METHOD__ . ": Moderation state does not exist 
: $state" );
-                       return false;
-               }
-               return self::$perms[$state]['historical'];
+               return in_array( $state, self::$perms );
        }
 
        /**
diff --git a/includes/Model/Header.php b/includes/Model/Header.php
index da19a91..f8ef91c 100644
--- a/includes/Model/Header.php
+++ b/includes/Model/Header.php
@@ -44,14 +44,6 @@
        }
 
        /**
-        * Headers are more like wiki pages and as such are moderated
-        * one revision at a time.
-        */
-       public function needsModerateHistorical( $state ) {
-               return false;
-       }
-
-       /**
         * @return UUID
         */
        public function getCollectionId() {

-- 
To view, visit https://gerrit.wikimedia.org/r/112042
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I14f3ecc30cd003e40df110116a44474b6f424ecd
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to