MediaWiki REL1_33
LinksDeletionUpdate.php
Go to the documentation of this file.
1<?php
24
30 protected $page;
32 protected $timestamp;
33
40 function __construct( WikiPage $page, $pageId = null, $timestamp = null ) {
41 $this->page = $page;
42 if ( $pageId ) {
43 $this->mId = $pageId; // page ID at time of deletion
44 } elseif ( $page->exists() ) {
45 $this->mId = $page->getId();
46 } else {
47 throw new InvalidArgumentException( "Page ID not known. Page doesn't exist?" );
48 }
49
50 $this->timestamp = $timestamp ?: wfTimestampNow();
51
52 $fakePO = new ParserOutput();
53 $fakePO->setCacheTime( $timestamp );
54 parent::__construct( $page->getTitle(), $fakePO, false );
55 }
56
57 protected function doIncrementalUpdate() {
58 $services = MediaWikiServices::getInstance();
59 $config = $services->getMainConfig();
60 $lbFactory = $services->getDBLoadBalancerFactory();
61 $batchSize = $config->get( 'UpdateRowsPerQuery' );
62
63 $id = $this->mId;
64 $title = $this->mTitle;
65
66 $dbw = $this->getDB(); // convenience
67
68 parent::doIncrementalUpdate();
69
70 // Typically, a category is empty when deleted, so check that we don't leave
71 // spurious row in the category table.
72 if ( $title->getNamespace() === NS_CATEGORY ) {
73 // T166757: do the update after the main job DB commit
74 DeferredUpdates::addCallableUpdate( function () use ( $title ) {
75 $cat = Category::newFromName( $title->getDBkey() );
76 $cat->refreshCountsIfEmpty();
77 } );
78 }
79
80 // Delete restrictions for the deleted page
81 $dbw->delete( 'page_restrictions', [ 'pr_page' => $id ], __METHOD__ );
82
83 // Delete any redirect entry
84 $dbw->delete( 'redirect', [ 'rd_from' => $id ], __METHOD__ );
85
86 // Find recentchanges entries to clean up...
87 $rcIdsForTitle = $dbw->selectFieldValues(
88 'recentchanges',
89 'rc_id',
90 [
91 'rc_type != ' . RC_LOG,
92 'rc_namespace' => $title->getNamespace(),
93 'rc_title' => $title->getDBkey(),
94 'rc_timestamp < ' .
95 $dbw->addQuotes( $dbw->timestamp( $this->timestamp ) )
96 ],
98 );
99 $rcIdsForPage = $dbw->selectFieldValues(
100 'recentchanges',
101 'rc_id',
102 [ 'rc_type != ' . RC_LOG, 'rc_cur_id' => $id ],
103 __METHOD__
104 );
105
106 // T98706: delete by PK to avoid lock contention with RC delete log insertions
107 $rcIdBatches = array_chunk( array_merge( $rcIdsForTitle, $rcIdsForPage ), $batchSize );
108 foreach ( $rcIdBatches as $rcIdBatch ) {
109 $dbw->delete( 'recentchanges', [ 'rc_id' => $rcIdBatch ], __METHOD__ );
110 if ( count( $rcIdBatches ) > 1 ) {
111 $lbFactory->commitAndWaitForReplication(
112 __METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
113 );
114 }
115 }
116
117 // Commit and release the lock (if set)
118 ScopedCallback::consume( $scopedLock );
119 }
120
121 public function getAsJobSpecification() {
122 return [
123 'domain' => $this->getDB()->getDomainID(),
124 'job' => new JobSpecification(
125 'deleteLinks',
126 [ 'pageId' => $this->mId, 'timestamp' => $this->timestamp ],
127 [ 'removeDuplicates' => true ],
128 $this->mTitle
129 )
130 ];
131 }
132}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
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:45
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition hooks.txt:2290
const RC_LOG
Definition Defines.php:153
const NS_CATEGORY
Definition Defines.php:87
Interface that marks a DataUpdate as enqueuable via the JobQueue.