r34982 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34981‎ | r34982 | r34983 >
Date:15:53, 17 May 2008
Author:brion
Status:old
Tags:
Comment:
Revert r34906, r34907, r34928 -- mixing high-level data into low-level storage functions for the sole purpose of passing it off to hooks, which seems very icky to me. It feels like a hook in the wrong place is being used.
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)
  • /trunk/phase3/includes/SpecialImport.php (modified) (history)
  • /trunk/phase3/includes/SpecialUndelete.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
@@ -929,8 +929,6 @@
930930
931931 'RevisionInsertComplete': called after a revision is inserted into the DB
932932 $revision: the Revision
933 -$edit: was this a new edit?
934 -$baseID: what revision ID was this revision based off? (false if none)
935933
936934 'SavePreferences': called at the end of PreferencesForm::savePreferences;
937935 returning false prevents the preferences from being saved.
Index: trunk/phase3/includes/SpecialImport.php
@@ -218,7 +218,7 @@
219219 $dbw = wfGetDB( DB_MASTER );
220220 $nullRevision = Revision::newNullRevision(
221221 $dbw, $title->getArticleId(), $comment, true );
222 - $nullRevision->insertOn( $dbw, true );
 222+ $nullRevision->insertOn( $dbw );
223223 # Update page record
224224 $article = new Article( $title );
225225 $article->updateRevisionOn( $dbw, $nullRevision );
Index: trunk/phase3/includes/Article.php
@@ -1362,11 +1362,10 @@
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
13671366 *
13681367 * @return bool success
13691368 */
1370 - function doEdit( $text, $summary, $flags = 0, $baseRevID = false ) {
 1369+ function doEdit( $text, $summary, $flags = 0 ) {
13711370 global $wgUser, $wgDBtransactions;
13721371
13731372 wfProfileIn( __METHOD__ );
@@ -1445,7 +1444,7 @@
14461445 ) );
14471446
14481447 $dbw->begin();
1449 - $revisionId = $revision->insertOn( $dbw, true, $baseRevID );
 1448+ $revisionId = $revision->insertOn( $dbw );
14501449
14511450 # Update page
14521451 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
@@ -1513,7 +1512,7 @@
15141513 'minor_edit' => $isminor,
15151514 'text' => $text
15161515 ) );
1517 - $revisionId = $revision->insertOn( $dbw, true );
 1516+ $revisionId = $revision->insertOn( $dbw );
15181517
15191518 $this->mTitle->resetArticleID( $newid );
15201519
@@ -2525,7 +2524,7 @@
25262525
25272526 if( $bot && ($wgUser->isAllowed('markbotedits') || $wgUser->isAllowed('bot')) )
25282527 $flags |= EDIT_FORCE_BOT;
2529 - $this->doEdit( $target->getText(), $summary, $flags, $target->getId() );
 2528+ $this->doEdit( $target->getText(), $summary, $flags );
