r44738 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44737‎ | r44738 | r44739 >
Date:22:57, 17 December 2008
Author:aaron
Status:ok (Comments)
Tags:
Comment:
*Did a good amount of patrol refactoring. Use core 'patrol' right per r44705 and remove patrol link duplication. Also solves bug 16684.
*'patrolother' right removed
*Short-circuit some hooks
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -172,14 +172,14 @@
173173 $wgGroupPermissions['editor']['review'] = true;
174174 $wgGroupPermissions['editor']['autoreview'] = true;
175175 $wgGroupPermissions['editor']['autoconfirmed'] = true;
176 -$wgGroupPermissions['editor']['patrolmarks'] = true;
177 -$wgGroupPermissions['editor']['autopatrolother'] = true;
 176+$wgGroupPermissions['editor']['patrol'] = true;
178177 $wgGroupPermissions['editor']['unreviewedpages'] = true;
179178
180179 # Defines extra rights for advanced reviewer class
181180 $wgGroupPermissions['reviewer']['validate'] = true;
182181 # Let this stand alone just in case...
183182 $wgGroupPermissions['reviewer']['review'] = true;
 183+$wgGroupPermissions['reviewer']['patrol'] = true;
184184
185185 $wgGroupPermissions['bot']['autoreview'] = true;
186186
@@ -373,6 +373,8 @@
374374 $wgHooks['NewRevisionFromEditComplete'][] = 'FlaggedRevsHooks::maybeMakeEditReviewed';
375375 # Disallow moves of stable pages
376376 $wgHooks['userCan'][] = 'FlaggedRevsHooks::userCanMove';
 377+# Determine what pages can be patrolled
 378+$wgHooks['userCan'][] = 'FlaggedRevsHooks::userCanPatrol';
377379 # Log parameter
378380 $wgHooks['LogLine'][] = 'FlaggedRevsHooks::reviewLogLine';
379381 # Disable auto-promotion for demoted users
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -1139,7 +1139,7 @@
11401140 * Add a link to patrol non-reviewable pages.
11411141 * Also add a diff to stable for other pages if possible.
11421142 */
1143 - public function addPatrolAndDiffLink( $diff, $oldRev, $newRev ) {
 1143+ public function addDiffLink( $diff, $oldRev, $newRev ) {
11441144 global $wgUser, $wgOut;
11451145 // Is there a stable version?
11461146 if( $oldRev && $this->isReviewable() ) {
@@ -1158,42 +1158,6 @@
11591159 $wgOut->addHTML( "<div class='fr-diff-to-stable' align='center'>$patrol</div>" );
11601160 }
11611161 }
1162 - // Prepare a change patrol link, if applicable
1163 - } else if( $this->isPatrollable() && $wgUser->isAllowed( 'review' ) ) {
1164 - wfLoadExtensionMessages( 'FlaggedRevs' );
1165 - // If we've been given an explicit change identifier, use it; saves time
1166 - if( $diff->mRcidMarkPatrolled ) {
1167 - $rcid = $diff->mRcidMarkPatrolled;
1168 - } else {
1169 - # Look for an unpatrolled change corresponding to this diff
1170 - $change = RecentChange::newFromConds(
1171 - array(
1172 - # Add redundant user,timestamp condition so we can use the existing index
1173 - 'rc_user_text' => $diff->mNewRev->getRawUserText(),
1174 - 'rc_timestamp' => wfGetDB( DB_SLAVE )->timestamp( $diff->mNewRev->getTimestamp() ),
1175 - 'rc_this_oldid' => $diff->mNewid,
1176 - 'rc_last_oldid' => $diff->mOldid,
1177 - 'rc_patrolled' => 0
1178 - ),
1179 - __METHOD__
1180 - );
1181 - if( $change instanceof RecentChange ) {
1182 - $rcid = $change->mAttribs['rc_id'];
1183 - } else {
1184 - $rcid = 0; // None found
1185 - }
1186 - }
1187 - // Build the link
1188 - if( $rcid ) {
1189 - $reviewTitle = SpecialPage::getTitleFor( 'RevisionReview' );
1190 - $token = $wgUser->editToken( $newRev->getTitle()->getPrefixedText(), $rcid );
1191 - $patrol = '[' . $wgUser->getSkin()->makeKnownLinkObj( $reviewTitle, wfMsgHtml( 'revreview-patrol' ),
1192 - wfArrayToCGI( array( 'patrolonly' => 1, 'target' => $newRev->getTitle()->getPrefixedDBKey(),
1193 - 'rcid' => $rcid, 'token' => $token ) ) ) . ']';
1194 - } else {
1195 - $patrol = '';
1196 - }
1197 - $wgOut->addHTML( '<div class="fr-diff-patrollink">' . $patrol . '</div>' );
11981162 }
11991163 return true;
12001164 }
Index: trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php
@@ -51,50 +51,12 @@
5252 $wgOut->showErrorPage('notargettitle', 'notargettext' );
5353 return;
5454 }
55 - # Basic patrolling
56 - $this->patrolonly = $wgRequest->getBool( 'patrolonly' );
57 - $this->rcid = $wgRequest->getIntOrNull( 'rcid' );
5855 # Param for sites with no tags, otherwise discarded
5956 $this->approve = $wgRequest->getBool( 'wpApprove' );
6057 # Patrol the edit if requested...
61 - if( $this->patrolonly && $this->rcid ) {
62 - $this->markPatrolled();
63 - # Otherwise, do a regular review...
64 - } else {
65 - $this->markReviewed();
66 - }
 58+ $this->markReviewed();
