r107636 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107635‎ | r107636 | r107637 >
Date:15:54, 30 December 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* Moved post-deletion code from WikiPage::doDeleteArticle() to WikiPage::doDeleteUpdates() so that it can be shared with page move
* Use WikiPage::doEditUpdates() and WikiPage::onArticleDelete() to do updates instead of reimplementing the whole thing in Title::moveTo(); avoids some bugs since the implementation differs from the one from WikiPage (notably the page and article count). This adds some more cache clearing, but they are needed depending on parameters (e.g. if the redirect is not created).
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -3488,15 +3488,14 @@
34893489 return $status->getErrorsArray();
34903490 }
34913491 }
 3492+ // Clear RepoGroup process cache
 3493+ RepoGroup::singleton()->clearCache( $this );
 3494+ RepoGroup::singleton()->clearCache( $nt ); # clear false negative cache
34923495 }
3493 - // Clear RepoGroup process cache
3494 - RepoGroup::singleton()->clearCache( $this );
3495 - RepoGroup::singleton()->clearCache( $nt ); # clear false negative cache
34963496
34973497 $dbw->begin(); # If $file was a LocalFile, its transaction would have closed our own.
34983498 $pageid = $this->getArticleID( self::GAID_FOR_UPDATE );
34993499 $protected = $this->isProtected();
3500 - $pageCountChange = ( $createRedirect ? 1 : 0 ) - ( $nt->exists() ? 1 : 0 );
35013500
35023501 // Do the actual move
35033502 $err = $this->moveToInternal( $nt, $reason, $createRedirect );
@@ -3506,8 +3505,6 @@
35073506 return $err;
35083507 }
35093508
3510 - $redirid = $this->getArticleID();
3511 -
35123509 // Refresh the sortkey for this row. Be careful to avoid resetting
35133510 // cl_timestamp, which may disturb time-based lists on some sites.
35143511 $prefixes = $dbw->select(
@@ -3531,6 +3528,8 @@
35323529 );
35333530 }
35343531
 3532+ $redirid = $this->getArticleID();
 3533+
35353534 if ( $protected ) {
35363535 # Protect the redirect title as the title used to be...
35373536 $dbw->insertSelect( 'page_restrictions', 'page_restrictions',
@@ -3566,50 +3565,8 @@
35673566 WatchedItem::duplicateEntries( $this, $nt );
35683567 }
35693568
3570 - # Update search engine
3571 - $u = new SearchUpdate( $pageid, $nt->getPrefixedDBkey() );
3572 - $u->doUpdate();
3573 - $u = new SearchUpdate( $redirid, $this->getPrefixedDBkey(), '' );
3574 - $u->doUpdate();
3575 -
35763569 $dbw->commit();
35773570
3578 - # Update site_stats
3579 - if ( $this->isContentPage() && !$nt->isContentPage() ) {
3580 - # No longer a content page
3581 - # Not viewed, edited, removing
3582 - $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange );
3583 - } elseif ( !$this->isContentPage() && $nt->isContentPage() ) {
3584 - # Now a content page
3585 - # Not viewed, edited, adding
3586 - $u = new SiteStatsUpdate( 0, 1, + 1, $pageCountChange );
3587 - } elseif ( $pageCountChange ) {
3588 - # Redirect added
3589 - $u = new SiteStatsUpdate( 0, 0, 0, 1 );
3590 - } else {
3591 - # Nothing special
3592 - $u = false;
3593 - }
3594 - if ( $u ) {
3595 - $u->doUpdate();
3596 - }
3597 -
3598 - # Update message cache for interface messages
3599 - if ( $this->getNamespace() == NS_MEDIAWIKI ) {
3600 - # @bug 17860: old article can be deleted, if this the case,
3601 - # delete it from message cache
3602 - if ( $this->getArticleID() === 0 ) {
3603 - MessageCache::singleton()->replace( $this->getDBkey(), false );
3604 - } else {
3605 - $rev = Revision::newFromTitle( $this );
3606 - MessageCache::singleton()->replace( $this->getDBkey(), $rev->getText() );
3607 - }
3608 - }
3609 - if ( $nt->getNamespace() == NS_MEDIAWIKI ) {
3610 - $rev = Revision::newFromTitle( $nt );
3611 - MessageCache::singleton()->replace( $nt->getDBkey(), $rev->getText() );
3612 - }
3613 -
36143571 wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
36153572 return true;
36163573 }
@@ -3659,36 +3616,18 @@
36603617
36613618 $dbw = wfGetDB( DB_MASTER );
36623619
3663 - if ( $moveOverRedirect ) {
3664 - $rcts = $dbw->timestamp( $nt->getEarliestRevTime() );
 3620+ $newpage = WikiPage::factory( $nt );
36653621
 3622+ if ( $moveOverRedirect ) {
36663623 $newid = $nt->getArticleID();
3667 - $newns = $nt->getNamespace();
3668 - $newdbk = $nt->getDBkey();
36693624
36703625 # Delete the old redirect. We don't save it to history since
36713626 # by definition if we've got here it's rather uninteresting.
36723627 # We have to remove it so that the next step doesn't trigger
36733628 # a conflict on the unique namespace+title index...
36743629 $dbw->delete( 'page', array( 'page_id' => $newid ), __METHOD__ );
3675 - if ( !$dbw->cascadingDeletes() ) {
3676 - $dbw->delete( 'revision', array( 'rev_page' => $newid ), __METHOD__ );
36773630
3678 - $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ );
3679 - $dbw->delete( 'imagelinks', array( 'il_from' => $newid ), __METHOD__ );
3680 - $dbw->delete( 'categorylinks', array( 'cl_from' => $newid ), __METHOD__ );
3681 - $dbw->delete( 'templatelinks', array( 'tl_from' => $newid ), __METHOD__ );
3682 - $dbw->delete( 'externallinks', array( 'el_from' => $newid ), __METHOD__ );
3683 - $dbw->delete( 'langlinks', array( 'll_from' => $newid ), __METHOD__ );
3684 - $dbw->delete( 'iwlinks', array( 'iwl_from' => $newid ), __METHOD__ );
3685 - $dbw->delete( 'redirect', array( 'rd_from' => $newid ), __METHOD__ );
3686 - $dbw->delete( 'page_props', array( 'pp_page' => $newid ), __METHOD__ );
3687 - }
3688 - // If the target page was recently created, it may have an entry in recentchanges still
3689 - $dbw->delete( 'recentchanges',
3690 - array( 'rc_timestamp' => $rcts, 'rc_namespace' => $newns, 'rc_title' => $newdbk, 'rc_new' => 1 ),
3691 - __METHOD__
3692 - );
 3631+ $newpage->doDeleteUpdates( $newid );
36933632 }
36943633
36953634 # Save a null revision in the page's history notifying of the move
@@ -3698,27 +3637,30 @@
36993638 }
37003639 $nullRevId = $nullRevision->insertOn( $dbw );
37013640
3702 - $now = wfTimestampNow();
37033641 # Change the name of the target page:
37043642 $dbw->update( 'page',
37053643 /* SET */ array(
3706 - 'page_touched' => $dbw->timestamp( $now ),
37073644 'page_namespace' => $nt->getNamespace(),
37083645 'page_title' => $nt->getDBkey(),
3709 - 'page_latest' => $nullRevId,
37103646 ),
37113647 /* WHERE */ array( 'page_id' => $oldid ),
37123648 __METHOD__
37133649 );
 3650+
 3651+ $this->resetArticleID( 0 );
37143652 $nt->resetArticleID( $oldid );
37153653
3716 - $article = WikiPage::factory( $nt );
 3654+ $newpage->updateRevisionOn( $dbw, $nullRevision );
 3655+
37173656 wfRunHooks( 'NewRevisionFromEditComplete',
3718 - array( $article, $nullRevision, $latest, $wgUser ) );
3719 - $article->setCachedLastEditTime( $now );
 3657+ array( $newpage, $nullRevision, $latest, $wgUser ) );
37203658
 3659+ $newpage->doEditUpdates( $nullRevision, $wgUser, array( 'changed' => false ) );
 3660+
