MediaWiki
master
Toggle main menu visibility
InterwikiLinksTable.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Deferred\LinksUpdate;
4
5
use MediaWiki\Parser\ParserOutput;
6
use MediaWiki\Parser\ParserOutputLinkTypes;
7
17
class
InterwikiLinksTable
extends
LinksTable
{
19
private
$newLinks = [];
20
22
private
$existingLinks;
23
24
public
function
setParserOutput
(
ParserOutput
$parserOutput ) {
25
$this->newLinks = [];
26
foreach
(
27
$parserOutput->
getLinkList
( ParserOutputLinkTypes::INTERWIKI )
28
as [
'link'
=> $link ]
29
) {
30
$this->newLinks[$link->getInterwiki()][$link->getDBkey()] = 1;
31
}
32
}
33
35
protected
function
getTableName
() {
36
return
'iwlinks'
;
37
}
38
40
protected
function
getFromField
() {
41
return
'iwl_from'
;
42
}
43
45
protected
function
getExistingFields
() {
46
return
[
'iwl_prefix'
,
'iwl_title'
];
47
}
48
50
protected
function
getNewLinkIDs
() {
51
foreach
( $this->newLinks as $prefix => $links ) {
52
foreach
( $links as $title => $unused ) {
53
yield [ (string)$prefix, (
string
)$title ];
54
}
55
}
56
}
57
64
private
function
getExistingLinks() {
65
if
( $this->existingLinks ===
null
) {
66
$this->existingLinks = [];
67
foreach
( $this->
fetchExistingRows
() as $row ) {
68
$this->existingLinks[$row->iwl_prefix][$row->iwl_title] =
true
;
69
}
70
}
71
return
$this->existingLinks;
72
}
73
75
protected
function
getExistingLinkIDs
() {
76
foreach
( $this->getExistingLinks() as $prefix => $links ) {
77
foreach
( $links as $title => $unused ) {
78
yield [ (string)$prefix, (
string
)$title ];
79
}
80
}
81
}
82
84
protected
function
isExisting
( $linkId ) {
85
$links = $this->getExistingLinks();
86
[ $prefix, $title ] = $linkId;
87
return
isset( $links[$prefix][$title] );
88
}
89
91
protected
function
isInNewSet
( $linkId ) {
92
[ $prefix, $title ] = $linkId;
93
return
isset( $this->newLinks[$prefix][$title] );
94
}
95
97
protected
function
insertLink
( $linkId ) {
98
[ $prefix, $title ] = $linkId;
99
$this->
insertRow
( [
100
'iwl_prefix'
=> $prefix,
101
'iwl_title'
=> $title
102
] );
103
}
104
106
protected
function
deleteLink
( $linkId ) {
107
[ $prefix, $title ] = $linkId;
108
$this->
deleteRow
( [
109
'iwl_prefix'
=> $prefix,
110
'iwl_title'
=> $title
111
] );
112
}
113
115
protected
function
virtualDomain
() {
116
return
self::VIRTUAL_DOMAIN;
117
}
118
}
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable
iwlinks
Definition
InterwikiLinksTable.php:17
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\insertLink
insertLink( $linkId)
Insert a link identified by ID.The subclass is expected to queue the insertion by calling insertRow()...
Definition
InterwikiLinksTable.php:97
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\getNewLinkIDs
getNewLinkIDs()
Get an array (or iterator) of link IDs for the new state.See the LinksTable doc comment for an explan...
Definition
InterwikiLinksTable.php:50
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\getExistingLinkIDs
getExistingLinkIDs()
Get an array (or iterator) of link IDs for the existing state.The subclass should load the data from ...
Definition
InterwikiLinksTable.php:75
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\isInNewSet
isInNewSet( $linkId)
Determine whether a link (from the existing set) is in the new set.bool
Definition
InterwikiLinksTable.php:91
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\deleteLink
deleteLink( $linkId)
Delete a link identified by ID.The subclass is expected to queue the deletion by calling deleteRow().
Definition
InterwikiLinksTable.php:106
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\getTableName
getTableName()
Get the table name.string
Definition
InterwikiLinksTable.php:35
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\getFromField
getFromField()
Get the name of the field which links to page_id.string
Definition
InterwikiLinksTable.php:40
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\virtualDomain
virtualDomain()
What virtual domain should be used to read/write from the table.string|bool
Definition
InterwikiLinksTable.php:115
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\isExisting
isExisting( $linkId)
Determine whether a link (from the new set) is in the existing set.bool
Definition
InterwikiLinksTable.php:84
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\getExistingFields
getExistingFields()
Get the fields to be used in fetchExistingRows().Note that fetchExistingRows() is just a helper for s...
Definition
InterwikiLinksTable.php:45
MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\setParserOutput
setParserOutput(ParserOutput $parserOutput)
Subclasses should implement this to extract the data they need from the ParserOutput.
Definition
InterwikiLinksTable.php:24
MediaWiki\Deferred\LinksUpdate\LinksTable
The base class for classes which update a single link table.
Definition
LinksTable.php:43
MediaWiki\Deferred\LinksUpdate\LinksTable\insertRow
insertRow( $row)
Queue a row for insertion.
Definition
LinksTable.php:394
MediaWiki\Deferred\LinksUpdate\LinksTable\fetchExistingRows
fetchExistingRows()
Do a select query to fetch the existing rows.
Definition
LinksTable.php:356
MediaWiki\Deferred\LinksUpdate\LinksTable\deleteRow
deleteRow( $conds)
Queue a deletion operation.
Definition
LinksTable.php:409
MediaWiki\Parser\ParserOutput
ParserOutput is a rendering of a Content object or a message.
Definition
ParserOutput.php:91
MediaWiki\Parser\ParserOutput\getLinkList
getLinkList(string|ParserOutputLinkTypes $linkType, ?int $onlyNamespace=null)
Get a list of links of the given type.
Definition
ParserOutput.php:699
includes
Deferred
LinksUpdate
InterwikiLinksTable.php
Generated on
for MediaWiki by
1.18.0