MediaWiki master
InterwikiLinksTable.php
Go to the documentation of this file.
1<?php
2
4
7
18 public const VIRTUAL_DOMAIN = 'virtual-interwikilinks';
19
21 private $newLinks = [];
22
24 private $existingLinks;
25
26 public function setParserOutput( ParserOutput $parserOutput ) {
27 $this->newLinks = [];
28 foreach (
29 $parserOutput->getLinkList( ParserOutputLinkTypes::INTERWIKI )
30 as [ 'link' => $link ]
31 ) {
32 $this->newLinks[$link->getInterwiki()][$link->getDBkey()] = 1;
33 }
34 }
35
37 protected function getTableName() {
38 return 'iwlinks';
39 }
40
42 protected function getFromField() {
43 return 'iwl_from';
44 }
45
47 protected function getExistingFields() {
48 return [ 'iwl_prefix', 'iwl_title' ];
49 }
50
52 protected function getNewLinkIDs() {
53 foreach ( $this->newLinks as $prefix => $links ) {
54 foreach ( $links as $title => $unused ) {
55 yield [ (string)$prefix, (string)$title ];
56 }
57 }
58 }
59
66 private function getExistingLinks() {
67 if ( $this->existingLinks === null ) {
68 $this->existingLinks = [];
69 foreach ( $this->fetchExistingRows() as $row ) {
70 $this->existingLinks[$row->iwl_prefix][$row->iwl_title] = true;
71 }
72 }
73 return $this->existingLinks;
74 }
75
77 protected function getExistingLinkIDs() {
78 foreach ( $this->getExistingLinks() as $prefix => $links ) {
79 foreach ( $links as $title => $unused ) {
80 yield [ (string)$prefix, (string)$title ];
81 }
82 }
83 }
84
86 protected function isExisting( $linkId ) {
87 $links = $this->getExistingLinks();
88 [ $prefix, $title ] = $linkId;
89 return isset( $links[$prefix][$title] );
90 }
91
93 protected function isInNewSet( $linkId ) {
94 [ $prefix, $title ] = $linkId;
95 return isset( $this->newLinks[$prefix][$title] );
96 }
97
99 protected function insertLink( $linkId ) {
100 [ $prefix, $title ] = $linkId;
101 $this->insertRow( [
102 'iwl_prefix' => $prefix,
103 'iwl_title' => $title
104 ] );
105 }
106
108 protected function deleteLink( $linkId ) {
109 [ $prefix, $title ] = $linkId;
110 $this->deleteRow( [
111 'iwl_prefix' => $prefix,
112 'iwl_title' => $title
113 ] );
114 }
115
117 protected function getVirtualDomain() {
119 }
120}
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
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.