Matthias Mullie has uploaded a new change for review.

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

Change subject: Link to single-view for block-level EnhancedRC entries
......................................................................

Link to single-view for block-level EnhancedRC entries

We've recently introduced a new hook in EnhancedRC that allowed
us to manipulate the timestamp & let it link to a post's
single-view action, where there's a link to patrol it.
That bit of code was only used in grouped entries, though. If
an entry is ungrouped (only 1 new post in a topic), it's rendered
differently & that hook wasn't called.
I've added another hook in EnhancedRC that works the same way,
so we can also add that link to the timestamp.

Meanwhile also fixed/cleaned up permissions:
* we weren't properly using PermissionException class everywhere
* we should be throwing PermissionsException instead of generic
  FlowException
* was missing some return value check in getTimestampLink where
  it could feed invalid param into another
* wasn't catching permission issues & aborting hook
* should be allows to see suppressed root-permissions things if
  user has the required permissions

Depends on core patch:
I6b4715277d44e5f09d7a230b33e956676aeab1c2 to introduce hook

And we'll also want to merge this one, though not required here:
I4a2f97d83f38071984d571773a6b09b6b6643d6d to allow hook abortion

Bug: T104399
Bug: T104564
Change-Id: Ib8b76dd501f5e881cdf2348b36a5711dcbaad818
---
M Flow.php
M FlowActions.php
M Hooks.php
M includes/Formatter/RecentChanges.php
M includes/Formatter/RevisionFormatter.php
M includes/Templating.php
6 files changed, 27 insertions(+), 3 deletions(-)


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

diff --git a/Flow.php b/Flow.php
index 291ef10..65ea2e5 100644
--- a/Flow.php
+++ b/Flow.php
@@ -107,6 +107,7 @@
 $wgHooks['ChangesListInitRows'][] = 'FlowHooks::onChangesListInitRows';
 $wgHooks['EnhancedChangesList::getLogText'][] = 'FlowHooks::onGetLogText';
 $wgHooks['EnhancedChangesListModifyLineData'][] = 
'FlowHooks::onEnhancedChangesListModifyLineData';
+$wgHooks['EnhancedChangesListModifyBlockLineData'][] = 
'FlowHooks::onEnhancedChangesListModifyBlockLineData';
 $wgHooks['SkinTemplateNavigation::Universal'][] = 
'FlowHooks::onSkinTemplateNavigation';
 $wgHooks['Article::MissingArticleConditions'][] = 
'FlowHooks::onMissingArticleConditions';
 $wgHooks['SpecialWatchlistGetNonRevisionTypes'][] = 
'FlowHooks::onSpecialWatchlistGetNonRevisionTypes';
diff --git a/FlowActions.php b/FlowActions.php
index 6a52f72..678596e 100644
--- a/FlowActions.php
+++ b/FlowActions.php
@@ -761,6 +761,7 @@
                        PostRevision::MODERATED_HIDDEN => '',
                        PostRevision::MODERATED_LOCKED => '',
                        PostRevision::MODERATED_DELETED => '',
+                       PostRevision::MODERATED_SUPPRESSED => 'flow-suppress',
                ),
                'core-delete-permissions' => array( 'deletedhistory' ),
                'history' => array(), // views don't generate history
diff --git a/Hooks.php b/Hooks.php
index fe0988a..6e71ea6 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -3,6 +3,7 @@
 use Flow\Collection\PostCollection;
 use Flow\Container;
 use Flow\Exception\FlowException;
+use Flow\Exception\PermissionException;
 use Flow\Formatter\CheckUserQuery;
 use Flow\Model\UUID;
 use Flow\OccupationController;
@@ -446,6 +447,16 @@
         * @return bool
         */
        public static function onEnhancedChangesListModifyLineData( 
$changesList, &$data, $block, $rc ) {
+               return static::onEnhancedChangesListModifyBlockLineData( 
$changesList, $data, $rc );
+       }
+
+       /**
+        * @param EnhancedChangesList $changesList
+        * @param array $data
+        * @param RecentChange $rc
+        * @return bool
+        */
+       public static function onEnhancedChangesListModifyBlockLineData( 
$changesList, &$data, $rc ) {
                // quit if non-flow
                if ( !FlowHooks::isFlow( $rc ) ) {
                        return true;
@@ -459,7 +470,11 @@
 
                /** @var Flow\Formatter\RecentChanges $formatter */
                $formatter = Container::get( 'formatter.recentchanges' );
-               $data['timestampLink'] = $formatter->getTimestampLink( $row, 
$changesList );
+               try {
+                       $data['timestampLink'] = $formatter->getTimestampLink( 
$row, $changesList );
+               } catch ( PermissionException $e ) {
+                       return false;
+               }
 
                return true;
        }
diff --git a/includes/Formatter/RecentChanges.php 
b/includes/Formatter/RecentChanges.php
index db6c699..8b41343 100644
--- a/includes/Formatter/RecentChanges.php
+++ b/includes/Formatter/RecentChanges.php
@@ -3,6 +3,7 @@
 namespace Flow\Formatter;
 
 use Flow\Exception\FlowException;
+use Flow\Exception\PermissionException;
 use Flow\Model\Anchor;
 use ChangesList;
 use Flow\Model\PostRevision;
@@ -164,6 +165,10 @@
         */
        public function getTimestampLink( $row, $ctx ) {
                $data = $this->serializer->formatApi( $row, $ctx, 
'recentchanges' );
+               if ( $data === false ) {
+                       throw new PermissionException( 'Insufficient 
permissions for ' . $row->revision->getRevisionId()->getAlphadecimal() );
+               }
+
                return $this->formatTimestamp( $data, 'time' );
        }
 
diff --git a/includes/Formatter/RevisionFormatter.php 
b/includes/Formatter/RevisionFormatter.php
index 50ffce4..dc2994f 100644
--- a/includes/Formatter/RevisionFormatter.php
+++ b/includes/Formatter/RevisionFormatter.php
@@ -3,6 +3,7 @@
 namespace Flow\Formatter;
 
 use Flow\Collection\PostCollection;
+use Flow\Exception\PermissionException;
 use Flow\Repository\UserNameBatch;
 use Flow\Exception\FlowException;
 use Flow\Model\AbstractRevision;
diff --git a/includes/Templating.php b/includes/Templating.php
index 3d9cd77..e3351da 100644
--- a/includes/Templating.php
+++ b/includes/Templating.php
@@ -3,6 +3,7 @@
 namespace Flow;
 
 use Flow\Exception\InvalidInputException;
+use Flow\Exception\PermissionException;
 use Flow\Repository\UserNameBatch;
 use Flow\Exception\FlowException;
 use Flow\Model\AbstractRevision;
@@ -84,11 +85,11 @@
         *
         * @param  AbstractRevision $revision        Revision to display
         * @return string                            HTML
-        * @throws FlowException
+        * @throws PermissionException
         */
        public function getUserLinks( AbstractRevision $revision ) {
                if ( !$revision->isModerated() && 
!$this->permissions->isAllowed( $revision, 'history' ) ) {
-                       throw new FlowException( 'Insufficient permissions to 
see userlinks for rev_id = ' . $revision->getRevisionId()->getAlphadecimal() );
+                       throw new PermissionException( 'Insufficient 
permissions to see userlinks for rev_id = ' . 
$revision->getRevisionId()->getAlphadecimal() );
                }
 
                // if this specific revision is moderated, its usertext can 
always be

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib8b76dd501f5e881cdf2348b36a5711dcbaad818
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org>

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

Reply via email to