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