MediaWiki REL1_39
LinksDeletionUpdate.php
Go to the documentation of this file.
1<?php
24
25use Category;
28use InvalidArgumentException;
32use MWException;
33use ParserOutput;
34use WikiPage;
35
41 protected $page;
43 protected $timestamp;
44
51 public function __construct( WikiPage $page, $pageId = null, $timestamp = null ) {
52 $this->page = $page;
53 if ( $pageId ) {
54 $this->mId = $pageId; // page ID at time of deletion
55 } elseif ( $page->exists() ) {
56 $this->mId = $page->getId();
57 } else {
58 throw new InvalidArgumentException( "Page ID not known. Page doesn't exist?" );
59 }
60
61 $this->timestamp = $timestamp ?: wfTimestampNow();
62
63 $fakePO = new ParserOutput();
64 $fakePO->setCacheTime( $timestamp );
65 // Use immutable page identity to keep reference to the page id at time of deletion - T299244
66 $immutablePageIdentity = $page->getTitle()->toPageIdentity();
67 parent::__construct( $immutablePageIdentity, $fakePO, false );
68 }
69
70 protected function doIncrementalUpdate() {
72 $config = $services->getMainConfig();
73 $lbFactory = $services->getDBLoadBalancerFactory();
74 $batchSize = $config->get( MainConfigNames::UpdateRowsPerQuery );
75
76 $id = $this->mId;
78
79 $dbw = $this->getDB(); // convenience
80
81 parent::doIncrementalUpdate();
82
83 // Typically, a category is empty when deleted, so check that we don't leave
84 // spurious row in the category table.
85 if ( $title->getNamespace() === NS_CATEGORY ) {
86 // T166757: do the update after the main job DB commit
87 DeferredUpdates::addCallableUpdate( static function () use ( $title ) {
88 $cat = Category::newFromName( $title->getDBkey() );
89 $cat->refreshCountsIfSmall();
90 } );
91 }
92
93 // Delete restrictions for the deleted page
94 $dbw->delete( 'page_restrictions', [ 'pr_page' => $id ], __METHOD__ );
95
96 // Delete any redirect entry
97 $dbw->delete( 'redirect', [ 'rd_from' => $id ], __METHOD__ );
98
99 // Find recentchanges entries to clean up...
100 $rcIdsForTitle = $dbw->selectFieldValues(
101 'recentchanges',
102 'rc_id',
103 [
104 'rc_type != ' . RC_LOG,
105 'rc_namespace' => $title->getNamespace(),
106 'rc_title' => $title->getDBkey(),
107 'rc_timestamp < ' .
108 $dbw->addQuotes( $dbw->timestamp( $this->timestamp ) )
109 ],
110 __METHOD__
111 );
112 $rcIdsForPage = $dbw->selectFieldValues(
113 'recentchanges',
114 'rc_id',
115 [ 'rc_type != ' . RC_LOG, 'rc_cur_id' => $id ],
116 __METHOD__
117 );
118
119 // T98706: delete by PK to avoid lock contention with RC delete log insertions
120 $rcIdBatches = array_chunk( array_merge( $rcIdsForTitle, $rcIdsForPage ), $batchSize );
121 foreach ( $rcIdBatches as $rcIdBatch ) {
122 $dbw->delete( 'recentchanges', [ 'rc_id' => $rcIdBatch ], __METHOD__ );
123 if ( count( $rcIdBatches ) > 1 ) {
124 $lbFactory->commitAndWaitForReplication(
125 __METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
126 );
127 }
128 }
129 }
130
131 public function getAsJobSpecification() {
132 return [
133 'domain' => $this->getDB()->getDomainID(),
134 'job' => new JobSpecification(
135 'deleteLinks',
136 [ 'pageId' => $this->mId, 'timestamp' => $this->timestamp ],
137 [ 'removeDuplicates' => true ],
138 $this->mTitle
139 )
140 ];
141 }
142}
143
145class_alias( LinksDeletionUpdate::class, 'LinksDeletionUpdate' );
const RC_LOG
Definition Defines.php:118
const NS_CATEGORY
Definition Defines.php:78
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Category objects are immutable, strictly speaking.
Definition Category.php:33
static newFromName( $name)
Factory function.
Definition Category.php:150
Class for managing the deferral of updates within the scope of a PHP script invocation.
Job queue task description base code.
MediaWiki exception.
Update object handling the cleanup of links tables after a page was deleted.
__construct(WikiPage $page, $pageId=null, $timestamp=null)
Class the manages updates of *_link tables as well as similar extension-managed tables.
Title $mTitle
Title object of the article linked from.
int $mId
Page ID of the article linked from.
A class containing constants representing the names of configuration variables.
const UpdateRowsPerQuery
Name constant for the UpdateRowsPerQuery setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Base representation for an editable wiki page.
Definition WikiPage.php:62
getId( $wikiId=self::LOCAL)
Definition WikiPage.php:573
getTitle()
Get the title object of the article.
Definition WikiPage.php:303
Interface that marks a DataUpdate as enqueuable via the JobQueue.