r91784 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91783‎ | r91784 | r91785 >
Date:09:17, 9 July 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
Pass the User object to RecentChange::doMarkPatrolled() instead of relying on $wgUser
Modified paths:
  • /trunk/phase3/includes/RecentChange.php (modified) (history)
  • /trunk/phase3/includes/actions/MarkpatrolledAction.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/actions/MarkpatrolledAction.php
@@ -51,12 +51,8 @@
5252 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
5353 }
5454
55 - # It would be nice to see where the user had actually come from, but for now just guess
56 - $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
57 - $return = SpecialPage::getTitleFor( $returnto );
 55+ $errors = $rc->doMarkPatrolled( $this->getUser() );
5856
59 - $errors = $rc->doMarkPatrolled();
60 -
6157 if ( in_array( array( 'rcpatroldisabled' ), $errors ) ) {
6258 throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
6359 }
@@ -66,6 +62,10 @@
6763 return;
6864 }
6965
 66+ # It would be nice to see where the user had actually come from, but for now just guess
 67+ $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
 68+ $return = SpecialPage::getTitleFor( $returnto );
 69+
7070 if ( in_array( array( 'markedaspatrollederror-noautopatrol' ), $errors ) ) {
7171 $this->getOutput()->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
7272 $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
Index: trunk/phase3/includes/RecentChange.php
@@ -268,24 +268,28 @@
269269 * @return Array See doMarkPatrolled(), or null if $change is not an existing rc_id
270270 */
271271 public static function markPatrolled( $change, $auto = false ) {
 272+ global $wgUser;
 273+
272274 $change = $change instanceof RecentChange
273275 ? $change
274276 : RecentChange::newFromId($change);
 277+
275278 if( !$change instanceof RecentChange ) {
276279 return null;
277280 }
278 - return $change->doMarkPatrolled( $auto );
 281+ return $change->doMarkPatrolled( $wgUser, $auto );
279282 }
280283
281284 /**
282285 * Mark this RecentChange as patrolled
283286 *
284287 * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
 288+ * @param $user User object doing the action
285289 * @param $auto Boolean: for automatic patrol
286290 * @return array of permissions errors, see Title::getUserPermissionsErrors()
287291 */
288 - public function doMarkPatrolled( $auto = false ) {
289 - global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
 292+ public function doMarkPatrolled( User $user, $auto = false ) {
 293+ global $wgUseRCPatrol, $wgUseNPPatrol;
290294 $errors = array();
291295 // If recentchanges patrol is disabled, only new pages
292296 // can be patrolled
@@ -294,13 +298,13 @@
295299 }
296300 // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
297301 $right = $auto ? 'autopatrol' : 'patrol';
298 - $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $wgUser ) );
 302+ $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
299303 if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$wgUser, false)) ) {
300304 $errors[] = array('hookaborted');
301305 }
302306 // Users without the 'autopatrol' right can't patrol their
303307 // own revisions
304 - if( $wgUser->getName() == $this->getAttribute('rc_user_text') && !$wgUser->isAllowed('autopatrol') ) {
 308+ if( $user->getName() == $this->getAttribute('rc_user_text') && !$user->isAllowed('autopatrol') ) {
305309 $errors[] = array('markedaspatrollederror-noautopatrol');
306310 }
307311 if( $errors ) {
@@ -314,7 +318,7 @@
315319 $this->reallyMarkPatrolled();
316320 // Log this patrol event
317321 PatrolLog::record( $this, $auto );
318 - wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$wgUser, false) );
 322+ wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$user, false) );
319323 return array();
320324 }
321325

Follow-up revisions

RevisionCommit summaryAuthorDate
r92568r91784 forgot to change one instance of $wgUser to $userplatonides20:21, 19 July 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   16:49, 11 July 2011

InterwikiIntegrationRecentChange.php should be updated.

Status & tagging log