r57261 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57260‎ | r57261 | r57262 >
Date:22:37, 1 October 2009
Author:aaron
Status:ok
Tags:
Comment:
bug 20855: noneditor self-reverts can be autoreviewed when appropriate
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -778,7 +778,9 @@
779779 # Get the user who made the edit
780780 $user = is_null($user) ? User::newFromId( $rev->getUser() ) : $user;
781781 # Is the page checked off to be reviewed?
 782+ # Autoreview if this is such a valid case...
782783 if( $wgRequest->getCheck('wpReviewEdit') && $user->isAllowed('review') ) {
 784+ # Check wpEdittime against the previous edit for verification
783785 if( $prevRevId ) {
784786 $prevTimestamp = Revision::getTimestampFromId( $title, $prevRevId ); // use PK
785787 }
@@ -791,10 +793,9 @@
792794 }
793795 # Get sync cache key
794796 $key = wfMemcKey( 'flaggedrevs', 'includesSynced', $rev->getPage() );
795 - global $wgMemc, $wgParserCacheExpireTime;
796797 # Auto-reviewing must be enabled and user must have the required permissions
797798 if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') ) {
798 - $isAllowed = false;
 799+ $isAllowed = false; // trusted user
799800 } else {
800801 # Get autoreview restriction settings...
801802 $config = FlaggedRevs::getPageVisibilitySettings( $title, true );
@@ -804,11 +805,6 @@
805806 # Check if the user has the required right, if any
806807 $isAllowed = ($right == '' || $user->isAllowed($right));
807808 }
808 - # Auto-reviewing must be enabled and user must have the required permissions
809 - if( !$isAllowed ) {
810 - $wgMemc->set( $key, FlaggedRevs::makeMemcObj('false'), $wgParserCacheExpireTime );
811 - return true; // done! edit pending!
812 - }
813809 # If $baseRevId passed in, this is a null edit
814810 $isNullEdit = $baseRevId ? true : false;
815811 $frev = null;
@@ -832,6 +828,28 @@
833829 $baseRevId = $prevRevId;
834830 }
835831 }
 832+ global $wgMemc, $wgParserCacheExpireTime;
 833+ # User must have the required permissions for all autoreview cases
 834+ # except for simple self-reversions.
 835+ if( !$isAllowed ) {
 836+ $srev = FlaggedRevision::newFromStable( $title, FR_MASTER );
 837+ # Check if this reverted to the stable version. Reverts to other reviewed
 838+ # revisions will not be allowed since we don't trust this user.
 839+ if( $srev && $baseRevId == $srev->getRevId() ) {
 840+ # Check that this user is ONLY reverting his/herself.
 841+ if( self::userWasLastAuthor($article,$baseRevId,$user) ) {
 842+ # Confirm the text; we can't trust this user.
 843+ if( $rev->getText() == $srev->getRevText() ) {
 844+ $flags = FlaggedRevs::quickTags( FR_SIGHTED );
 845+ $ok = FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags );
 846+ if( $ok ) return true; // done!
 847+ }
 848+ }
 849+ }
 850+ # User does not have the permission for general autoreviewing...
 851+ $wgMemc->set( $key, FlaggedRevs::makeMemcObj('false'), $wgParserCacheExpireTime );
 852+ return true; // done! edit pending!
 853+ }
836854 // New pages
837855 if( !$prevRevId ) {
838856 $reviewableNewPage = (bool)$wgFlaggedRevsAutoReviewNew;
@@ -844,8 +862,8 @@
845863 $frev = FlaggedRevision::newFromTitle( $title, $prevRevId, FR_MASTER );
846864 }
847865 }
848 - # Is this an edit directly to the stable version? Is it a new page?
849 - if( $reviewableNewPage || !is_null($frev) ) {
 866+ // Is this an edit directly to the stable version? Is it a new page?
 867+ if( $isAllowed && ($reviewableNewPage || !is_null($frev)) ) {
850868 # Assume basic flagging level unless this is a null edit
851869 if( $isNullEdit ) $flags = $frev->getTags();
852870 # Review this revision of the page. Let articlesavecomplete hook do rc_patrolled bit...
@@ -860,6 +878,20 @@
861879 }
862880
863881 /**
 882+ * Check if a user was the last author of the revisions of a page
 883+ */
 884+ protected static function userWasLastAuthor( $article, $baseRevId, $user ) {
 885+ $dbw = wfGetDB( DB_MASTER );
 886+ return !$dbw->selectField( 'revision', '1',
 887+ array(
 888+ 'rev_page' => $article->getId(),
 889+ 'rev_id > '.intval($baseRevId),
 890+ 'rev_user_text != '.$dbw->addQuotes($user->getName())
 891+ ), __METHOD__
 892+ );
 893+ }
 894+
 895+ /**
864896 * When an user makes a null-edit we sometimes want to review it...
865897 */
866898 public static function maybeNullEditReview( $article, $user, $text, $summary, $m, $a, $b,
@@ -1006,6 +1038,9 @@
10071039 return ($benchmarks >= $needed );
10081040 }
10091041
 1042+ /**
 1043+ * Checks if $user was previously blocked
 1044+ */
10101045 protected function previousBlockCheck( $user ) {
10111046 $dbr = wfGetDB( DB_SLAVE );
10121047 return (bool)$dbr->selectField( 'logging', '1',

Follow-up revisions

RevisionCommit summaryAuthorDate
r57360merged r57261: self-revert autoreviewaaron18:09, 4 October 2009

Status & tagging log