r63585 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63584‎ | r63585 | r63586 >
Date:07:28, 11 March 2010
Author:aaron
Status:resolved
Tags:
Comment:
* Improved handling of intermediate edits and "review changes" checkbox
* Split out editCheckReview() from maybeMakeEditReviewed()
* Edge case fix for review failure (don't mark patrolled)
* Made FR_MASTER flag skip process cache (which can have slave/old data)
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedArticleView.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -91,25 +91,21 @@
9292 /**
9393 * Get latest quality rev, if not, the latest reviewed one
9494 * @param int $flags
95 - * @return Row
 95+ * @return mixed (FlaggedRevision/false)
9696 */
9797 public function getStableRev( $flags = 0 ) {
98 - if ( $this->stableRev === false ) {
99 - return null; // We already looked and found nothing...
100 - }
10198 # Cached results available?
102 - if ( !is_null( $this->stableRev ) ) {
 99+ if ( !($flags & FR_MASTER) && $this->stableRev !== null ) {
103100 return $this->stableRev;
104101 }
105102 # Do we have one?
106103 $srev = FlaggedRevision::newFromStable( $this->getTitle(), $flags );
107104 if ( $srev ) {
108105 $this->stableRev = $srev;
109 - return $srev;
110106 } else {
111107 $this->stableRev = false;
112 - return null;
113108 }
 109+ return $this->stableRev;
114110 }
115111
116112 /**
@@ -119,7 +115,7 @@
120116 */
121117 public function getVisibilitySettings( $flags = 0 ) {
122118 # Cached results available?
123 - if ( !is_null( $this->pageConfig ) ) {
 119+ if ( !($flags & FR_MASTER) && $this->pageConfig !== null ) {
124120 return $this->pageConfig;
125121 }
126122 # Get the content page, skip talk
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -857,6 +857,8 @@
858858 * edit was made from is the stable version, or the edit is a reversion
859859 * to the stable version, then try to automatically review it.
860860 * 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...
861863 */
862864 public static function maybeMakeEditReviewed(
863865 $article, $rev, $baseRevId = false, $user = null
@@ -874,22 +876,17 @@
875877 $title->resetArticleID( $rev->getPage() ); // Avoid extra DB hit and lag issues
876878 # Get what was just the current revision ID
877879 $prevRevId = $rev->getParentId();
878 - $prevTimestamp = $frev = $flags = null;
 880+ $frev = $flags = null;
879881 # Get edit timestamp. Existance already validated by EditPage.php.
880882 $editTimestamp = $wgRequest->getVal( 'wpEdittime' );
881883 # 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!
886890 }
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 - }
894891 }
895892 # All cases below require auto-review of edits to be enabled
896893 if( !FlaggedRevs::autoReviewEdits() ) {
@@ -899,9 +896,7 @@
900897 $isNullEdit = (bool)$baseRevId;
901898 # Get the revision ID the incoming one was based off...
902899 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 );
906901 # The user just made an edit. The one before that should have
907902 # been the current version. If not reflected in wpEdittime, an
908903 # edit may have been auto-merged in between, in that case, discard
@@ -916,9 +911,10 @@
917912 }
918913 }
919914 # 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 );
921916 if ( $srev && self::isSelfRevertToStable( $rev, $srev, $baseRevId, $user ) ) {
922917 $flags = $srev->getTags(); // use old tags
 918+ # Review this revision of the page...
923919 FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags );
924920 return true; // done!
925921 }
@@ -941,14 +937,42 @@
942938 // Is this an edit directly to the stable version? Is it a new page?
943939 if ( $isAllowed && ( $reviewableNewPage || !is_null( $frev ) ) ) {
944940 if ( $isNullEdit && $frev ) {
945 - $flags = $frev->getTags(); // Null edits always keep previous tags
 941+ $flags = $frev->getTags(); // Dummy edits always keep previous tags
946942 }
947 - # Review this revision of the page. Let articlesavecomplete hook do rc_patrolled bit...
 943+ # Review this revision of the page...
948944 FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags );
949945 }
950946 return true;
951947 }
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+
953977 /**
954978 * Check if a user reverted himself to the stable version
955979 */
@@ -986,43 +1010,64 @@
9871011
9881012 /**
9891013 * 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
9901016 */
9911017 public static function maybeNullEditReview(
9921018 $article, $user, $text, $summary, $m, $a, $b, $flags, $rev, &$status, $baseId
9931019 ) {
9941020 global $wgRequest;
995 - # Must be in reviewable namespace
996 - $title = $article->getTitle();
9971021 # 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 ) {
9991023 return true;
10001024 }
 1025+ $fa = FlaggedArticle::getArticleInstance( $article );
 1026+ if ( !$fa->isReviewable( FR_MASTER ) ) {
 1027+ return true; // page is not reviewable
 1028+ }
 1029+ $title = $article->getTitle(); // convenience
