Pass the User object to RecentChange::doMarkPatrolled() instead of relying on $wgUser
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 9 Jul 2011 09:17:35 +0000 (09:17 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 9 Jul 2011 09:17:35 +0000 (09:17 +0000)
includes/RecentChange.php
includes/actions/MarkpatrolledAction.php

index 8cc5dd7..a2b9796 100644 (file)
@@ -268,24 +268,28 @@ class RecentChange {
         * @return Array See doMarkPatrolled(), or null if $change is not an existing rc_id
         */
        public static function markPatrolled( $change, $auto = false ) {
+               global $wgUser;
+
                $change = $change instanceof RecentChange
                        ? $change
                        : RecentChange::newFromId($change);
+
                if( !$change instanceof RecentChange ) {
                        return null;
                }
-               return $change->doMarkPatrolled( $auto );
+               return $change->doMarkPatrolled( $wgUser, $auto );
        }
        
        /**
         * Mark this RecentChange as patrolled
         *
         * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
+        * @param $user User object doing the action
         * @param $auto Boolean: for automatic patrol
         * @return array of permissions errors, see Title::getUserPermissionsErrors()
         */
-       public function doMarkPatrolled( $auto = false ) {
-               global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
+       public function doMarkPatrolled( User $user, $auto = false ) {
+               global $wgUseRCPatrol, $wgUseNPPatrol;
                $errors = array();
                // If recentchanges patrol is disabled, only new pages
                // can be patrolled
@@ -294,13 +298,13 @@ class RecentChange {
                }
                // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
                $right = $auto ? 'autopatrol' : 'patrol';
-               $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $wgUser ) );
+               $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
                if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$wgUser, false)) ) {
                        $errors[] = array('hookaborted');
                }
                // Users without the 'autopatrol' right can't patrol their
                // own revisions
-               if( $wgUser->getName() == $this->getAttribute('rc_user_text') && !$wgUser->isAllowed('autopatrol') ) {
+               if( $user->getName() == $this->getAttribute('rc_user_text') && !$user->isAllowed('autopatrol') ) {
                        $errors[] = array('markedaspatrollederror-noautopatrol');
                }
                if( $errors ) {
@@ -314,7 +318,7 @@ class RecentChange {
                $this->reallyMarkPatrolled();
                // Log this patrol event
                PatrolLog::record( $this, $auto );
-               wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$wgUser, false) );
+               wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$user, false) );
                return array();
        }
        
index 5ea986e..a5d7662 100644 (file)
@@ -51,11 +51,7 @@ class MarkpatrolledAction extends FormlessAction {
                        throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
                }
 
-               # It would be nice to see where the user had actually come from, but for now just guess
-               $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
-               $return = SpecialPage::getTitleFor( $returnto );
-
-               $errors = $rc->doMarkPatrolled();
+               $errors = $rc->doMarkPatrolled( $this->getUser() );
 
                if ( in_array( array( 'rcpatroldisabled' ), $errors ) ) {
                        throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
@@ -66,6 +62,10 @@ class MarkpatrolledAction extends FormlessAction {
                        return;
                }
 
+               # It would be nice to see where the user had actually come from, but for now just guess
+               $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
+               $return = SpecialPage::getTitleFor( $returnto );
+
                if ( in_array( array( 'markedaspatrollederror-noautopatrol' ), $errors ) ) {
                        $this->getOutput()->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
                        $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );