MediaWiki REL1_40
InterwikiLinksTable.php
Go to the documentation of this file.
1<?php
2
4
6
18 private $newLinks = [];
19
21 private $existingLinks;
22
23 public function setParserOutput( ParserOutput $parserOutput ) {
24 $this->newLinks = $parserOutput->getInterwikiLinks();
25 }
26
27 protected function getTableName() {
28 return 'iwlinks';
29 }
30
31 protected function getFromField() {
32 return 'iwl_from';
33 }
34
35 protected function getExistingFields() {
36 return [ 'iwl_prefix', 'iwl_title' ];
37 }
38
39 protected function getNewLinkIDs() {
40 foreach ( $this->newLinks as $prefix => $links ) {
41 foreach ( $links as $title => $unused ) {
42 yield [ (string)$prefix, (string)$title ];
43 }
44 }
45 }
46
53 private function getExistingLinks() {
54 if ( $this->existingLinks === null ) {
55 $this->existingLinks = [];
56 foreach ( $this->fetchExistingRows() as $row ) {
57 $this->existingLinks[$row->iwl_prefix][$row->iwl_title] = true;
58 }
59 }
60 return $this->existingLinks;
61 }
62
63 protected function getExistingLinkIDs() {
64 foreach ( $this->getExistingLinks() as $prefix => $links ) {
65 foreach ( $links as $title => $unused ) {
66 yield [ (string)$prefix, (string)$title ];
67 }
68 }
69 }
70
71 protected function isExisting( $linkId ) {
72 $links = $this->getExistingLinks();
73 [ $prefix, $title ] = $linkId;
74 return isset( $links[$prefix][$title] );
75 }
76
77 protected function isInNewSet( $linkId ) {
78 [ $prefix, $title ] = $linkId;
79 return isset( $this->newLinks[$prefix][$title] );
80 }
81
82 protected function insertLink( $linkId ) {
83 [ $prefix, $title ] = $linkId;
84 $this->insertRow( [
85 'iwl_prefix' => $prefix,
86 'iwl_title' => $title
87 ] );
88 }
89
90 protected function deleteLink( $linkId ) {
91 [ $prefix, $title ] = $linkId;
92 $this->deleteRow( [
93 'iwl_prefix' => $prefix,
94 'iwl_title' => $title
95 ] );
96 }
97}
insertLink( $linkId)
Insert a link identified by ID.
getNewLinkIDs()
Get an array (or iterator) of link IDs for the new state.
getExistingLinkIDs()
Get an array (or iterator) of link IDs for the existing state.
isInNewSet( $linkId)
Determine whether a link (from the existing set) is in the new set.
deleteLink( $linkId)
Delete a link identified by ID.
getFromField()
Get the name of the field which links to page_id.
isExisting( $linkId)
Determine whether a link (from the new set) is in the existing set.
getExistingFields()
Get the fields to be used in fetchExistingRows().
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.