MediaWiki REL1_37
LinksDeletionUpdate.php
Go to the documentation of this file.
1<?php
23
29 protected $page;
31 protected $timestamp;
32
39 public function __construct( WikiPage $page, $pageId = null, $timestamp = null ) {
40 $this->page = $page;
41 if ( $pageId ) {
42 $this->mId = $pageId; // page ID at time of deletion
43 } elseif ( $page->exists() ) {
44 $this->mId = $page->getId();
45 } else {
46 throw new InvalidArgumentException( "Page ID not known. Page doesn't exist?" );
47 }
48
49 $this->timestamp = $timestamp ?: wfTimestampNow();
50
51 $fakePO = new ParserOutput();
52 $fakePO->setCacheTime( $timestamp );
53 parent::__construct( $page->getTitle(), $fakePO, false );
54 }
55
56 protected function doIncrementalUpdate() {
57 $services = MediaWikiServices::getInstance();
58 $config = $services->getMainConfig();
59 $lbFactory = $services->getDBLoadBalancerFactory();
60 $batchSize = $config->get( 'UpdateRowsPerQuery' );
61
62 $id = $this->mId;
64
65 $dbw = $this->getDB(); // convenience
66
67 parent::doIncrementalUpdate();
68
69 // Typically, a category is empty when deleted, so check that we don't leave
70 // spurious row in the category table.
71 if ( $title->getNamespace() === NS_CATEGORY ) {
72 // T166757: do the update after the main job DB commit
73 DeferredUpdates::addCallableUpdate( static function () use ( $title ) {
74 $cat = Category::newFromName( $title->getDBkey() );
75 $cat->refreshCountsIfSmall();
76 } );
77 }
78
79 // Delete restrictions for the deleted page
80 $dbw->delete( 'page_restrictions', [ 'pr_page' => $id ], __METHOD__ );
81
82 // Delete any redirect entry
83 $dbw->delete( 'redirect', [ 'rd_from' => $id ], __METHOD__ );
84
85 // Find recentchanges entries to clean up...
86 $rcIdsForTitle = $dbw->selectFieldValues(
87 'recentchanges',
88 'rc_id',
89 [
90 'rc_type != ' . RC_LOG,
91 'rc_namespace' => $title->getNamespace(),
92 'rc_title' => $title->getDBkey(),
93 'rc_timestamp < ' .
94 $dbw->addQuotes( $dbw->timestamp( $this->timestamp ) )
95 ],
96 __METHOD__
97 );
98 $rcIdsForPage = $dbw->selectFieldValues(
99 'recentchanges',
100 'rc_id',
101 [ 'rc_type != ' . RC_LOG, 'rc_cur_id' => $id ],
102 __METHOD__
103 );
104
105 // T98706: delete by PK to avoid lock contention with RC delete log insertions
106 $rcIdBatches = array_chunk( array_merge( $rcIdsForTitle, $rcIdsForPage ), $batchSize );
107 foreach ( $rcIdBatches as $rcIdBatch ) {
108 $dbw->delete( 'recentchanges', [ 'rc_id' => $rcIdBatch ], __METHOD__ );
109 if ( count( $rcIdBatches ) > 1 ) {
110 $lbFactory->commitAndWaitForReplication(
111 __METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
112 );
113 }
114 }
115 }
116
117 public function getAsJobSpecification() {
118 return [
119 'domain' => $this->getDB()->getDomainID(),
120 'job' => new JobSpecification(
121 'deleteLinks',
122 [ 'pageId' => $this->mId, 'timestamp' => $this->timestamp ],
123 [ 'removeDuplicates' => true ],
124 $this->mTitle
125 )
126 ];
127 }
128}
getDB()
const RC_LOG
Definition Defines.php:117
const NS_CATEGORY
Definition Defines.php:78
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Title null $mTitle
Job queue task description base code.
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.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Class representing a MediaWiki article and history.
Definition WikiPage.php:60
getId( $wikiId=self::LOCAL)
Definition WikiPage.php:584
getTitle()
Get the title object of the article.
Definition WikiPage.php:311
Interface that marks a DataUpdate as enqueuable via the JobQueue.