MediaWiki  master
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 }
ParserOutput
Definition: ParserOutput.php:32
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:195
LinksUpdate\$mId
int $mId
Page ID of the article linked from.
Definition: LinksUpdate.php:45
LinksDeletionUpdate\$timestamp
string $timestamp
Definition: LinksDeletionUpdate.php:31
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:60
LinksUpdate
Class the manages updates of *_link tables as well as similar extension-managed tables.
Definition: LinksUpdate.php:39
LinksDeletionUpdate\$page
WikiPage $page
Definition: LinksDeletionUpdate.php:29
EnqueueableDataUpdate
Interface that marks a DataUpdate as enqueuable via the JobQueue.
Definition: EnqueueableDataUpdate.php:12
RC_LOG
const RC_LOG
Definition: Defines.php:117
LinksDeletionUpdate\doIncrementalUpdate
doIncrementalUpdate()
Definition: LinksDeletionUpdate.php:56
LinksDeletionUpdate\getAsJobSpecification
getAsJobSpecification()
Definition: LinksDeletionUpdate.php:117
WikiPage\getTitle
getTitle()
Get the title object of the article.
Definition: WikiPage.php:311
WikiPage\exists
exists()
Definition: WikiPage.php:596
LinksDeletionUpdate\__construct
__construct(WikiPage $page, $pageId=null, $timestamp=null)
Definition: LinksDeletionUpdate.php:39
$title
$title
Definition: testCompression.php:38
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1697
LinksUpdate\$mTitle
Title $mTitle
Title object of the article linked from.
Definition: LinksUpdate.php:48
WikiPage\getId
getId( $wikiId=self::LOCAL)
Definition: WikiPage.php:584
LinksDeletionUpdate
Update object handling the cleanup of links tables after a page was deleted.
Definition: LinksDeletionUpdate.php:27
JobSpecification
Job queue task description base code.
Definition: JobSpecification.php:42
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
Category\newFromName
static newFromName( $name)
Factory function.
Definition: Category.php:139
LinksUpdate\getDB
getDB()
Definition: LinksUpdate.php:1243
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add an update to the pending update queue that invokes the specified callback when run.
Definition: DeferredUpdates.php:145