Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php |
— | — | @@ -91,25 +91,21 @@ |
92 | 92 | /** |
93 | 93 | * Get latest quality rev, if not, the latest reviewed one |
94 | 94 | * @param int $flags |
95 | | - * @return Row |
| 95 | + * @return mixed (FlaggedRevision/false) |
96 | 96 | */ |
97 | 97 | public function getStableRev( $flags = 0 ) { |
98 | | - if ( $this->stableRev === false ) { |
99 | | - return null; // We already looked and found nothing... |
100 | | - } |
101 | 98 | # Cached results available? |
102 | | - if ( !is_null( $this->stableRev ) ) { |
| 99 | + if ( !($flags & FR_MASTER) && $this->stableRev !== null ) { |
103 | 100 | return $this->stableRev; |
104 | 101 | } |
105 | 102 | # Do we have one? |
106 | 103 | $srev = FlaggedRevision::newFromStable( $this->getTitle(), $flags ); |
107 | 104 | if ( $srev ) { |
108 | 105 | $this->stableRev = $srev; |
109 | | - return $srev; |
110 | 106 | } else { |
111 | 107 | $this->stableRev = false; |
112 | | - return null; |
113 | 108 | } |
| 109 | + return $this->stableRev; |
114 | 110 | } |
115 | 111 | |
116 | 112 | /** |
— | — | @@ -119,7 +115,7 @@ |
120 | 116 | */ |
121 | 117 | public function getVisibilitySettings( $flags = 0 ) { |
122 | 118 | # Cached results available? |
123 | | - if ( !is_null( $this->pageConfig ) ) { |
| 119 | + if ( !($flags & FR_MASTER) && $this->pageConfig !== null ) { |
124 | 120 | return $this->pageConfig; |
125 | 121 | } |
126 | 122 | # Get the content page, skip talk |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -857,6 +857,8 @@ |
858 | 858 | * edit was made from is the stable version, or the edit is a reversion |
859 | 859 | * to the stable version, then try to automatically review it. |
860 | 860 | * Also automatically review if the "review this revision" box is checked. |
| 861 | + * |
| 862 | + * Note: RC items not inserted yet, RecentChange_save hook does rc_patrolled bit... |
861 | 863 | */ |
862 | 864 | public static function maybeMakeEditReviewed( |
863 | 865 | $article, $rev, $baseRevId = false, $user = null |
— | — | @@ -874,22 +876,17 @@ |
875 | 877 | $title->resetArticleID( $rev->getPage() ); // Avoid extra DB hit and lag issues |
876 | 878 | # Get what was just the current revision ID |
877 | 879 | $prevRevId = $rev->getParentId(); |
878 | | - $prevTimestamp = $frev = $flags = null; |
| 880 | + $frev = $flags = null; |
879 | 881 | # Get edit timestamp. Existance already validated by EditPage.php. |
880 | 882 | $editTimestamp = $wgRequest->getVal( 'wpEdittime' ); |
881 | 883 | # Is the page manually checked off to be reviewed? |
882 | | - if ( $wgRequest->getCheck( 'wpReviewEdit' ) && $user->isAllowed( 'review' ) ) { |
883 | | - # Check wpEdittime against the previous edit for verification |
884 | | - if ( $prevRevId ) { |
885 | | - $prevTimestamp = Revision::getTimestampFromId( $title, $prevRevId ); |
| 884 | + if ( $editTimestamp |
| 885 | + && $wgRequest->getCheck( 'wpReviewEdit' ) |
| 886 | + && $user->isAllowed( 'review' ) ) |
| 887 | + { |
| 888 | + if( self::editCheckReview( $article, $rev, $user, $editTimestamp ) ) { |
| 889 | + return true; // reviewed...done! |
886 | 890 | } |
887 | | - # Review this revision of the page unless edit was auto-merged in between... |
888 | | - if ( !$editTimestamp || !$prevTimestamp || $prevTimestamp == $editTimestamp ) { |
889 | | - # Note: articlesavecomplete hook does rc_patrolled bit |
890 | | - $ok = FlaggedRevs::autoReviewEdit( |
891 | | - $article, $user, $rev->getText(), $rev, $flags, false ); |
892 | | - if ( $ok ) return true; // done! |
893 | | - } |
894 | 891 | } |
895 | 892 | # All cases below require auto-review of edits to be enabled |
896 | 893 | if( !FlaggedRevs::autoReviewEdits() ) { |
— | — | @@ -899,9 +896,7 @@ |
900 | 897 | $isNullEdit = (bool)$baseRevId; |
901 | 898 | # Get the revision ID the incoming one was based off... |
902 | 899 | if ( !$baseRevId && $prevRevId ) { |
903 | | - if ( is_null( $prevTimestamp ) ) { // may already be set |
904 | | - $prevTimestamp = Revision::getTimestampFromId( $title, $prevRevId ); |
905 | | - } |
| 900 | + $prevTimestamp = Revision::getTimestampFromId( $title, $prevRevId ); |
906 | 901 | # The user just made an edit. The one before that should have |
907 | 902 | # been the current version. If not reflected in wpEdittime, an |
908 | 903 | # edit may have been auto-merged in between, in that case, discard |
— | — | @@ -916,9 +911,10 @@ |
917 | 912 | } |
918 | 913 | } |
919 | 914 | # Self-reversions to the stable version by anyone can be auto-reviewed... |
920 | | - $srev = FlaggedRevision::newFromStable( $title, FR_MASTER ); |
| 915 | + $srev = $fa->getStableRev( FR_MASTER ); |
921 | 916 | if ( $srev && self::isSelfRevertToStable( $rev, $srev, $baseRevId, $user ) ) { |
922 | 917 | $flags = $srev->getTags(); // use old tags |
| 918 | + # Review this revision of the page... |
923 | 919 | FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags ); |
924 | 920 | return true; // done! |
925 | 921 | } |
— | — | @@ -941,14 +937,42 @@ |
942 | 938 | // Is this an edit directly to the stable version? Is it a new page? |
943 | 939 | if ( $isAllowed && ( $reviewableNewPage || !is_null( $frev ) ) ) { |
944 | 940 | if ( $isNullEdit && $frev ) { |
945 | | - $flags = $frev->getTags(); // Null edits always keep previous tags |
| 941 | + $flags = $frev->getTags(); // Dummy edits always keep previous tags |
946 | 942 | } |
947 | | - # Review this revision of the page. Let articlesavecomplete hook do rc_patrolled bit... |
| 943 | + # Review this revision of the page... |
948 | 944 | FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags ); |
949 | 945 | } |
950 | 946 | return true; |
951 | 947 | } |
952 | | - |
| 948 | + |
| 949 | + // Review $rev if $editTimestamp matches the previous revision's timestamp. |
| 950 | + // Otherwise, review the revision that has $editTimestamp as its timestamp value. |
| 951 | + protected static function editCheckReview( $article, $rev, $user, $editTimestamp ) { |
| 952 | + $prevRevId = $rev->getParentId(); |
| 953 | + $prevTimestamp = $flags = null; |
| 954 | + $title = $article->getTitle(); // convenience |
| 955 | + # Check wpEdittime against the former current rev for verification |
| 956 | + if ( $prevRevId ) { |
| 957 | + $prevTimestamp = Revision::getTimestampFromId( $title, $prevRevId ); |
| 958 | + } |
| 959 | + # Is $rev is an edit to an existing page? |
| 960 | + if ( $prevTimestamp ) { |
| 961 | + # Check wpEdittime against the former current revision's time. |
| 962 | + # If an edit was auto-merged in between, review only up to what |
| 963 | + # was the current rev when this user started editing the page. |
| 964 | + if ( $editTimestamp != $prevTimestamp ) { |
| 965 | + $dbw = wfGetDB( DB_MASTER ); |
| 966 | + $rev = Revision::loadFromTimestamp( $dbw, $title, $editTimestamp ); |
| 967 | + if ( !$rev ) { |
| 968 | + return false; // deleted? |
| 969 | + } |
| 970 | + } |
| 971 | + } |
| 972 | + # Review this revision of the page... |
| 973 | + return FlaggedRevs::autoReviewEdit( |
| 974 | + $article, $user, $rev->getText(), $rev, $flags, false ); |
| 975 | + } |
| 976 | + |
953 | 977 | /** |
954 | 978 | * Check if a user reverted himself to the stable version |
955 | 979 | */ |
— | — | @@ -986,43 +1010,64 @@ |
987 | 1011 | |
988 | 1012 | /** |
989 | 1013 | * When an user makes a null-edit we sometimes want to review it... |
| 1014 | + * (a) Null undo or rollback |
| 1015 | + * (b) Null edit with review box checked |
990 | 1016 | */ |
991 | 1017 | public static function maybeNullEditReview( |
992 | 1018 | $article, $user, $text, $summary, $m, $a, $b, $flags, $rev, &$status, $baseId |
993 | 1019 | ) { |
994 | 1020 | global $wgRequest; |
995 | | - # Must be in reviewable namespace |
996 | | - $title = $article->getTitle(); |
997 | 1021 | # Revision must *be* null (null edit). We also need the user who made the edit. |
998 | | - if ( !$user || $rev !== null || !FlaggedRevs::inReviewNamespace( $title ) ) { |
| 1022 | + if ( !$user || $rev !== null ) { |
999 | 1023 | return true; |
1000 | 1024 | } |
| 1025 | + $fa = FlaggedArticle::getArticleInstance( $article ); |
| 1026 | + if ( !$fa->isReviewable( FR_MASTER ) ) { |
| 1027 | + return true; // page is not reviewable |
| 1028 | + } |
| 1029 | + $title = $article->getTitle(); // convenience |
1001 | 1030 | # Get the current revision ID |
1002 | 1031 | $rev = Revision::newFromTitle( $title ); |
| 1032 | + if( !$rev ) { |
| 1033 | + return true; // wtf? |
| 1034 | + } |
1003 | 1035 | $flags = null; |
1004 | 1036 | # Is this a rollback/undo that didn't change anything? |
1005 | | - if ( $rev && $baseId ) { |
| 1037 | + if ( $baseId > 0 ) { |
1006 | 1038 | $frev = FlaggedRevision::newFromTitle( $title, $baseId ); |
1007 | 1039 | # Was the edit that we tried to revert to reviewed? |
1008 | 1040 | if ( $frev ) { |
1009 | | - FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags ); |
1010 | | - FlaggedRevs::markRevisionPatrolled( $rev ); // Make sure it is now marked patrolled... |
| 1041 | + # Review this revision of the page... |
| 1042 | + $ok = FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags ); |
| 1043 | + if( $ok ) { |
| 1044 | + FlaggedRevs::markRevisionPatrolled( $rev ); // reviewed -> patrolled |
| 1045 | + return true; |
| 1046 | + } |
1011 | 1047 | } |
1012 | 1048 | } |
1013 | 1049 | # Get edit timestamp, it must exist. |
1014 | 1050 | $editTimestamp = $wgRequest->getVal( 'wpEdittime' ); |
1015 | 1051 | # Is the page checked off to be reviewed? |
1016 | | - if ( $rev && $editTimestamp && $wgRequest->getCheck( 'wpReviewEdit' ) |
| 1052 | + if ( $editTimestamp |
| 1053 | + && $wgRequest->getCheck( 'wpReviewEdit' ) |
1017 | 1054 | && $user->isAllowed( 'review' ) ) |
1018 | 1055 | { |
1019 | | - # Review this revision of the page. Let articlesavecomplete hook do rc_patrolled bit. |
1020 | | - # Don't do so if an edit was auto-merged in between though... |
1021 | | - if ( $rev->getTimestamp() == $editTimestamp ) { |
1022 | | - FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), |
1023 | | - $rev, $flags, false ); |
1024 | | - FlaggedRevs::markRevisionPatrolled( $rev ); // Make sure it is now marked patrolled... |
1025 | | - return true; // done! |
| 1056 | + # Check wpEdittime against current revision's time. |
| 1057 | + # If an edit was auto-merged in between, review only up to what |
| 1058 | + # was the current rev when this user started editing the page. |
| 1059 | + if ( $rev->getTimestamp() != $editTimestamp ) { |
| 1060 | + $dbw = wfGetDB( DB_MASTER ); |
| 1061 | + $rev = Revision::loadFromTimestamp( $dbw, $title, $editTimestamp ); |
| 1062 | + if( !$rev ) { |
| 1063 | + return true; // deleted? |
| 1064 | + } |
1026 | 1065 | } |
| 1066 | + # Review this revision of the page... |
| 1067 | + $ok = FlaggedRevs::autoReviewEdit( |
| 1068 | + $article, $user, $rev->getText(), $rev, $flags, false ); |
| 1069 | + if ( $ok ) { |
| 1070 | + FlaggedRevs::markRevisionPatrolled( $rev ); // reviewed -> patrolled |
| 1071 | + } |
1027 | 1072 | } |
1028 | 1073 | return true; |
1029 | 1074 | } |
— | — | @@ -1620,7 +1665,8 @@ |
1621 | 1666 | return true; |
1622 | 1667 | } |
1623 | 1668 | $fa = FlaggedArticle::getTitleInstance( $title ); |
1624 | | - if ( $srev = $fa->getStableRev() ) { |
| 1669 | + $srev = $fa->getStableRev(); |
| 1670 | + if ( $srev ) { |
1625 | 1671 | $view = FlaggedArticleView::singleton(); |
1626 | 1672 | # If synced, nothing special here... |
1627 | 1673 | if ( $srev->getRevId() != $article->getLatest() && $view->pageOverride() ) { |
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php |
— | — | @@ -734,7 +734,7 @@ |
735 | 735 | } |
736 | 736 | # Add a notice if there are pending edits... |
737 | 737 | $frev = $this->article->getStableRev(); |
738 | | - if ( $frev && $frev->getRevId() < $this->article->getLatest() ) { |
| 738 | + if ( $frev && $frev->getRevId() != $this->article->getLatest() ) { |
739 | 739 | $revsSince = FlaggedRevs::getRevCountSince( $this->article, $frev->getRevId() ); |
740 | 740 | $tag = "<div id='mw-fr-revisiontag-edit' class='flaggedrevs_notice plainlinks'>" . |
741 | 741 | FlaggedRevsXML::lockStatusIcon( $this->article ) . # flag protection icon as needed |
— | — | @@ -866,7 +866,7 @@ |
867 | 867 | return true; // nothing to do |
868 | 868 | } |
869 | 869 | $frev = $this->article->getStableRev(); |
870 | | - if( $frev ) { |
| 870 | + if( $frev && $frev->getRevId() != $this->article->getLatest() ) { |
871 | 871 | $revsSince = FlaggedRevs::getRevCountSince( $this->article, $frev->getRevId() ); |
872 | 872 | if( $revsSince ) { |
873 | 873 | $s .= "<div class='flaggedrevs_editnotice plainlinks'>" . |