MediaWiki master
LinksDeletionUpdate.php
Go to the documentation of this file.
1<?php
10
11use InvalidArgumentException;
22
28 protected $timestamp;
29
35 public function __construct( PageIdentity $page, $pageId = null, $timestamp = null ) {
36 if ( $pageId ) {
37 $this->mId = $pageId; // page ID at time of deletion
38 } elseif ( $page->exists() ) {
39 $this->mId = $page->getId();
40 } else {
41 throw new InvalidArgumentException( "Page ID not known. Page doesn't exist?" );
42 }
43
44 $this->timestamp = $timestamp ?: wfTimestampNow();
45
46 $fakePO = new ParserOutput();
47 $fakePO->setCacheTime( $timestamp );
48 // Use an immutable page identity to keep reference to the page id at time of deletion - T299244
49 $immutablePageIdentity = new PageIdentityValue(
50 $page->getId(),
51 $page->getNamespace(),
52 $page->getDBkey(),
53 $page->getWikiId()
54 );
55 parent::__construct( $immutablePageIdentity, $fakePO, false );
56 }
57
58 protected function doIncrementalUpdate() {
60 $config = $services->getMainConfig();
61 $dbProvider = $services->getConnectionProvider();
62 $batchSize = $config->get( MainConfigNames::UpdateRowsPerQuery );
63
64 $id = $this->mId;
65 $title = $this->mTitle;
66
67 $dbw = $this->getDB(); // convenience
68
69 parent::doIncrementalUpdate();
70
71 // Typically, a category is empty when deleted, so check that we don't leave
72 // spurious row in the category table.
73 if ( $title->getNamespace() === NS_CATEGORY ) {
74 // T166757: do the update after the main job DB commit
75 DeferredUpdates::addCallableUpdate( static function () use ( $title ) {
76 $cat = Category::newFromName( $title->getDBkey() );
77 $cat->refreshCountsIfSmall();
78 } );
79 }
80
81 // Delete restrictions for the deleted page
82 $dbw->newDeleteQueryBuilder()
83 ->deleteFrom( 'page_restrictions' )
84 ->where( [ 'pr_page' => $id ] )
85 ->caller( __METHOD__ )->execute();
86
87 // Delete any redirect entry
88 $dbw->newDeleteQueryBuilder()
89 ->deleteFrom( 'redirect' )
90 ->where( [ 'rd_from' => $id ] )
91 ->caller( __METHOD__ )->execute();
92
93 // Find recentchanges entries to clean up...
94 // Select RC IDs just by curid, and not by title (see T307865 and T140960)
95 $rcIdsForPage = $dbw->newSelectQueryBuilder()
96 ->select( 'rc_id' )
97 ->from( 'recentchanges' )
98 ->where( [
99 $dbw->expr( 'rc_source', '!=', RecentChange::SRC_LOG ),
100 'rc_cur_id' => $id
101 ] )
102 ->caller( __METHOD__ )->fetchFieldValues();
103
104 // T98706: delete by PK to avoid lock contention with RC delete log insertions
105 $rcIdBatches = array_chunk( $rcIdsForPage, $batchSize );
106 foreach ( $rcIdBatches as $rcIdBatch ) {
107 $dbw->newDeleteQueryBuilder()
108 ->deleteFrom( 'recentchanges' )
109 ->where( [ 'rc_id' => $rcIdBatch ] )
110 ->caller( __METHOD__ )->execute();
111 if ( count( $rcIdBatches ) > 1 ) {
112 $dbProvider->commitAndWaitForReplication(
113 __METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
114 );
115 }
116 }
117 }
118
120 public function getAsJobSpecification() {
121 return [
122 'domain' => $this->getDB()->getDomainID(),
123 'job' => new JobSpecification(
124 'deleteLinks',
125 [ 'pageId' => $this->mId, 'timestamp' => $this->timestamp ],
126 [ 'removeDuplicates' => true ],
127 $this->mTitle
128 )
129 ];
130 }
131}
const NS_CATEGORY
Definition Defines.php:65
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Category objects are immutable, strictly speaking.
Definition Category.php:28
Defer callable updates to run later in the PHP process.
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dependeeDbws=[])
Add an update to the pending update queue that invokes the specified callback when run.
Update object handling the cleanup of links tables after a page was deleted.
getAsJobSpecification()
array (domain => DB domain ID, job => IJobSpecification)
__construct(PageIdentity $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.
Job queue task description base code.
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.
Immutable value object representing a page identity.
ParserOutput is a rendering of a Content object or a message.
Utility class for creating and reading rows in the recentchanges table.
Interface that marks a DataUpdate as enqueuable via the JobQueue.
Interface for objects (potentially) representing an editable wiki page.
getId( $wikiId=self::LOCAL)
Returns the page ID.
exists()
Checks if the page currently exists.
getNamespace()
Returns the page's namespace number.
getDBkey()
Get the page title in DB key form.
getWikiId()
Get the ID of the wiki this page belongs to.