r34987 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34986‎ | r34987 | r34988 >
Date:17:53, 17 May 2008
Author:aaron
Status:old
Tags:
Comment:
* Add higher level newRevisionFromEditComplete hook
* Use this hook for autoreviewing. Merge to one function again.
* Remove template ID query for $usestabletemplates, not needed
* Improve includes change diff if $usestabletemplates is on
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/SpecialImport.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/filerepo/ICRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -800,6 +800,11 @@
801801 instead.
802802 $tools: array of tools
803803
 804+'newRevisionFromEditComplete': called when a revision was inserted due to an edit
 805+$title: the page title
 806+$rev: the new revision
 807+$baseID: the revision ID this was based off, if any
 808+
804809 'OutputPageBeforeHTML': a page has been processed by the parser and
805810 the resulting HTML is about to be displayed.
806811 $parserOutput: the parserOutput (object) that corresponds to the page
Index: trunk/phase3/includes/SpecialImport.php
@@ -216,9 +216,9 @@
217217
218218 $comment = $detail; // quick
219219 $dbw = wfGetDB( DB_MASTER );
220 - $nullRevision = Revision::newNullRevision(
221 - $dbw, $title->getArticleId(), $comment, true );
 220+ $nullRevision = Revision::newNullRevision( $dbw, $title->getArticleId(), $comment, true );
222221 $nullRevision->insertOn( $dbw );
 222+ wfRunHooks( 'newRevisionFromEditComplete', array($title, $nullRevision, false) );
223223 # Update page record
224224 $article = new Article( $title );
225225 $article->updateRevisionOn( $dbw, $nullRevision );
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 $baseRevId, the revision ID this edit was based off, if any
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__ );
@@ -1445,6 +1446,8 @@
14461447
14471448 $dbw->begin();
14481449 $revisionId = $revision->insertOn( $dbw );
 1450+
 1451+ wfRunHooks( 'newRevisionFromEditComplete', array($this->mTitle, $revision, $baseRevId) );
14491452
14501453 # Update page
14511454 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
@@ -1513,6 +1516,8 @@
15141517 'text' => $text
15151518 ) );
15161519 $revisionId = $revision->insertOn( $dbw );
 1520+
 1521+ wfRunHooks( 'newRevisionFromEditComplete', array($this->mTitle, $revision, false) );
15171522
15181523 $this->mTitle->resetArticleID( $newid );
15191524
@@ -1865,6 +1870,8 @@
18661871 # Insert a null revision
18671872 $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true );
18681873 $nullRevId = $nullRevision->insertOn( $dbw );
 1874+
 1875+ wfRunHooks( 'newRevisionFromEditComplete', array($this->mTitle, $nullRevision, false) );
18691876
18701877 # Update page record
18711878 $dbw->update( 'page',
@@ -2524,7 +2531,7 @@
25252532
25262533 if( $bot && ($wgUser->isAllowed('markbotedits') || $wgUser->isAllowed('bot')) )
25272534 $flags |= EDIT_FORCE_BOT;
2528 - $this->doEdit( $target->getText(), $summary, $flags );
 2535+ $this->doEdit( $target->getText(), $summary, $flags, $target->getId() );
25292536
25302537 wfRunHooks( 'ArticleRollbackComplete', array( $this, $wgUser, $target ) );
25312538
@@ -2967,6 +2974,7 @@
29682975 'minor_edit' => $minor ? 1 : 0,
29692976 ) );
29702977 $revision->insertOn( $dbw );
 2978+ wfRunHooks( 'newRevisionFromEditComplete', array($this->mTitle, $revision, false) );
29712979 $this->updateRevisionOn( $dbw, $revision );
29722980 $dbw->commit();
29732981
Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -859,6 +859,7 @@
860860 # Create a null revision
861861 $nullRevision = Revision::newNullRevision( $dbw, $descTitle->getArticleId(), $log->getRcComment(), false );
862862 $nullRevision->insertOn( $dbw );
 863+ wfRunHooks( 'newRevisionFromEditComplete', array($descTitle, $nullRevision, false) );
