MediaWiki
1.39.10
LinksDeletionUpdate.php
Go to the documentation of this file.
1
<?php
23
namespace
MediaWiki\Deferred\LinksUpdate
;
24
25
use
Category
;
26
use
DeferredUpdates
;
27
use
EnqueueableDataUpdate
;
28
use InvalidArgumentException;
29
use
JobSpecification
;
30
use
MediaWiki\MainConfigNames
;
31
use
MediaWiki\MediaWikiServices
;
32
use
MWException
;
33
use
ParserOutput
;
34
use
WikiPage
;
35
39
class
LinksDeletionUpdate
extends
LinksUpdate
implements
EnqueueableDataUpdate
{
41
protected
$page
;
43
protected
$timestamp
;
44
51
public
function
__construct
(
WikiPage
$page
, $pageId =
null
,
$timestamp
=
null
) {
52
$this->page =
$page
;
53
if
( $pageId ) {
54
$this->mId = $pageId;
// page ID at time of deletion
55
} elseif (
$page
->
exists
() ) {
56
$this->mId =
$page
->
getId
();
57
}
else
{
58
throw
new
InvalidArgumentException(
"Page ID not known. Page doesn't exist?"
);
59
}
60
61
$this->timestamp =
$timestamp
?:
wfTimestampNow
();
62
63
$fakePO =
new
ParserOutput
();
64
$fakePO->setCacheTime(
$timestamp
);
65
// Use immutable page identity to keep reference to the page id at time of deletion - T299244
66
$immutablePageIdentity =
$page
->
getTitle
()->toPageIdentity();
67
parent::__construct( $immutablePageIdentity, $fakePO,
false
);
68
}
69
70
protected
function
doIncrementalUpdate
() {
71
$services =
MediaWikiServices::getInstance
();
72
$config = $services->getMainConfig();
73
$lbFactory = $services->getDBLoadBalancerFactory();
74
$batchSize = $config->get(
MainConfigNames::UpdateRowsPerQuery
);
75
76
$id =
$this->mId
;
77
$title
=
$this->mTitle
;
78
79
$dbw = $this->
getDB
();
// convenience
80
81
parent::doIncrementalUpdate();
82
83
// Typically, a category is empty when deleted, so check that we don't leave
84
// spurious row in the category table.
85
if
(
$title
->getNamespace() ===
NS_CATEGORY
) {
86
// T166757: do the update after the main job DB commit
87
DeferredUpdates::addCallableUpdate(
static
function
() use (
$title
) {
88
$cat =
Category::newFromName
(
$title
->getDBkey() );
89
$cat->refreshCountsIfSmall();
90
} );
91
}
92
93
// Delete restrictions for the deleted page
94
$dbw->delete(
'page_restrictions'
, [
'pr_page'
=> $id ], __METHOD__ );
95
96
// Delete any redirect entry
97
$dbw->delete(
'redirect'
, [
'rd_from'
=> $id ], __METHOD__ );
98
99
// Find recentchanges entries to clean up...
100
$rcIdsForTitle = $dbw->selectFieldValues(
101
'recentchanges'
,
102
'rc_id'
,
103
[
104
'rc_type != '
.
RC_LOG
,
105
'rc_namespace'
=>
$title
->getNamespace(),
106
'rc_title'
=>
$title
->getDBkey(),
107
'rc_timestamp < '
.
108
$dbw->addQuotes( $dbw->timestamp( $this->timestamp ) )
109
],
110
__METHOD__
111
);
112
$rcIdsForPage = $dbw->selectFieldValues(
113
'recentchanges'
,
114
'rc_id'
,
115
[
'rc_type != '
.
RC_LOG
,
'rc_cur_id'
=> $id ],
116
__METHOD__
117
);
118
119
// T98706: delete by PK to avoid lock contention with RC delete log insertions
120
$rcIdBatches = array_chunk( array_merge( $rcIdsForTitle, $rcIdsForPage ), $batchSize );
121
foreach
( $rcIdBatches as $rcIdBatch ) {
122
$dbw->delete(
'recentchanges'
, [
'rc_id'
=> $rcIdBatch ], __METHOD__ );
123
if
( count( $rcIdBatches ) > 1 ) {
124
$lbFactory->commitAndWaitForReplication(
125
__METHOD__, $this->ticket, [
'domain'
=> $dbw->getDomainID() ]
126
);
127
}
128
}
129
}
130
131
public
function
getAsJobSpecification
() {
132
return
[
133
'domain'
=> $this->
getDB
()->getDomainID(),
134
'job'
=>
new
JobSpecification
(
135
'deleteLinks'
,
136
[
'pageId'
=> $this->mId,
'timestamp'
=> $this->timestamp ],
137
[
'removeDuplicates'
=>
true
],
138
$this->mTitle
139
)
140
];
141
}
142
}
143
145
class_alias( LinksDeletionUpdate::class,
'LinksDeletionUpdate'
);
RC_LOG
const RC_LOG
Definition
Defines.php:118
NS_CATEGORY
const NS_CATEGORY
Definition
Defines.php:78
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition
GlobalFunctions.php:1453
Category
Category objects are immutable, strictly speaking.
Definition
Category.php:33
Category\newFromName
static newFromName( $name)
Factory function.
Definition
Category.php:150
DeferredUpdates
Class for managing the deferral of updates within the scope of a PHP script invocation.
Definition
DeferredUpdates.php:82
JobSpecification
Job queue task description base code.
Definition
JobSpecification.php:42
MWException
MediaWiki exception.
Definition
MWException.php:29
MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate
Update object handling the cleanup of links tables after a page was deleted.
Definition
LinksDeletionUpdate.php:39
MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate\getAsJobSpecification
getAsJobSpecification()
Definition
LinksDeletionUpdate.php:131
MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate\$page
WikiPage $page
Definition
LinksDeletionUpdate.php:41
MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate\$timestamp
string $timestamp
Definition
LinksDeletionUpdate.php:43
MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate\__construct
__construct(WikiPage $page, $pageId=null, $timestamp=null)
Definition
LinksDeletionUpdate.php:51
MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate\doIncrementalUpdate
doIncrementalUpdate()
Definition
LinksDeletionUpdate.php:70
MediaWiki\Deferred\LinksUpdate\LinksUpdate
Class the manages updates of *_link tables as well as similar extension-managed tables.
Definition
LinksUpdate.php:55
MediaWiki\Deferred\LinksUpdate\LinksUpdate\$mTitle
Title $mTitle
Title object of the article linked from.
Definition
LinksUpdate.php:65
MediaWiki\Deferred\LinksUpdate\LinksUpdate\getDB
getDB()
Definition
LinksUpdate.php:613
MediaWiki\Deferred\LinksUpdate\LinksUpdate\$mId
int $mId
Page ID of the article linked from.
Definition
LinksUpdate.php:62
MediaWiki\MainConfigNames
A class containing constants representing the names of configuration variables.
Definition
MainConfigNames.php:23
MediaWiki\MainConfigNames\UpdateRowsPerQuery
const UpdateRowsPerQuery
Name constant for the UpdateRowsPerQuery setting, for use with Config::get()
Definition
MainConfigNames.php:4361
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:212
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition
MediaWikiServices.php:273
ParserOutput
Definition
ParserOutput.php:38
WikiPage
Base representation for an editable wiki page.
Definition
WikiPage.php:62
WikiPage\exists
exists()
Definition
WikiPage.php:585
WikiPage\getId
getId( $wikiId=self::LOCAL)
Definition
WikiPage.php:573
WikiPage\getTitle
getTitle()
Get the title object of the article.
Definition
WikiPage.php:303
EnqueueableDataUpdate
Interface that marks a DataUpdate as enqueuable via the JobQueue.
Definition
EnqueueableDataUpdate.php:12
MediaWiki\Deferred\LinksUpdate
Definition
CategoryLinksTable.php:3
$title
$title
Definition
testCompression.php:38
includes
deferred
LinksUpdate
LinksDeletionUpdate.php
Generated on Tue Oct 1 2024 01:15:29 for MediaWiki by
1.10.0