25302529
25312530 wfRunHooks( 'ArticleRollbackComplete', array( $this, $wgUser, $target ) );
25322531
Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -858,7 +858,7 @@
859859 if( $descTitle->exists() ) {
860860 # Create a null revision
861861 $nullRevision = Revision::newNullRevision( $dbw, $descTitle->getArticleId(), $log->getRcComment(), false );
862 - $nullRevision->insertOn( $dbw, true );
 862+ $nullRevision->insertOn( $dbw );
863863 $article->updateRevisionOn( $dbw, $nullRevision );
864864
865865 # Invalidate the cache for the description page
Index: trunk/phase3/includes/filerepo/ICRepo.php
@@ -285,7 +285,7 @@
286286 if( $descTitle->exists() ) {
287287 # Create a null revision
288288 $nullRevision = Revision::newNullRevision( $dbw, $descTitle->getArticleId(), $log->getRcComment(), false );
289 - $nullRevision->insertOn( $dbw, true );
 289+ $nullRevision->insertOn( $dbw );
290290 $article->updateRevisionOn( $dbw, $nullRevision );
291291
292292 # Invalidate the cache for the description page
Index: trunk/phase3/includes/Revision.php
@@ -707,11 +707,9 @@
708708 * number on success and dies horribly on failure.
709709 *
710710 * @param Database $dbw
711 - * @param bool $edit, was this a new edit? (optional)
712 - * @param integer $baseID, what revision was this based on? (optional)
713711 * @return int
714712 */
715 - public function insertOn( &$dbw, $edit = false, $baseID = false ) {
 713+ public function insertOn( &$dbw ) {
716714 global $wgDefaultExternalStore;
717715
718716 wfProfileIn( __METHOD__ );
@@ -774,7 +772,7 @@
775773
776774 $this->mId = !is_null($rev_id) ? $rev_id : $dbw->insertId();
777775
778 - wfRunHooks( 'RevisionInsertComplete', array( &$this, $edit, $baseID ) );
 776+ wfRunHooks( 'RevisionInsertComplete', array( &$this ) );
779777
780778 wfProfileOut( __METHOD__ );
781779 return $this->mId;
Index: trunk/phase3/includes/SpecialUndelete.php
@@ -514,7 +514,7 @@
515515 'deleted' => $unsuppress ? 0 : $row->ar_deleted,
516516 'len' => $row->ar_len
517517 ) );
518 - $revision->insertOn( $dbw, false );
 518+ $revision->insertOn( $dbw );
519519 $restored++;
520520
521521 wfRunHooks( 'ArticleRevisionUndeleted', array( &$this->title, $revision, $row->ar_page_id ) );
Index: trunk/phase3/includes/Title.php
@@ -2598,7 +2598,7 @@
25992599
26002600 # Save a null revision in the page's history notifying of the move
26012601 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
2602 - $nullRevId = $nullRevision->insertOn( $dbw, true );
 2602+ $nullRevId = $nullRevision->insertOn( $dbw );
26032603
26042604 # Change the name of the target page:
26052605 $dbw->update( 'page',
@@ -2624,7 +2624,7 @@
26252625 'page' => $newid,
26262626 'comment' => $comment,
26272627 'text' => $redirectText ) );
2628 - $redirectRevision->insertOn( $dbw, true );
 2628+ $redirectRevision->insertOn( $dbw );
26292629 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
26302630
26312631 # Now, we record the link from the redirect to the new title.
@@ -2685,7 +2685,7 @@
26862686
26872687 # Save a null revision in the page's history notifying of the move
26882688 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
2689 - $nullRevId = $nullRevision->insertOn( $dbw, true );
 2689+ $nullRevId = $nullRevision->insertOn( $dbw );
26902690
26912691 # Rename page entry
26922692 $dbw->update( 'page',
@@ -2711,7 +2711,7 @@
27122712 'page' => $newid,
27132713 'comment' => $comment,
27142714 'text' => $redirectText ) );
2715 - $redirectRevision->insertOn( $dbw, true );
 2715+ $redirectRevision->insertOn( $dbw );
27162716 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
27172717
27182718 # Record the just-created redirect's linking to the page
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -285,6 +285,7 @@
286286 # Auto-reviewing
287287 $wgHooks['ArticleSaveComplete'][] = 'FlaggedRevs::autoMarkPatrolled';
288288 $wgHooks['RevisionInsertComplete'][] = 'FlaggedRevs::maybeMakeEditReviewed';
 289+ $wgHooks['ArticleRollbackComplete'][] = 'FlaggedRevs::maybeMakeRollbackReviewed';
289290 # Disallow moves of stable pages
290291 $wgHooks['userCan'][] = 'FlaggedRevs::userCanMove';
291292 $wgHooks['userCan'][] = 'FlaggedRevs::userCanView';
@@ -1933,10 +1934,40 @@
19341935 }
19351936
19361937 /**
 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+ /**
19371968 * When an edit is made by a reviewer, if the current revision is the stable
19381969 * version, try to automatically review it.
19391970 */
1940 - public static function maybeMakeEditReviewed( $rev, $edit, $baseRevID ) {
 1971+ public static function maybeMakeEditReviewed( $rev ) {
19411972 global $wgFlaggedRevsAutoReview, $wgFlaggedArticle, $wgRequest;
19421973 # Get the user
19431974 $user = User::newFromId( $rev->getUser() );
@@ -1950,13 +1981,13 @@
19511982 return true;
19521983 }
19531984 # For edits from normal form submits only!
1954 - if( !$edit ) {
 1985+ if( !self::revSubmitted( $title, $rev ) ) {
19551986 return true;
19561987 }
19571988 $frev = null;
19581989 $reviewableNewPage = false;
1959 - # Get the revision the incoming one was based off if
1960 - $baseRevID = $baseRevID ? $baseRevID : $wgRequest->getIntOrNull('baseRevId');
 1990+ # Get the revision the incoming one was based off
 1991+ $baseRevID = $wgRequest->getIntOrNull('baseRevId');
19611992 # If baseRevId not given, assume the previous
19621993 $baseRevID = $baseRevID ? $baseRevID : $title->getPreviousRevisionId( $rev->getId(), GAID_FOR_UPDATE );
19631994 if( $baseRevID ) {
@@ -1988,6 +2019,33 @@
19892020 }
19902021
19912022 /**
 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+ /**
19922050 * When an edit is made to a page that can't be reviewed, autopatrol if allowed.
19932051 * This is not loggged for perfomance reasons and no one cares if talk pages and such
19942052 * are autopatrolled.

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r34906Decrappify edit check for revision hookaaron03:17, 16 May 2008
r34907Actually check $edit ;)aaron03:21, 16 May 2008
r34928Improve efficiency of autoreviewing of edits rollbacks and merge into main fu...aaron18:22, 16 May 2008

Status & tagging log