changed signature of ContentHandler::getDeletionUpdates() ro remove cross-dependency...
authordaniel <daniel.kinzler@wikimedia.de>
Wed, 6 Jun 2012 14:43:12 +0000 (16:43 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Wed, 6 Jun 2012 14:43:12 +0000 (16:43 +0200)
includes/ContentHandler.php
includes/LinksUpdate.php
includes/WikiPage.php

index eea2570..2d81881 100644 (file)
@@ -758,15 +758,21 @@ abstract class ContentHandler {
        }
 
        /**
+        * Returns a lost of updates to perform when the given content is deleted.
+        * The necessary updates may be taken from the Content object, or depend on the current state of the database.
+        *
         * @since WD.1
         *
-        * @param $page WikiPage the page that was deleted (note: $page->getId() must still return the old page ID!)
+        * @param \Content           $content the Content object for deletion
+        * @param \Title             $title   the title of the deleted page
+        * @param null|\ParserOutput $parserOutput optional parser output object for efficient access to meta-information
+        *                           about the content object. Provide if you have one handy.
         *
         * @return array a list of DataUpdate instances that will clean up the database ofter deletion.
         */
-       public function getDeletionUpdates( WikiPage $page ) {
+       public function getDeletionUpdates( Content $content, Title $title, ParserOutput $parserOutput = null ) {
                return array(
-                       new LinksDeletionUpdate( $page ),
+                       new LinksDeletionUpdate( $title ),
                );
        }
 }
index 4b484a7..39f82d8 100644 (file)
@@ -813,7 +813,7 @@ class LinksUpdate extends SqlDataUpdate {
  **/
 class LinksDeletionUpdate extends SqlDataUpdate {
 
-       protected $mPage;     //!< WikiPage the wikipage that was deleted
+       protected $mTitle;     //!< Title the title of page that was deleted
 
        /**
         * Constructor
@@ -822,18 +822,18 @@ class LinksDeletionUpdate extends SqlDataUpdate {
         * @param $parserOutput ParserOutput: output from a full parse of this page
         * @param $recursive Boolean: queue jobs for recursive updates?
         */
-       function __construct( WikiPage $page ) {
+       function __construct( Title $title ) {
                parent::__construct( );
 
-               $this->mPage = $page;
+               $this->mTitle = $title;
        }
 
        /**
         * Do some database updates after deletion
         */
        public function doUpdate() {
-               $title = $this->mPage->getTitle();
-               $id = $this->mPage->getId();
+               $title = $this->mTitle;
+               $id = $title->getArticleID();
 
                # Delete restrictions for it
                $this->mDb->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ );
@@ -846,7 +846,7 @@ class LinksDeletionUpdate extends SqlDataUpdate {
                        $cats [] = $row->cl_to;
                }
 
-               $this->mPage->updateCategoryCounts( array(), $cats );
+               $this->updateCategoryCounts( array(), $cats );
 
                # If using cascading deletes, we can skip some explicit deletes
                if ( !$this->mDb->cascadingDeletes() ) {
@@ -877,4 +877,16 @@ class LinksDeletionUpdate extends SqlDataUpdate {
                                __METHOD__ );
                }
        }
+
+       /**
+        * Update all the appropriate counts in the category table.
+        * @param $added array associative array of category name => sort key
+        * @param $deleted array associative array of category name => sort key
+        */
+       function updateCategoryCounts( $added, $deleted ) {
+               $a = WikiPage::factory( $this->mTitle );
+               $a->updateCategoryCounts(
+                       array_keys( $added ), array_keys( $deleted )
+               );
+       }
 }
index afd6880..6d24d9b 100644 (file)
@@ -1987,7 +1987,7 @@ class WikiPage extends Page {
                }
 
                # Update the links tables and other secondary data
-               $updates = $editInfo->output->getSecondaryDataUpdates( $this->getTitle() );
+               $updates = $editInfo->output->getSecondaryDataUpdates( $this->getTitle() ); #FIXME: call ContentHandler::getSecondaryLinkUpdates. Don't parse iuf not needed! But don't parse too early either, only after saving, so we have an article ID!
                DataUpdate::runUpdates( $updates );
 
                wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
@@ -2431,6 +2431,9 @@ class WikiPage extends Page {
                        $bitfield = 'rev_deleted';
                }
 
+               // we need to remember the old content so we can use it to generate all deletion updates.
+               $content = $this->getContent( Revision::RAW );
+
                $dbw = wfGetDB( DB_MASTER );
                $dbw->begin( __METHOD__ );
                // For now, shunt the revision data into the archive table.
@@ -2485,7 +2488,7 @@ class WikiPage extends Page {
                        return WikiPage::DELETE_NO_REVISIONS;
                }
 
-               $this->doDeleteUpdates( $id );
+               $this->doDeleteUpdates( $id, $content );
 
                # Log the deletion, if the page was suppressed, log it at Oversight instead
                $logtype = $suppress ? 'suppress' : 'delete';
@@ -2509,13 +2512,15 @@ class WikiPage extends Page {
         * Do some database updates after deletion
         *
         * @param $id Int: page_id value of the page being deleted (B/C, currently unused)
+        * @param $content Content: optional page content to be used when determining the required updates.
+        *        This may be needed because $this->getContent() may already return null when the page proper was deleted.
         */
-       public function doDeleteUpdates( $id ) {
+       public function doDeleteUpdates( $id, Content $content = null ) {
                # update site status
                DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 ) );
 
                # remove secondary indexes, etc
-               $updates = $this->getDeletionUpdates( );
+               $updates = $this->getDeletionUpdates( $content );
                DataUpdate::runUpdates( $updates );
 
                # Clear caches
@@ -2534,7 +2539,7 @@ class WikiPage extends Page {
         * roll back to, e.g. user is the sole contributor. This function
         * performs permissions checks on $user, then calls commitRollback()
         * to do the dirty work
-        * 
+        *
         * @todo: seperate the business/permission stuff out from backend code
         *
         * @param $fromP String: Name of the user whose edits to rollback.
@@ -3113,8 +3118,21 @@ class WikiPage extends Page {
                return $this->isParserCacheUsed( ParserOptions::newFromUser( $wgUser ), $oldid );
        }
 
-       public function getDeletionUpdates() {
-               $updates = $this->getContentHandler()->getDeletionUpdates( $this );
+       /**
+        * Returns a list of updates to be performed when this page is deleted. The updates should remove any infomration
+        * about this page from secondary data stores such as links tables.
+        *
+        * @param Content|null $content optional Content object for determining the necessary updates
+        * @return Array an array of DataUpdates objects
+        */
+       public function getDeletionUpdates( Content $content = null ) {
+               if ( !$content ) {
+                       // load content object, which may be used to determine the necessary updates
+                       // XXX: the content may not be needed to determine the updates, then this would be overhead.
+                       $content = $this->getContent( Revision::RAW );
+               }
+
+               $updates = $this->getContentHandler()->getDeletionUpdates( $content, $this->mTitle );
 
                wfRunHooks( 'WikiPageDeletionUpdates', array( $this, &$updates ) );
                return $updates;