MediaWiki master
LinksDeletionUpdate.php
Go to the documentation of this file.
1<?php
24
25use InvalidArgumentException;
35
41 protected $timestamp;
42
48 public function __construct( PageIdentity $page, $pageId = null, $timestamp = null ) {
49 if ( $pageId ) {
50 $this->mId = $pageId; // page ID at time of deletion
51 } elseif ( $page->exists() ) {
52 $this->mId = $page->getId();
53 } else {
54 throw new InvalidArgumentException( "Page ID not known. Page doesn't exist?" );
55 }
56
57 $this->timestamp = $timestamp ?: wfTimestampNow();
58
59 $fakePO = new ParserOutput();
60 $fakePO->setCacheTime( $timestamp );
61 // Use an immutable page identity to keep reference to the page id at time of deletion - T299244
62 $immutablePageIdentity = new PageIdentityValue(
63 $page->getId(),
64 $page->getNamespace(),
65 $page->getDBkey(),
66 $page->getWikiId()
67 );
68 parent::__construct( $immutablePageIdentity, $fakePO, false );
69 }
70
71 protected function doIncrementalUpdate() {
73 $config = $services->getMainConfig();
74 $dbProvider = $services->getConnectionProvider();
75 $batchSize = $config->get( MainConfigNames::UpdateRowsPerQuery );
76
77 $id = $this->mId;
78 $title = $this->mTitle;
79
80 $dbw = $this->getDB(); // convenience
81
82 parent::doIncrementalUpdate();
83
84 // Typically, a category is empty when deleted, so check that we don't leave
85 // spurious row in the category table.
86 if ( $title->getNamespace() === NS_CATEGORY ) {
87 // T166757: do the update after the main job DB commit
88 DeferredUpdates::addCallableUpdate( static function () use ( $title ) {
89 $cat = Category::newFromName( $title->getDBkey() );
90 $cat->refreshCountsIfSmall();
91 } );
92 }
93
94 // Delete restrictions for the deleted page
95 $dbw->newDeleteQueryBuilder()
96 ->deleteFrom( 'page_restrictions' )
97 ->where( [ 'pr_page' => $id ] )
98 ->caller( __METHOD__ )->execute();
99
100 // Delete any redirect entry
101 $dbw->newDeleteQueryBuilder()
102 ->deleteFrom( 'redirect' )
103 ->where( [ 'rd_from' => $id ] )
104 ->caller( __METHOD__ )->execute();
105
106 // Find recentchanges entries to clean up...
107 // Select RC IDs just by curid, and not by title (see T307865 and T140960)
108 $rcIdsForPage = $dbw->newSelectQueryBuilder()
109 ->select( 'rc_id' )
110 ->from( 'recentchanges' )
111 ->where( [ $dbw->expr( 'rc_type', '!=', RC_LOG ), 'rc_cur_id' => $id ] )
112 ->caller( __METHOD__ )->fetchFieldValues();
113
114 // T98706: delete by PK to avoid lock contention with RC delete log insertions
115 $rcIdBatches = array_chunk( $rcIdsForPage, $batchSize );
116 foreach ( $rcIdBatches as $rcIdBatch ) {
117 $dbw->newDeleteQueryBuilder()
118 ->deleteFrom( 'recentchanges' )
119 ->where( [ 'rc_id' => $rcIdBatch ] )
120 ->caller( __METHOD__ )->execute();
121 if ( count( $rcIdBatches ) > 1 ) {
122 $dbProvider->commitAndWaitForReplication(
123 __METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
124 );
125 }
126 }
127 }
128
129 public function getAsJobSpecification() {
130 return [
131 'domain' => $this->getDB()->getDomainID(),
132 'job' => new JobSpecification(
133 'deleteLinks',
134 [ 'pageId' => $this->mId, 'timestamp' => $this->timestamp ],
135 [ 'removeDuplicates' => true ],
136 $this->mTitle
137 )
138 ];
139 }
140}
const RC_LOG
Definition Defines.php:119
const NS_CATEGORY
Definition Defines.php:79
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Job queue task description base code.
Category objects are immutable, strictly speaking.
Definition Category.php:42
Defer callable updates to run later in the PHP process.
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
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.
__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.
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.
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.