6759 }
6860
69 - private function markPatrolled() {
70 - global $wgRequest, $wgOut, $wgUser;
71 -
72 - $token = $wgRequest->getVal('token');
73 - $wgOut->setPageTitle( wfMsg( 'revreview-patrol-title' ) );
74 - # Prevent hijacking
75 - if( !$wgUser->matchEditToken( $token, $this->page->getPrefixedText(), $this->rcid ) ) {
76 - $wgOut->addWikiText( wfMsg('sessionfailure') );
77 - return;
78 - }
79 - # Make sure page is not reviewable. This can be spoofed in theory,
80 - # but the token is salted with the id and title and this should
81 - # be a trusted user...so it is not worth doing extra query work.
82 - $fa = FlaggedArticle::getTitleInstance( $this->page );
83 - if( $fa->isReviewable() ) {
84 - $wgOut->showErrorPage('notargettitle', 'notargettext' );
85 - return;
86 - }
87 - # Mark as patrolled
88 - $dbw = wfGetDB( DB_MASTER );
89 - if( ( $rc = RecentChange::newFromId($this->rcid) ) ) {
90 - $rc->reallyMarkPatrolled();
91 - // Log this patrol event
92 - PatrolLog::record( $rc, false );
93 - }
94 - # Inform the user
95 - $wgOut->addWikiText( wfMsg( 'revreview-patrolled', $this->page->getPrefixedText() ) );
96 - $wgOut->returnToMain( false, SpecialPage::getTitleFor( 'Recentchanges' ) );
97 - }
98 -
9961 private function markReviewed() {
10062 global $wgRequest, $wgOut, $wgUser;
10163 # Must be in reviewable namespace
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -7,7 +7,7 @@
88 public static function stripPatrolRights( $user, &$rights ) {
99 # Use only our extension mechanisms
1010 foreach( $rights as $n => $right ) {
11 - if( $right == 'patrol' || $right == 'autopatrol' ) {
 11+ if( $right == 'autopatrol' ) {
1212 unset($rights[$n]);
1313 }
1414 }
@@ -577,7 +577,7 @@
578578 * Don't let users vandalize pages by moving them
579579 */
580580 public static function userCanMove( $title, $user, &$action, &$result ) {
581 - if( $action != 'move' || !FlaggedRevs::isPageReviewable( $title ) ) {
 581+ if( $action != 'move' || $result===false || !FlaggedRevs::isPageReviewable($title) ) {
582582 return true;
583583 }
584584 $flaggedArticle = FlaggedArticle::getTitleInstance( $title );
@@ -594,6 +594,28 @@
595595 return true;
596596 }
597597
 598+ /**
 599+ * Don't let users pages pages not in $wgFlaggedRevsPatrolNamespaces
 600+ */
 601+ public static function userCanPatrol( $title, $user, &$action, &$result ) {
 602+ if( $action != 'patrol' || $result===false ) {
 603+ return true;
 604+ }
 605+ # Pages in reviewable namespace can be patrolled IF reviewing
 606+ # is disabled for pages that don't show the stable by default.
 607+ # In such cases, we let people with 'review' rights patrol them.
 608+ if( FlaggedRevs::isPageReviewable($title) && !$user->isAllowed( 'review' ) ) {
 609+ $result = false;
 610+ return false;
 611+ }
 612+ $flaggedArticle = FlaggedArticle::getTitleInstance( $title );
 613+ if( !$flaggedArticle->isPatrollable() ) {
 614+ $result = false;
 615+ return false;
 616+ }
 617+ return true;
 618+ }
 619+
598620 /**
599621 * Allow users to view reviewed pages
600622 */
@@ -601,7 +623,7 @@
602624 global $wgFlaggedRevsVisible, $wgFlaggedRevsTalkVisible, $wgTitle;
603625 # Assume $action may still not be set, in which case, treat it as 'view'...
604626 # Return out if $result set to false by some other hooked call.
605 - if( empty($wgFlaggedRevsVisible) || $action !== 'read' || $result===false )
 627+ if( $action !== 'read' || $result===false || empty($wgFlaggedRevsVisible) )
606628 return true;
607629 # Admin may set this to false, rather than array()...
608630 $groups = $user->getGroups();
@@ -1229,7 +1251,7 @@
12301252 public static function onDiffViewHeader( $diff, $oldRev, $newRev ) {
12311253 self::injectStyleAndJS();
12321254 $flaggedArticle = FlaggedArticle::getTitleInstance( $diff->getTitle() );
1233 - $flaggedArticle->addPatrolAndDiffLink( $diff, $oldRev, $newRev );
 1255+ $flaggedArticle->addDiffLink( $diff, $oldRev, $newRev );
12341256 $flaggedArticle->addDiffNoticeAndIncludes( $diff, $oldRev, $newRev );
12351257 return true;
12361258 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r44705Use more thorough Title->userCan('patrol')aaron07:17, 17 December 2008

Comments

#Comment by Raymond (talk | contribs)   05:19, 18 December 2008

I am a bit confused:

-$wgGroupPermissions['editor']['autopatrolother'] = true;

was removed. No usergroup has this right now but in FlaggedRevs.hooks::autoMarkPatrolled exists a check still:

$patrol = $wgUser->isAllowed('autopatrolother');

#Comment by Brion VIBBER (talk | contribs)   18:57, 23 December 2008

That was resolved in r44754

Status & tagging log