10011030 # Get the current revision ID
10021031 $rev = Revision::newFromTitle( $title );
 1032+ if( !$rev ) {
 1033+ return true; // wtf?
 1034+ }
10031035 $flags = null;
10041036 # Is this a rollback/undo that didn't change anything?
1005 - if ( $rev && $baseId ) {
 1037+ if ( $baseId > 0 ) {
10061038 $frev = FlaggedRevision::newFromTitle( $title, $baseId );
10071039 # Was the edit that we tried to revert to reviewed?
10081040 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+ }
10111047 }
10121048 }
10131049 # Get edit timestamp, it must exist.
10141050 $editTimestamp = $wgRequest->getVal( 'wpEdittime' );
10151051 # Is the page checked off to be reviewed?
1016 - if ( $rev && $editTimestamp && $wgRequest->getCheck( 'wpReviewEdit' )
 1052+ if ( $editTimestamp
 1053+ && $wgRequest->getCheck( 'wpReviewEdit' )
10171054 && $user->isAllowed( 'review' ) )
10181055 {
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+ }
10261065 }
 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+ }
10271072 }
10281073 return true;
10291074 }
@@ -1620,7 +1665,8 @@
16211666 return true;
16221667 }
16231668 $fa = FlaggedArticle::getTitleInstance( $title );
1624 - if ( $srev = $fa->getStableRev() ) {
 1669+ $srev = $fa->getStableRev();
 1670+ if ( $srev ) {
16251671 $view = FlaggedArticleView::singleton();
16261672 # If synced, nothing special here...
16271673 if ( $srev->getRevId() != $article->getLatest() && $view->pageOverride() ) {
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
@@ -734,7 +734,7 @@
735735 }
736736 # Add a notice if there are pending edits...
737737 $frev = $this->article->getStableRev();
738 - if ( $frev && $frev->getRevId() < $this->article->getLatest() ) {
 738+ if ( $frev && $frev->getRevId() != $this->article->getLatest() ) {
739739 $revsSince = FlaggedRevs::getRevCountSince( $this->article, $frev->getRevId() );
740740 $tag = "<div id='mw-fr-revisiontag-edit' class='flaggedrevs_notice plainlinks'>" .
741741 FlaggedRevsXML::lockStatusIcon( $this->article ) . # flag protection icon as needed
@@ -866,7 +866,7 @@
867867 return true; // nothing to do
868868 }
869869 $frev = $this->article->getStableRev();
870 - if( $frev ) {
 870+ if( $frev && $frev->getRevId() != $this->article->getLatest() ) {
871871 $revsSince = FlaggedRevs::getRevCountSince( $this->article, $frev->getRevId() );
872872 if( $revsSince ) {
873873 $s .= "<div class='flaggedrevs_editnotice plainlinks'>" .

Follow-up revisions

RevisionCommit summaryAuthorDate
r63818Follow-up r63585: fixed $frev existence checksaaron14:51, 16 March 2010

Status & tagging log