jenkins-bot has submitted this change and it was merged.

Change subject: Provide CategoryAfterPageRemoved hook handlers with deleted 
page IDs
......................................................................


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
---
M docs/hooks.txt
M includes/Title.php
M includes/deferred/LinksDeletionUpdate.php
M includes/page/Article.php
M includes/page/WikiPage.php
5 files changed, 14 insertions(+), 14 deletions(-)

Approvals:
  Anomie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/docs/hooks.txt b/docs/hooks.txt
index 44f2551..f20c5b8 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -919,6 +919,7 @@
 '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 4555f16..f291a69 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -4371,7 +4371,6 @@
                $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 2f17729..a7c39ca 100644
--- a/includes/deferred/LinksDeletionUpdate.php
+++ b/includes/deferred/LinksDeletionUpdate.php
@@ -73,7 +73,7 @@
                );
                $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 eccf36f..1f1e8d6 100644
--- a/includes/page/Article.php
+++ b/includes/page/Article.php
@@ -2601,8 +2601,8 @@
         * 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 8d9d5a8..a416d56 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -3427,16 +3427,16 @@
         *
         * @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 @@
                                                'category',
                                                'cat_title',
                                                [ 'cat_title' => $added ],
-                                               __METHOD__
+                                               $method
                                        );
 
                                        // For category rows that already 
exist, do a plain
@@ -3464,7 +3464,7 @@
                                                        'category',
                                                        $addFields,
                                                        [ 'cat_title' => 
$existingAdded ],
-                                                       __METHOD__
+                                                       $method
                                                );
                                        }
 
@@ -3500,12 +3500,12 @@
 
                                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 ] );
                                }
                        }
                );

-- 
To view, visit https://gerrit.wikimedia.org/r/294873
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I20b583948157dccceca6eb1fbd25121822bf1b2f
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to