r57360 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57359‎ | r57360 | r57361 >
Date:18:09, 4 October 2009
Author:aaron
Status:ok
Tags:
Comment:
merged r57261: self-revert autoreview
Modified paths:
  • /branches/wmf-deployment/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)

Diff [purge]

Index: branches/wmf-deployment/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -753,7 +753,9 @@
754754 # Get the user who made the edit
755755 $user = is_null($user) ? User::newFromId( $rev->getUser() ) : $user;
756756 # Is the page checked off to be reviewed?
 757+ # Autoreview if this is such a valid case...
757758 if( $wgRequest->getCheck('wpReviewEdit') && $user->isAllowed('review') ) {
 759+ # Check wpEdittime against the previous edit for verification
758760 if( $prevRevId ) {
759761 $prevTimestamp = Revision::getTimestampFromId( $title, $prevRevId ); // use PK
760762 }
@@ -766,10 +768,9 @@
767769 }
768770 # Get sync cache key
769771 $key = wfMemcKey( 'flaggedrevs', 'includesSynced', $rev->getPage() );
770 - global $wgMemc, $wgParserCacheExpireTime;
771772 # Auto-reviewing must be enabled and user must have the required permissions
772773 if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') ) {
773 - $isAllowed = false;
 774+ $isAllowed = false; // trusted user
774775 } else {
775776 # Get autoreview restriction settings...
776777 $config = FlaggedRevs::getPageVisibilitySettings( $title, true );
@@ -779,11 +780,6 @@
780781 # Check if the user has the required right, if any
781782 $isAllowed = ($right == '' || $user->isAllowed($right));
782783 }
783 - # Auto-reviewing must be enabled and user must have the required permissions
784 - if( !$isAllowed ) {
785 - $wgMemc->set( $key, FlaggedRevs::makeMemcObj('false'), $wgParserCacheExpireTime );
786 - return true; // done! edit pending!
787 - }
788784 # If $baseRevId passed in, this is a null edit
789785 $isNullEdit = $baseRevId ? true : false;
790786 $frev = null;
@@ -807,6 +803,28 @@
808804 $baseRevId = $prevRevId;
809805 }
810806 }
 807+ global $wgMemc, $wgParserCacheExpireTime;
 808+ # User must have the required permissions for all autoreview cases
 809+ # except for simple self-reversions.
 810+ if( !$isAllowed ) {
 811+ $srev = FlaggedRevision::newFromStable( $title, FR_MASTER );
 812+ # Check if this reverted to the stable version. Reverts to other reviewed
 813+ # revisions will not be allowed since we don't trust this user.
 814+ if( $srev && $baseRevId == $srev->getRevId() ) {
 815+ # Check that this user is ONLY reverting his/herself.
 816+ if( self::userWasLastAuthor($article,$baseRevId,$user) ) {
 817+ # Confirm the text; we can't trust this user.
 818+ if( $rev->getText() == $srev->getRevText() ) {
 819+ $flags = FlaggedRevs::quickTags( FR_SIGHTED );
 820+ $ok = FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags );
 821+ if( $ok ) return true; // done!
 822+ }
 823+ }
 824+ }
 825+ # User does not have the permission for general autoreviewing...
 826+ $wgMemc->set( $key, FlaggedRevs::makeMemcObj('false'), $wgParserCacheExpireTime );
 827+ return true; // done! edit pending!
 828+ }
811829 // New pages
812830 if( !$prevRevId ) {
813831 $reviewableNewPage = (bool)$wgFlaggedRevsAutoReviewNew;
@@ -819,8 +837,8 @@
820838 $frev = FlaggedRevision::newFromTitle( $title, $prevRevId, FR_MASTER );
821839 }
822840 }
823 - # Is this an edit directly to the stable version? Is it a new page?
824 - if( $reviewableNewPage || !is_null($frev) ) {
 841+ // Is this an edit directly to the stable version? Is it a new page?
 842+ if( $isAllowed && ($reviewableNewPage || !is_null($frev)) ) {
825843 # Assume basic flagging level unless this is a null edit
826844 if( $isNullEdit ) $flags = $frev->getTags();
827845 # Review this revision of the page. Let articlesavecomplete hook do rc_patrolled bit...
@@ -835,6 +853,20 @@
836854 }
837855
838856 /**
 857+ * Check if a user was the last author of the revisions of a page
 858+ */
 859+ protected static function userWasLastAuthor( $article, $baseRevId, $user ) {
 860+ $dbw = wfGetDB( DB_MASTER );
 861+ return !$dbw->selectField( 'revision', '1',
 862+ array(
 863+ 'rev_page' => $article->getId(),
 864+ 'rev_id > '.intval($baseRevId),
 865+ 'rev_user_text != '.$dbw->addQuotes($user->getName())
 866+ ), __METHOD__
 867+ );
 868+ }
 869+
 870+ /**
839871 * When an user makes a null-edit we sometimes want to review it...
840872 */
841873 public static function maybeNullEditReview( $article, $user, $text, $summary, $m, $a, $b,

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r57261bug 20855: noneditor self-reverts can be autoreviewed when appropriateaaron22:37, 1 October 2009

Status & tagging log