MediaWiki REL1_39
LangLinksTable.php
Go to the documentation of this file.
1<?php
2
4
6
17 private $newLinks = [];
18 private $existingLinks;
19
20 public function setParserOutput( ParserOutput $parserOutput ) {
21 // Convert the format of the interlanguage links
22 // I didn't want to change it in the ParserOutput, because that array is passed all
23 // the way back to the skin, so either a skin API break would be required, or an
24 // inefficient back-conversion.
25 $ill = $parserOutput->getLanguageLinks();
26 $this->newLinks = [];
27 foreach ( $ill as $link ) {
28 [ $key, $title ] = explode( ':', $link, 2 );
29 $this->newLinks[$key] = $title;
30 }
31 }
32
33 protected function getTableName() {
34 return 'langlinks';
35 }
36
37 protected function getFromField() {
38 return 'll_from';
39 }
40
41 protected function getExistingFields() {
42 return [ 'll_lang', 'll_title' ];
43 }
44
45 protected function getNewLinkIDs() {
46 foreach ( $this->newLinks as $key => $title ) {
47 yield [ (string)$key, $title ];
48 }
49 }
50
57 private function getExistingLinks() {
58 if ( $this->existingLinks === null ) {
59 $this->existingLinks = [];
60 foreach ( $this->fetchExistingRows() as $row ) {
61 $this->existingLinks[$row->ll_lang] = $row->ll_title;
62 }
63 }
64 return $this->existingLinks;
65 }
66
67 protected function getExistingLinkIDs() {
68 foreach ( $this->getExistingLinks() as $lang => $title ) {
69 yield [ (string)$lang, $title ];
70 }
71 }
72
73 protected function isExisting( $linkId ) {
74 $links = $this->getExistingLinks();
75 [ $lang, $title ] = $linkId;
76 return \array_key_exists( $lang, $links )
77 && $links[$lang] === $title;
78 }
79
80 protected function isInNewSet( $linkId ) {
81 [ $lang, $title ] = $linkId;
82 return \array_key_exists( $lang, $this->newLinks )
83 && $this->newLinks[$lang] === $title;
84 }
85
86 protected function insertLink( $linkId ) {
87 [ $lang, $title ] = $linkId;
88 $this->insertRow( [
89 'll_lang' => $lang,
90 'll_title' => $title
91 ] );
92 }
93
94 protected function deleteLink( $linkId ) {
95 $this->deleteRow( [
96 'll_lang' => $linkId[0]
97 ] );
98 }
99}
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.
if(!isset( $args[0])) $lang