Matthias Mullie has uploaded a new change for review.

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


Change subject: Fetch moderation status from last revision
......................................................................

Fetch moderation status from last revision

We shouldn't be looking at a certain revision to find if it's suppressed, we
should check the current revision

Change-Id: I497900d469acb6984ca250a141a337910b93c650
---
M FlowActions.php
M includes/Block/Header.php
M includes/Block/Topic.php
3 files changed, 56 insertions(+), 12 deletions(-)


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

diff --git a/FlowActions.php b/FlowActions.php
index 350d161..5a78247 100644
--- a/FlowActions.php
+++ b/FlowActions.php
@@ -476,6 +476,21 @@
                'button-method' => 'GET',
        ),
 
+       'board-history' => array(
+               'performs-writes' => false,
+               'log_type' => false,
+               'permissions' => array(
+                       PostRevision::MODERATED_NONE => '',
+                       PostRevision::MODERATED_HIDDEN => function( 
PostRevision $post, RevisionActionPermissions $permissions ) {
+                                       // visible for logged in users (or 
anyone with hide permission)
+                                       return 
$permissions->getUser()->isLoggedIn() ? '' : 'flow-hide';
+                               },
+                       PostRevision::MODERATED_DELETED => array( 
'flow-delete', 'flow-suppress' ),
+                       PostRevision::MODERATED_SUPPRESSED => 'flow-suppress',
+               ),
+               'button-method' => 'GET',
+       ),
+
        'view' => array(
                'performs-writes' => false,
                'log_type' => false, // don't log views
diff --git a/includes/Block/Header.php b/includes/Block/Header.php
index 31dd3b3..3c7949c 100644
--- a/includes/Block/Header.php
+++ b/includes/Block/Header.php
@@ -137,10 +137,39 @@
                                'historyExists' => false,
                        );
 
-                       $historyRecord = $this->loadBoardHistory();
-                       if ( $historyRecord ) {
+                       $history = $this->loadBoardHistory();
+
+                       // get rid of history entries user doesn't have 
sufficient permissions for
+                       foreach ( $history as $i => $revision ) {
+                               switch( $revision->getRevisionType() ) {
+                                       case 'header':
+                                               // headers can't be moderated
+                                               break;
+                                       case 'post':
+                                               // comments should not be in 
board history
+                                               if ( !$revision->isTopicTitle() 
) {
+                                                       unset( $history[$i] );
+                                               }
+
+                                               // check permissions against 
most recent revision
+                                               // NOTE: code duplicated from 
Topic::loadTopicTitle
+                                               $postId = 
$revision->getPostId();
+                                               $found = $this->storage->find(
+                                                       'PostRevision',
+                                                       array( 
'tree_rev_descendant_id' => $postId ),
+                                                       array( 'sort' => 
'rev_id', 'order' => 'DESC', 'limit' => 1 )
+                                               );
+
+                                               if ( !$found || 
!$this->permissions->isAllowed( reset( $found ), 'board-history' ) ) {
+                                                       unset( $history[$i] );
+                                               }
+                                               break;
+                               }
+                       }
+
+                       if ( $history ) {
                                $tplVars['historyExists'] = true;
-                               $tplVars['history'] = new History( 
$historyRecord );
+                               $tplVars['history'] = new History( $history );
                                $tplVars['historyRenderer'] = new 
HistoryRenderer( $templating, $this );
                        }
 
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 64199c3..6495646 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -359,8 +359,10 @@
                        $history = $this->loadTopicHistory();
 
                        // get rid of history entries user doesn't have 
sufficient permissions for
-                       foreach ( $history as $i => $post ) {
-                               if ( !$this->permissions->isAllowed( $post, 
'topic-history' ) ) {
+                       foreach ( $history as $i => $revision ) {
+                               // check permissions against most recent 
revision
+                               $last = $this->loadRequestedPost( 
$revision->getPostId() );
+                               if ( !$last || !$this->permissions->isAllowed( 
$last, 'topic-history' ) ) {
                                        unset( $history[$i] );
                                }
                        }
@@ -524,13 +526,11 @@
                        return;
                }
 
-               $history = $this->getHistory( $options['postId'] );
-
-               // get rid of history entries user doesn't have sufficient 
permissions for
-               foreach ( $history as $i => $post ) {
-                       if ( !$this->permissions->isAllowed( $post, 
'post-history' ) ) {
-                               unset( $history[$i] );
-                       }
+               $history = array();
+               // don't show post history if user doesn't have permissions
+               // @todo: if some day, we have rev-delete, we'll need to also 
check for that in here
+               if ( $this->permissions->isAllowed( $post, 'post-history' ) ) {
+                       $history = $this->getHistory( $options['postId'] );
                }
 
                return $templating->render( "flow:post-history.html.php", array(

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I497900d469acb6984ca250a141a337910b93c650
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