[bug 37746] string ids for content model and format.
[lhc/web/wiklou.git] / includes / LinksUpdate.php
index 8b403fc..3e8e362 100644 (file)
@@ -39,8 +39,6 @@ class LinksUpdate extends SqlDataUpdate {
                $mCategories,    //!< Map of category names to sort keys
                $mInterlangs,    //!< Map of language codes to titles
                $mProperties,    //!< Map of arbitrary name to value
-               $mDb,            //!< Database connection reference
-               $mOptions,       //!< SELECT options to be used (array)
                $mRecursive;     //!< Whether to queue jobs for recursive updates
 
        /**
@@ -66,7 +64,12 @@ class LinksUpdate extends SqlDataUpdate {
                $this->mTitle = $title;
                $this->mId = $title->getArticleID();
 
+               if ( !$this->mId ) {
+                       throw new MWException( "The Title object did not provide an article ID. Perhaps the page doesn't exist?" );
+               }
+
                $this->mParserOutput = $parserOutput;
+
                $this->mLinks = $parserOutput->getLinks();
                $this->mImages = $parserOutput->getImages();
                $this->mTemplates = $parserOutput->getTemplates();
@@ -813,7 +816,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 +825,22 @@ 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;
+
+               if ( !$title->getArticleID() ) {
+                       throw new MWException( "The Title object did not provide an article ID. Perhaps the page doesn't exist?" );
+               }
        }
 
        /**
         * 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 +853,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 +884,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 )
+               );
+       }
 }