r34928 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34927‎ | r34928 | r34929 >
Date:18:22, 16 May 2008
Author:aaron
Status:old
Tags:
Comment:
Improve efficiency of autoreviewing of edits rollbacks and merge into main function
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Revision.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -920,6 +920,7 @@
921921 'RevisionInsertComplete': called after a revision is inserted into the DB
922922 $revision: the Revision
923923 $edit: was this a new edit?
 924+$baseID: what revision ID was this revision based off? (false if none)
924925
925926 'SavePreferences': called at the end of PreferencesForm::savePreferences;
926927 returning false prevents the preferences from being saved.
Index: trunk/phase3/includes/Article.php
@@ -1362,10 +1362,11 @@
13631363 * EDIT_NEW is specified and the article does exist, a duplicate key error will cause an exception
13641364 * to be thrown from the Database. These two conditions are also possible with auto-detection due
13651365 * to MediaWiki's performance-optimised locking strategy.
 1366+ * @param integer $baseRevID, the revision ID this is based off
13661367 *
13671368 * @return bool success
13681369 */
1369 - function doEdit( $text, $summary, $flags = 0 ) {
 1370+ function doEdit( $text, $summary, $flags = 0, $baseRevID = false ) {
13701371 global $wgUser, $wgDBtransactions;
13711372
13721373 wfProfileIn( __METHOD__ );
@@ -1444,7 +1445,7 @@
14451446 ) );
14461447
14471448 $dbw->begin();
1448 - $revisionId = $revision->insertOn( $dbw, true );
 1449+ $revisionId = $revision->insertOn( $dbw, true, $baseRevID );
14491450
14501451 # Update page
14511452 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
@@ -2524,7 +2525,7 @@
25252526
25262527 if( $bot && ($wgUser->isAllowed('markbotedits') || $wgUser->isAllowed('bot')) )
25272528 $flags |= EDIT_FORCE_BOT;
2528 - $this->doEdit( $target->getText(), $summary, $flags );
 2529+ $this->doEdit( $target->getText(), $summary, $flags, $target->getId() );
25292530
25302531 wfRunHooks( 'ArticleRollbackComplete', array( $this, $wgUser, $target ) );
25312532
Index: trunk/phase3/includes/Revision.php
@@ -708,9 +708,10 @@
709709 *
710710 * @param Database $dbw
711711 * @param bool $edit, was this a new edit? (optional)
 712+ * @param integer $baseID, what revision was this based on? (optional)