37213661 # Recreate the redirect, this time in the other direction.
3722 - if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) {
 3662+ if ( $redirectSuppressed ) {
 3663+ WikiPage::onArticleDelete( $this );
 3664+ } else {
37233665 $mwRedir = MagicWord::get( 'redirect' );
37243666 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
37253667 $redirectArticle = WikiPage::factory( $this );
@@ -3734,33 +3676,13 @@
37353677 wfRunHooks( 'NewRevisionFromEditComplete',
37363678 array( $redirectArticle, $redirectRevision, false, $wgUser ) );
37373679
3738 - # Now, we record the link from the redirect to the new title.
3739 - # It should have no other outgoing links...
3740 - $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ );
3741 - $dbw->insert( 'pagelinks',
3742 - array(
3743 - 'pl_from' => $newid,
3744 - 'pl_namespace' => $nt->getNamespace(),
3745 - 'pl_title' => $nt->getDBkey() ),
3746 - __METHOD__ );
 3680+ $redirectArticle->doEditUpdates( $redirectRevision, $wgUser, array( 'created' => true ) );
37473681 }
3748 - } else {
3749 - $this->resetArticleID( 0 );
37503682 }
37513683
37523684 # Log the move
37533685 $logid = $logEntry->insert();
37543686 $logEntry->publish( $logid );
3755 -
3756 - # Purge caches for old and new titles
3757 - if ( $moveOverRedirect ) {
3758 - # A simple purge is enough when moving over a redirect
3759 - $nt->purgeSquid();
3760 - } else {
3761 - # Purge caches as per article creation, including any pages that link to this title
3762 - WikiPage::onArticleCreate( $nt );
3763 - }
3764 - $this->purgeSquid();
37653687 }
37663688
37673689 /**
Index: trunk/phase3/includes/WikiPage.php
@@ -1901,10 +1901,6 @@
19021902 return false;
19031903 }
19041904
1905 - DeferredUpdates::addUpdate(
1906 - new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 )
1907 - );
1908 -
19091905 // Bitfields to further suppress the content
19101906 if ( $suppress ) {
19111907 $bitfield = 0;
@@ -1952,9 +1948,6 @@
19531949 ), __METHOD__
19541950 );
19551951
1956 - # Delete restrictions for it
1957 - $dbw->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ );
1958 -
19591952 # Now that it's safely backed up, delete it
19601953 $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__ );
19611954 $ok = ( $dbw->affectedRows() > 0 ); // getArticleId() uses slave, could be laggy
@@ -1964,6 +1957,39 @@
19651958 return false;
19661959 }
19671960
 1961+ $this->doDeleteUpdates( $id );
 1962+
 1963+ # Log the deletion, if the page was suppressed, log it at Oversight instead
 1964+ $logtype = $suppress ? 'suppress' : 'delete';
 1965+
 1966+ $logEntry = new ManualLogEntry( $logtype, 'delete' );
 1967+ $logEntry->setPerformer( $user );
 1968+ $logEntry->setTarget( $this->mTitle );
 1969+ $logEntry->setComment( $reason );
 1970+ $logid = $logEntry->insert();
 1971+ $logEntry->publish( $logid );
 1972+
 1973+ if ( $commit ) {
 1974+ $dbw->commit();
 1975+ }
 1976+
 1977+ wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id ) );
 1978+ return true;
 1979+ }
 1980+
 1981+ /**
 1982+ * Do some database updates after deletion
 1983+ *
 1984+ * @param $id Int: page_id value of the page being deleted
 1985+ */
 1986+ public function doDeleteUpdates( $id ) {
 1987+ DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 ) );
 1988+
 1989+ $dbw = wfGetDB( DB_MASTER );
 1990+
 1991+ # Delete restrictions for it
 1992+ $dbw->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ );
 1993+
19681994 # Fix category table counts
19691995 $cats = array();
19701996 $res = $dbw->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__ );
@@ -2008,23 +2034,6 @@
20092035
20102036 # Clear the cached article id so the interface doesn't act like we exist
20112037 $this->mTitle->resetArticleID( 0 );
2012 -
2013 - # Log the deletion, if the page was suppressed, log it at Oversight instead
2014 - $logtype = $suppress ? 'suppress' : 'delete';
2015 -
2016 - $logEntry = new ManualLogEntry( $logtype, 'delete' );
2017 - $logEntry->setPerformer( $user );
2018 - $logEntry->setTarget( $this->mTitle );
2019 - $logEntry->setComment( $reason );
2020 - $logid = $logEntry->insert();
2021 - $logEntry->publish( $logid );
2022 -
2023 - if ( $commit ) {
2024 - $dbw->commit();
2025 - }
2026 -
2027 - wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id ) );
2028 - return true;
20292038 }
20302039
20312040 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r112951* (bug 34937) Fix for r107636: call WikiPage::onArticleCreate() when moving a...ialex16:36, 3 March 2012

Comments

#Comment by Bawolff (talk | contribs)   09:18, 3 January 2012

This fixes bug 32946

#Comment by P.Copp (talk | contribs)   16:10, 3 March 2012

Possibly caused bugzilla:34937

Status & tagging log