Index: branches/wmf-deployment/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -753,7 +753,9 @@ |
754 | 754 | # Get the user who made the edit |
755 | 755 | $user = is_null($user) ? User::newFromId( $rev->getUser() ) : $user; |
756 | 756 | # Is the page checked off to be reviewed? |
| 757 | + # Autoreview if this is such a valid case... |
757 | 758 | if( $wgRequest->getCheck('wpReviewEdit') && $user->isAllowed('review') ) { |
| 759 | + # Check wpEdittime against the previous edit for verification |
758 | 760 | if( $prevRevId ) { |
759 | 761 | $prevTimestamp = Revision::getTimestampFromId( $title, $prevRevId ); // use PK |
760 | 762 | } |
— | — | @@ -766,10 +768,9 @@ |
767 | 769 | } |
768 | 770 | # Get sync cache key |
769 | 771 | $key = wfMemcKey( 'flaggedrevs', 'includesSynced', $rev->getPage() ); |
770 | | - global $wgMemc, $wgParserCacheExpireTime; |
771 | 772 | # Auto-reviewing must be enabled and user must have the required permissions |
772 | 773 | if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') ) { |
773 | | - $isAllowed = false; |
| 774 | + $isAllowed = false; // trusted user |
774 | 775 | } else { |
775 | 776 | # Get autoreview restriction settings... |
776 | 777 | $config = FlaggedRevs::getPageVisibilitySettings( $title, true ); |
— | — | @@ -779,11 +780,6 @@ |
780 | 781 | # Check if the user has the required right, if any |
781 | 782 | $isAllowed = ($right == '' || $user->isAllowed($right)); |
782 | 783 | } |
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 | | - } |
788 | 784 | # If $baseRevId passed in, this is a null edit |
789 | 785 | $isNullEdit = $baseRevId ? true : false; |
790 | 786 | $frev = null; |
— | — | @@ -807,6 +803,28 @@ |
808 | 804 | $baseRevId = $prevRevId; |
809 | 805 | } |
810 | 806 | } |
| 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 | + } |
811 | 829 | // New pages |
812 | 830 | if( !$prevRevId ) { |
813 | 831 | $reviewableNewPage = (bool)$wgFlaggedRevsAutoReviewNew; |
— | — | @@ -819,8 +837,8 @@ |
820 | 838 | $frev = FlaggedRevision::newFromTitle( $title, $prevRevId, FR_MASTER ); |
821 | 839 | } |
822 | 840 | } |
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)) ) { |
825 | 843 | # Assume basic flagging level unless this is a null edit |
826 | 844 | if( $isNullEdit ) $flags = $frev->getTags(); |
827 | 845 | # Review this revision of the page. Let articlesavecomplete hook do rc_patrolled bit... |
— | — | @@ -835,6 +853,20 @@ |
836 | 854 | } |
837 | 855 | |
838 | 856 | /** |
| 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 | + /** |
839 | 871 | * When an user makes a null-edit we sometimes want to review it... |
840 | 872 | */ |
841 | 873 | public static function maybeNullEditReview( $article, $user, $text, $summary, $m, $a, $b, |