MediaWiki master
InterwikiLinksTable.php
Go to the documentation of this file.
1<?php
2
4
7
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() {
117 }
118}
insertLink( $linkId)
Insert a link identified by ID.The subclass is expected to queue the insertion by calling insertRow()...
getNewLinkIDs()
Get an array (or iterator) of link IDs for the new state.See the LinksTable doc comment for an explan...
getExistingLinkIDs()
Get an array (or iterator) of link IDs for the existing state.The subclass should load the data from ...
isInNewSet( $linkId)
Determine whether a link (from the existing set) is in the new set.bool
deleteLink( $linkId)
Delete a link identified by ID.The subclass is expected to queue the deletion by calling deleteRow().
getFromField()
Get the name of the field which links to page_id.string
virtualDomain()
What virtual domain should be used to read/write from the table.string|bool
isExisting( $linkId)
Determine whether a link (from the new set) is in the existing set.bool
getExistingFields()
Get the fields to be used in fetchExistingRows().Note that fetchExistingRows() is just a helper for s...
setParserOutput(ParserOutput $parserOutput)
Subclasses should implement this to extract the data they need from the ParserOutput.
The base class for classes which update a single link table.
insertRow( $row)
Queue a row for insertion.
fetchExistingRows()
Do a select query to fetch the existing rows.
deleteRow( $conds)
Queue a deletion operation.
ParserOutput is a rendering of a Content object or a message.
getLinkList(string|ParserOutputLinkTypes $linkType, ?int $onlyNamespace=null)
Get a list of links of the given type.