Matthias Mullie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/112042

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(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/42/112042/1

diff --git a/Hooks.php b/Hooks.php
index b63f64f..0fa8b2c 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -268,7 +268,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 2796220..77923dc 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();
 
@@ -286,11 +285,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;
@@ -376,10 +371,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 b3af131..0942bac 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 2f7cfb5..22408bf 100644
--- a/includes/Model/Header.php
+++ b/includes/Model/Header.php
@@ -42,12 +42,4 @@
        public function getWorkflowId() {
                return $this->workflowId;
        }
-
-       /**
-        * Headers are more like wiki pages and as such are moderated
-        * one revision at a time.
-        */
-       public function needsModerateHistorical( $state ) {
-               return false;
-       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I14f3ecc30cd003e40df110116a44474b6f424ecd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to