Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -778,7 +778,9 @@ |
779 | 779 | # Get the user who made the edit |
780 | 780 | $user = is_null($user) ? User::newFromId( $rev->getUser() ) : $user; |
781 | 781 | # Is the page checked off to be reviewed? |
| 782 | + # Autoreview if this is such a valid case... |
782 | 783 | if( $wgRequest->getCheck('wpReviewEdit') && $user->isAllowed('review') ) { |
| 784 | + # Check wpEdittime against the previous edit for verification |
783 | 785 | if( $prevRevId ) { |
784 | 786 | $prevTimestamp = Revision::getTimestampFromId( $title, $prevRevId ); // use PK |
785 | 787 | } |
— | — | @@ -791,10 +793,9 @@ |
792 | 794 | } |
793 | 795 | # Get sync cache key |
794 | 796 | $key = wfMemcKey( 'flaggedrevs', 'includesSynced', $rev->getPage() ); |
795 | | - global $wgMemc, $wgParserCacheExpireTime; |
796 | 797 | # Auto-reviewing must be enabled and user must have the required permissions |
797 | 798 | if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') ) { |
798 | | - $isAllowed = false; |
| 799 | + $isAllowed = false; // trusted user |
799 | 800 | } else { |
800 | 801 | # Get autoreview restriction settings... |
801 | 802 | $config = FlaggedRevs::getPageVisibilitySettings( $title, true ); |
— | — | @@ -804,11 +805,6 @@ |
805 | 806 | # Check if the user has the required right, if any |
806 | 807 | $isAllowed = ($right == '' || $user->isAllowed($right)); |
807 | 808 | } |
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 | | - } |
813 | 809 | # If $baseRevId passed in, this is a null edit |
814 | 810 | $isNullEdit = $baseRevId ? true : false; |
815 | 811 | $frev = null; |
— | — | @@ -832,6 +828,28 @@ |
833 | 829 | $baseRevId = $prevRevId; |
834 | 830 | } |
835 | 831 | } |
| 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 | + } |
836 | 854 | // New pages |
837 | 855 | if( !$prevRevId ) { |
838 | 856 | $reviewableNewPage = (bool)$wgFlaggedRevsAutoReviewNew; |
— | — | @@ -844,8 +862,8 @@ |
845 | 863 | $frev = FlaggedRevision::newFromTitle( $title, $prevRevId, FR_MASTER ); |
846 | 864 | } |
847 | 865 | } |
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)) ) { |
850 | 868 | # Assume basic flagging level unless this is a null edit |
851 | 869 | if( $isNullEdit ) $flags = $frev->getTags(); |
852 | 870 | # Review this revision of the page. Let articlesavecomplete hook do rc_patrolled bit... |
— | — | @@ -860,6 +878,20 @@ |
861 | 879 | } |
862 | 880 | |
863 | 881 | /** |
| 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 | + /** |
864 | 896 | * When an user makes a null-edit we sometimes want to review it... |
865 | 897 | */ |
866 | 898 | public static function maybeNullEditReview( $article, $user, $text, $summary, $m, $a, $b, |
— | — | @@ -1006,6 +1038,9 @@ |
1007 | 1039 | return ($benchmarks >= $needed ); |
1008 | 1040 | } |
1009 | 1041 | |
| 1042 | + /** |
| 1043 | + * Checks if $user was previously blocked |
| 1044 | + */ |
1010 | 1045 | protected function previousBlockCheck( $user ) { |
1011 | 1046 | $dbr = wfGetDB( DB_SLAVE ); |
1012 | 1047 | return (bool)$dbr->selectField( 'logging', '1', |