From: Aaron Schulz Date: Fri, 17 Jun 2016 02:56:42 +0000 (-0700) Subject: Provide CategoryAfterPageRemoved hook handlers with deleted page IDs X-Git-Tag: 1.31.0-rc.0~6569^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=a81d467f8caf5524731f35933adafa200d37c287;p=lhc%2Fweb%2Fwiklou.git Provide CategoryAfterPageRemoved hook handlers with deleted page IDs 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 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 44f2551985..f20c5b86b3 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/Title.php b/includes/Title.php index 4555f16d9b..f291a69b9e 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 ], diff --git a/includes/deferred/LinksDeletionUpdate.php b/includes/deferred/LinksDeletionUpdate.php index 2f17729e28..a7c39ca625 100644 --- a/includes/deferred/LinksDeletionUpdate.php +++ b/includes/deferred/LinksDeletionUpdate.php @@ -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() ] ); diff --git a/includes/page/Article.php b/includes/page/Article.php index eccf36fefb..1f1e8d6f55 100644 --- a/includes/page/Article.php +++ b/includes/page/Article.php @@ -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 ); } /** diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 8d9d5a8628..a416d5643d 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -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 ] ); } } );