863864 $article->updateRevisionOn( $dbw, $nullRevision );
864865
865866 # Invalidate the cache for the description page
Index: trunk/phase3/includes/filerepo/ICRepo.php
@@ -286,6 +286,7 @@
287287 # Create a null revision
288288 $nullRevision = Revision::newNullRevision( $dbw, $descTitle->getArticleId(), $log->getRcComment(), false );
289289 $nullRevision->insertOn( $dbw );
 290+ wfRunHooks( 'newRevisionFromEditComplete', array($descTitle, $nullRevision, false) );
290291 $article->updateRevisionOn( $dbw, $nullRevision );
291292
292293 # Invalidate the cache for the description page
Index: trunk/phase3/includes/Title.php
@@ -2599,6 +2599,7 @@
26002600 # Save a null revision in the page's history notifying of the move
26012601 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
26022602 $nullRevId = $nullRevision->insertOn( $dbw );
 2603+ wfRunHooks( 'newRevisionFromEditComplete', array($nt, $nullRevision, false) );
26032604
26042605 # Change the name of the target page:
26052606 $dbw->update( 'page',
@@ -2625,6 +2626,7 @@
26262627 'comment' => $comment,
26272628 'text' => $redirectText ) );
26282629 $redirectRevision->insertOn( $dbw );
 2630+ wfRunHooks( 'newRevisionFromEditComplete', array($this, $redirectRevision, false) );
26292631 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
26302632
26312633 # Now, we record the link from the redirect to the new title.
@@ -2686,6 +2688,7 @@
26872689 # Save a null revision in the page's history notifying of the move
26882690 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
26892691 $nullRevId = $nullRevision->insertOn( $dbw );
 2692+ wfRunHooks( 'newRevisionFromEditComplete', array($nt, $nullRevision, false) );
26902693
26912694 # Rename page entry
26922695 $dbw->update( 'page',
@@ -2712,6 +2715,7 @@
27132716 'comment' => $comment,
27142717 'text' => $redirectText ) );
27152718 $redirectRevision->insertOn( $dbw );
 2719+ wfRunHooks( 'newRevisionFromEditComplete', array($this, $redirectRevision, false) );
27162720 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
27172721
27182722 # Record the just-created redirect's linking to the page
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -284,8 +284,7 @@
285285 $wgHooks['OutputPageParserOutput'][] = 'FlaggedRevs::outputInjectTimestamps';
286286 # Auto-reviewing
287287 $wgHooks['ArticleSaveComplete'][] = 'FlaggedRevs::autoMarkPatrolled';
288 - $wgHooks['RevisionInsertComplete'][] = 'FlaggedRevs::maybeMakeEditReviewed';
289 - $wgHooks['ArticleRollbackComplete'][] = 'FlaggedRevs::maybeMakeRollbackReviewed';
 288+ $wgHooks['newRevisionFromEditComplete'][] = 'FlaggedRevs::maybeMakeEditReviewed';
