'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
);
$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() ] );
* 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 );
}
/**
*
* @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' ];
'category',
'cat_title',
[ 'cat_title' => $added ],
- __METHOD__
+ $method
);
// For category rows that already exist, do a plain
'category',
$addFields,
[ 'cat_title' => $existingAdded ],
- __METHOD__
+ $method
);
}
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 ] );
}
}
);