712713 * @return int
713714 */
714 - public function insertOn( &$dbw, $edit=false ) {
 715+ public function insertOn( &$dbw, $edit = false, $baseID = false ) {
715716 global $wgDefaultExternalStore;
716717
717718 wfProfileIn( __METHOD__ );
@@ -773,7 +774,7 @@
774775
775776 $this->mId = !is_null($rev_id) ? $rev_id : $dbw->insertId();
776777
777 - wfRunHooks( 'RevisionInsertComplete', array( &$this, $edit ) );
 778+ wfRunHooks( 'RevisionInsertComplete', array( &$this, $edit, $baseID ) );
778779
779780 wfProfileOut( __METHOD__ );
780781 return $this->mId;
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -285,7 +285,6 @@
286286 # Auto-reviewing
287287 $wgHooks['ArticleSaveComplete'][] = 'FlaggedRevs::autoMarkPatrolled';
288288 $wgHooks['RevisionInsertComplete'][] = 'FlaggedRevs::maybeMakeEditReviewed';
289 - $wgHooks['ArticleRollbackComplete'][] = 'FlaggedRevs::maybeMakeRollbackReviewed';
290289 # Disallow moves of stable pages
291290 $wgHooks['userCan'][] = 'FlaggedRevs::userCanMove';
292291 $wgHooks['userCan'][] = 'FlaggedRevs::userCanView';
@@ -1900,35 +1899,10 @@
19011900 }
19021901
19031902 /**
1904 - * Was this request an edit to said title?
1905 - * @param Title $title
1906 - * @param Revision $rev
1907 - */
1908 - public static function revSubmitted( $title, $rev, $edit ) {
1909 - global $wgRequest, $wgUser;
1910 - # Request was submitted
1911 - if( !$edit || !$wgRequest->wasPosted() ) {
1912 - return false;
1913 - }
1914 - # Must be by this user
1915 - if( $wgUser->getId() ) {
1916 - if( $rev->getUser() != $wgUser->getId() ) {
1917 - return false;
1918 - }
1919 - # Must be by this IP
1920 - } else {
1921 - if( $rev->getRawUserText() != $wgUser->getName() ) {
1922 - return false;
1923 - }
1924 - }
1925 - return true;
1926 - }
1927 -
1928 - /**
19291903 * When an edit is made by a reviewer, if the current revision is the stable
19301904 * version, try to automatically review it.
19311905 */
1932 - public static function maybeMakeEditReviewed( $rev, $edit ) {
 1906+ public static function maybeMakeEditReviewed( $rev, $edit, $baseRevID ) {
19331907 global $wgFlaggedRevsAutoReview, $wgFlaggedArticle, $wgRequest;
19341908 # Get the user
19351909 $user = User::newFromId( $rev->getUser() );
@@ -1942,13 +1916,13 @@
19431917 return true;
19441918 }
19451919 # For edits from normal form submits only!
1946 - if( !self::revSubmitted( $title, $rev, $edit ) ) {
 1920+ if( !$edit ) {
19471921 return true;
19481922 }
19491923 $frev = null;
19501924 $reviewableNewPage = false;
1951 - # Get the revision the incoming one was based off
1952 - $baseRevID = $wgRequest->getIntOrNull('baseRevId');
 1925+ # Get the revision the incoming one was based off if
 1926+ $baseRevID = $baseRevID ? $baseRevID : $wgRequest->getIntOrNull('baseRevId');
19531927 # If baseRevId not given, assume the previous
19541928 $baseRevID = $baseRevID ? $baseRevID : $title->getPreviousRevisionId( $rev->getId(), GAID_FOR_UPDATE );
19551929 if( $baseRevID ) {
@@ -1980,33 +1954,6 @@
19811955 }
19821956
19831957 /**
1984 - * When a rollback is made by a reviwer, try to automatically review it.
1985 - */
1986 - public static function maybeMakeRollbackReviewed( $article, $user, $rev ) {
1987 - global $wgFlaggedRevsAutoReview, $wgFlaggedArticle;
1988 - if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') )
1989 - return true;
1990 - # Must be in reviewable namespace
1991 - if( !self::isPageReviewable( $article->getTitle() ) )
1992 - return true;
1993 - # Was this revision flagged?
1994 - $frev = self::getFlaggedRev( $article->getTitle(), $rev->getId() );
1995 - if( !is_null($frev) ) {
1996 - # Assume basic flagging level
1997 - $flags = array();
1998 - foreach( self::$dimensions as $tag => $minQL ) {
1999 - $flags[$tag] = 1;
2000 - }
2001 - $newRev = Revision::newFromId( $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE) );
2002 - if( $newRev ) {
2003 - self::autoReviewEdit( $article, $user, $rev->getText(), $newRev, $flags );
2004 - self::articleLinksUpdate( $article ); // lame...
2005 - }
2006 - }
2007 - return true;
2008 - }
2009 -
2010 - /**
20111958 * When an edit is made to a page that can't be reviewed, autopatrol if allowed.
20121959 * This is not loggged for perfomance reasons and no one cares if talk pages and such
20131960 * are autopatrolled.

Follow-up revisions

RevisionCommit summaryAuthorDate
r34982Revert r34906, r34907, r34928 -- mixing high-level data into low-level storag...brion15:53, 17 May 2008

Status & tagging log