290289 # Disallow moves of stable pages
291290 $wgHooks['userCan'][] = 'FlaggedRevs::userCanMove';
292291 $wgHooks['userCan'][] = 'FlaggedRevs::userCanView';
@@ -477,20 +476,12 @@
478477 $wgParser->fr_isStable = false;
479478 $wgParser->fr_includesMatched = false;
480479 # Do we need to set the template uses via DB?
481 - if( $reparsed ) {
 480+ if( $reparsed && !$wgUseStableTemplates ) {
482481 $dbr = wfGetDB( DB_SLAVE );
483 - if( $wgUseStableTemplates ) {
484 - $res = $dbr->select( array('flaggedtemplates','page','flaggedpages'),
485 - array( 'ft_namespace', 'ft_title', 'fp_stable AS rev_id', 'page_id' ),
486 - array( 'ft_rev_id' => $id, 'page_namespace = ft_namespace', 'page_title = ft_title',
487 - 'fp_page_id = page_id' ),
488 - __METHOD__ );
489 - } else {
490 - $res = $dbr->select( array('flaggedtemplates','revision'),
491 - array( 'ft_namespace', 'ft_title', 'ft_tmp_rev_id AS rev_id', 'rev_page AS page_id' ),
492 - array( 'ft_rev_id' => $id, 'rev_id = ft_rev_id' ),
493 - __METHOD__ );
494 - }
 482+ $res = $dbr->select( array('flaggedtemplates','revision'),
 483+ array( 'ft_namespace', 'ft_title', 'ft_tmp_rev_id AS rev_id', 'rev_page AS page_id' ),
 484+ array( 'ft_rev_id' => $id, 'rev_id = ft_rev_id' ),
 485+ __METHOD__ );
495486 # Add template metadata to output
496487 $maxTempID = 0;
497488 while( $row = $res->fetchObject() ) {
@@ -1934,64 +1925,31 @@
19351926 }
19361927
19371928 /**
1938 - * Was this request an edit to said title?
1939 - * @param Title $title
1940 - * @param Revision $rev
1941 - */
1942 - public static function revSubmitted( $title, $rev ) {
1943 - global $wgRequest, $wgUser;
1944 - # Request was submitted
1945 - if( !$wgRequest->wasPosted() ) {
1946 - return false;
1947 - }
1948 - # Sent to page title or Special:MovePage
1949 - $move = SpecialPage::getTitleFor( 'MovePage' );
1950 - if( !in_array( $wgRequest->getVal('title'), array($title->getPrefixedDBkey(),$move->getPrefixedDBkey()) ) ) {
1951 - return false;
1952 - }
1953 - # Must be by this user
1954 - if( $wgUser->getId() ) {
1955 - if( $rev->getUser() != $wgUser->getId() ) {
1956 - return false;
1957 - }
1958 - # Must be by this IP
1959 - } else {
1960 - if( $rev->getRawUserText() != $wgUser->getName() ) {
1961 - return false;
1962 - }
1963 - }
1964 - return true;
1965 - }
1966 -
1967 - /**
19681929 * When an edit is made by a reviewer, if the current revision is the stable
19691930 * version, try to automatically review it.
19701931 */
1971 - public static function maybeMakeEditReviewed( $rev ) {
 1932+ public static function maybeMakeEditReviewed( $title, $rev, $baseRevId = false ) {
19721933 global $wgFlaggedRevsAutoReview, $wgFlaggedArticle, $wgRequest;
19731934 # Get the user
19741935 $user = User::newFromId( $rev->getUser() );
19751936 if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') )
19761937 return true;
1977 - # GetTitle() for revisions uses slaves and wants page_id,rev_id to
1978 - # match...this is bad if we *just* added it.
1979 - $title = $rev->getTitle() ? $rev->getTitle() : Title::newFromID( $rev->getPage(), GAID_FOR_UPDATE );
19801938 # Must be in reviewable namespace
19811939 if( !$title || !self::isPageReviewable( $title ) ) {
19821940 return true;
19831941 }
1984 - # For edits from normal form submits only!
1985 - if( !self::revSubmitted( $title, $rev ) ) {
1986 - return true;
1987 - }
19881942 $frev = null;
19891943 $reviewableNewPage = false;
1990 - # Get the revision the incoming one was based off
1991 - $baseRevID = $wgRequest->getIntOrNull('baseRevId');
1992 - # If baseRevId not given, assume the previous
1993 - $baseRevID = $baseRevID ? $baseRevID : $title->getPreviousRevisionId( $rev->getId(), GAID_FOR_UPDATE );
 1944+ # Get the revision ID the incoming one was based off
 1945+ $baseRevID = $baseRevId ? $baseRevId : $wgRequest->getIntOrNull('baseRevId');
 1946+ # Get what was just the current revision ID
 1947+ $prevRevID = $title->getPreviousRevisionId( $rev->getId(), GAID_FOR_UPDATE );
 1948+ # If baseRevId not given, assume the previous revision ID
 1949+ $baseRevID = $baseRevID ? $baseRevID : $prevRevID;
19941950 if( $baseRevID ) {
19951951 $frev = self::getFlaggedRev( $title, $baseRevID, false, true, $rev->getPage() );
 1952+ # If the base revision was not reviewed, check if the previous one was
 1953+ $frev = $frev ? $frev : self::getFlaggedRev( $title, $prevRevID, false, true, $rev->getPage() );
19961954 } else {
19971955 $prevRevID = $title->getPreviousRevisionId( $rev->getId(), GAID_FOR_UPDATE );
19981956 $prevRev = $prevRevID ? Revision::newFromID( $prevRevID ) : null;
@@ -2019,33 +1977,6 @@
20201978 }
20211979
20221980 /**
2023 - * When a rollback is made by a reviwer, try to automatically review it.
2024 - */
2025 - public static function maybeMakeRollbackReviewed( $article, $user, $rev ) {
2026 - global $wgFlaggedRevsAutoReview, $wgFlaggedArticle;
2027 - if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') )
2028 - return true;
2029 - # Must be in reviewable namespace
2030 - if( !self::isPageReviewable( $article->getTitle() ) )
2031 - return true;
2032 - # Was this revision flagged?
2033 - $frev = self::getFlaggedRev( $article->getTitle(), $rev->getId() );
2034 - if( !is_null($frev) ) {
2035 - # Assume basic flagging level
2036 - $flags = array();
2037 - foreach( self::$dimensions as $tag => $minQL ) {
2038 - $flags[$tag] = 1;
2039 - }
2040 - $newRev = Revision::newFromId( $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE) );
2041 - if( $newRev ) {
2042 - self::autoReviewEdit( $article, $user, $rev->getText(), $newRev, $flags );
2043 - self::articleLinksUpdate( $article ); // lame...
2044 - }
2045 - }
2046 - return true;
2047 - }
2048 -
2049 - /**
20501981 * When an edit is made to a page that can't be reviewed, autopatrol if allowed.
20511982 * This is not loggged for perfomance reasons and no one cares if talk pages and such
20521983 * are autopatrolled.
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -726,18 +726,20 @@
727727 # Make a list of each changed template...
728728 $dbr = wfGetDB( DB_SLAVE );
729729 global $wgUseStableTemplates;
 730+ // Get templates where the current and stable are not the same revision
730731 if( $wgUseStableTemplates ) {
731732 $ret = $dbr->select( array('flaggedtemplates','page','flaggedpages'),
732 - array( 'ft_namespace', 'ft_title', 'ft_tmp_rev_id' ),
 733+ array( 'ft_namespace', 'ft_title', 'fp_stable AS rev_id' ),
733734 array( 'ft_rev_id' => $frev->getRevId(),
734735 'page_namespace = ft_namespace',
735736 'page_title = ft_title',
736737 'fp_page_id = page_id',
737738 'fp_stable != page_latest' ),
738739 __METHOD__ );
 740+ // Get templates that are newer than the ones of the stable version of this page
739741 } else {
740742 $ret = $dbr->select( array('flaggedtemplates','page'),
741 - array( 'ft_namespace', 'ft_title', 'ft_tmp_rev_id' ),
 743+ array( 'ft_namespace', 'ft_title', 'ft_tmp_rev_id AS rev_id' ),
742744 array( 'ft_rev_id' => $frev->getRevId(),
743745 'page_namespace = ft_namespace',
744746 'page_title = ft_title',
@@ -747,11 +749,12 @@
748750 while( $row = $dbr->fetchObject( $ret ) ) {
749751 $title = Title::makeTitle( $row->ft_namespace, $row->ft_title );
750752 $changeList[] = $skin->makeKnownLinkObj( $title, $title->GetPrefixedText(),
751 - "diff=cur&oldid=" . $row->ft_tmp_rev_id );
 753+ "diff=cur&oldid=" . $row->rev_id );
752754 }
753755
754756 # And images...
755757 global $wgUseStableImages;
 758+ // Get images where the current and stable are not the same revision
756759 if( $wgUseStableImages ) {
757760 $ret = $dbr->select( array('flaggedimages','page','flaggedpages','flaggedrevs','image'),
758761 array( 'fi_name' ),
@@ -764,6 +767,7 @@
765768 'img_name = fi_name',
766769 'fr_img_sha1 != img_sha1' ),
767770 __METHOD__ );
 771+ // Get images that are newer than the ones of the stable version of this page
768772 } else {
769773 $ret = $dbr->select( array('flaggedimages','image'),
770774 array( 'fi_name' ),

Status & tagging log