Provide CategoryAfterPageRemoved hook handlers with deleted page IDs
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 17 Jun 2016 02:56:42 +0000 (19:56 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 20 Jun 2016 19:40:03 +0000 (12:40 -0700)
Since this updates happens post-send or via the job queue, the
page object will be for a non-existing or newer page/redirect.

Change-Id: I20b583948157dccceca6eb1fbd25121822bf1b2f

docs/hooks.txt
includes/Title.php
includes/deferred/LinksDeletionUpdate.php
includes/page/Article.php
includes/page/WikiPage.php

index 44f2551..f20c5b8 100644 (file)
@@ -919,6 +919,7 @@ $wikiPage: WikiPage that was added
 'CategoryAfterPageRemoved': After a page is removed from a category.
 $category: Category that page was removed from
 $wikiPage: WikiPage that was removed
+$id: the page ID (original ID in case of page deletions)
 
 'CategoryPageView': Before viewing a categorypage in CategoryPage::view.
 &$catpage: CategoryPage instance
index 4555f16..f291a69 100644 (file)
@@ -4371,7 +4371,6 @@ class Title implements LinkTarget {
                $conds = $this->pageCond();
                $dbw->onTransactionIdle( function () use ( $dbw, $conds, $method, $purgeTime ) {
                        $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
-
                        $dbw->update(
                                'page',
                                [ 'page_touched' => $dbTimestamp ],
index 2f17729..a7c39ca 100644 (file)
@@ -73,7 +73,7 @@ class LinksDeletionUpdate extends SqlDataUpdate implements EnqueueableDataUpdate
                );
                $catBatches = array_chunk( $cats, $batchSize );
                foreach ( $catBatches as $catBatch ) {
-                       $this->page->updateCategoryCounts( [], $catBatch );
+                       $this->page->updateCategoryCounts( [], $catBatch, $id );
                        if ( count( $catBatches ) > 1 ) {
                                $this->mDb->commit( __METHOD__, 'flush' );
                                wfGetLBFactory()->waitForReplication( [ 'wiki' => $this->mDb->getWikiID() ] );
index eccf36f..1f1e8d6 100644 (file)
@@ -2601,8 +2601,8 @@ class Article implements Page {
         * Call to WikiPage function for backwards compatibility.
         * @see WikiPage::updateCategoryCounts
         */
-       public function updateCategoryCounts( array $added, array $deleted ) {
-               return $this->mPage->updateCategoryCounts( $added, $deleted );
+       public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) {
+               return $this->mPage->updateCategoryCounts( $added, $deleted, $id );
        }
 
        /**
index 8d9d5a8..a416d56 100644 (file)
@@ -3427,16 +3427,16 @@ class WikiPage implements Page, IDBAccessObject {
         *
         * @param array $added The names of categories that were added
         * @param array $deleted The names of categories that were deleted
+        * @param integer $id Page ID (this should be the original deleted page ID)
         */
-       public function updateCategoryCounts( array $added, array $deleted ) {
-               $that = $this;
-               $method = __METHOD__;
+       public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) {
+               $id = $id ?: $this->getId();
                $dbw = wfGetDB( DB_MASTER );
-
+               $method = __METHOD__;
                // Do this at the end of the commit to reduce lock wait timeouts
                $dbw->onTransactionPreCommitOrIdle(
-                       function () use ( $dbw, $that, $method, $added, $deleted ) {
-                               $ns = $that->getTitle()->getNamespace();
+                       function () use ( $dbw, $added, $deleted, $id, $method ) {
+                               $ns = $this->getTitle()->getNamespace();
 
                                $addFields = [ 'cat_pages = cat_pages + 1' ];
                                $removeFields = [ 'cat_pages = cat_pages - 1' ];
@@ -3453,7 +3453,7 @@ class WikiPage implements Page, IDBAccessObject {
                                                'category',
                                                'cat_title',
                                                [ 'cat_title' => $added ],
-                                               __METHOD__
+                                               $method
                                        );
 
                                        // For category rows that already exist, do a plain
@@ -3464,7 +3464,7 @@ class WikiPage implements Page, IDBAccessObject {
                                                        'category',
                                                        $addFields,
                                                        [ 'cat_title' => $existingAdded ],
-                                                       __METHOD__
+                                                       $method
                                                );
                                        }
 
@@ -3500,12 +3500,12 @@ class WikiPage implements Page, IDBAccessObject {
 
                                foreach ( $added as $catName ) {
                                        $cat = Category::newFromName( $catName );
-                                       Hooks::run( 'CategoryAfterPageAdded', [ $cat, $that ] );
+                                       Hooks::run( 'CategoryAfterPageAdded', [ $cat, $this ] );
                                }
 
                                foreach ( $deleted as $catName ) {
                                        $cat = Category::newFromName( $catName );
-                                       Hooks::run( 'CategoryAfterPageRemoved', [ $cat, $that ] );
+                                       Hooks::run( 'CategoryAfterPageRemoved', [ $cat, $this, $id ] );
                                }
                        }
                );