MediaWiki 1.43.1
LangLinksTable.php
Go to the documentation of this file.
1<?php
2
4
6
18 private $newLinks = [];
20 private $existingLinks;
21
22 public function setParserOutput( ParserOutput $parserOutput ) {
23 // Convert the format of the interlanguage links
24 // I didn't want to change it in the ParserOutput, because that array is passed all
25 // the way back to the skin, so either a skin API break would be required, or an
26 // inefficient back-conversion.
27 $ill = $parserOutput->getLanguageLinks();
28 $this->newLinks = [];
29 foreach ( $ill as $link ) {
30 [ $key, $title ] = explode( ':', $link, 2 );
31 // Ensure that the "first" link has precedence: T26502
32 $this->newLinks[$key] ??= $title;
33 }
34 }
35
36 protected function getTableName() {
37 return 'langlinks';
38 }
39
40 protected function getFromField() {
41 return 'll_from';
42 }
43
44 protected function getExistingFields() {
45 return [ 'll_lang', 'll_title' ];
46 }
47
48 protected function getNewLinkIDs() {
49 foreach ( $this->newLinks as $key => $title ) {
50 yield [ (string)$key, $title ];
51 }
52 }
53
60 private function getExistingLinks() {
61 if ( $this->existingLinks === null ) {
62 $this->existingLinks = [];
63 foreach ( $this->fetchExistingRows() as $row ) {
64 $this->existingLinks[$row->ll_lang] = $row->ll_title;
65 }
66 }
67 return $this->existingLinks;
68 }
69
70 protected function getExistingLinkIDs() {
71 foreach ( $this->getExistingLinks() as $lang => $title ) {
72 yield [ (string)$lang, $title ];
73 }
74 }
75
76 protected function isExisting( $linkId ) {
77 $links = $this->getExistingLinks();
78 [ $lang, $title ] = $linkId;
79 return \array_key_exists( $lang, $links )
80 && $links[$lang] === $title;
81 }
82
83 protected function isInNewSet( $linkId ) {
84 [ $lang, $title ] = $linkId;
85 return \array_key_exists( $lang, $this->newLinks )
86 && $this->newLinks[$lang] === $title;
87 }
88
89 protected function insertLink( $linkId ) {
90 [ $lang, $title ] = $linkId;
91 $this->insertRow( [
92 'll_lang' => $lang,
93 'll_title' => $title
94 ] );
95 }
96
97 protected function deleteLink( $linkId ) {
98 $this->deleteRow( [
99 'll_lang' => $linkId[0]
100 ] );
101 }
102}
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.
insertLink( $linkId)
Insert a link identified by ID.
deleteLink( $linkId)
Delete a link identified by ID.
isExisting( $linkId)
Determine whether a link (from the new set) is in the existing set.
setParserOutput(ParserOutput $parserOutput)
Subclasses should implement this to extract the data they need from the ParserOutput.
getExistingFields()
Get the fields to be used in fetchExistingRows().
isInNewSet( $linkId)
Determine whether a link (from the existing set) is in the new set.
getFromField()
Get the name of the field which links to page_id.
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.