MediaWiki master
ExternalLinksTable.php
Go to the documentation of this file.
1<?php
2
4
7
16 public const VIRTUAL_DOMAIN = 'virtual-externallinks';
18 private $newLinks = [];
20 private $existingLinks;
21
22 public function setParserOutput( ParserOutput $parserOutput ) {
23 foreach ( $parserOutput->getExternalLinks() as $url => $unused ) {
24 foreach ( LinkFilter::makeIndexes( $url ) as [ $domainIndex, $path ] ) {
25 $this->newLinks[$domainIndex][$path] = true;
26 }
27 }
28 }
29
31 protected function getTableName() {
32 return 'externallinks';
33 }
34
36 protected function getFromField() {
37 return 'el_from';
38 }
39
41 protected function getExistingFields() {
42 return [ 'el_to_domain_index', 'el_to_path' ];
43 }
44
50 private function getExistingLinks() {
51 if ( $this->existingLinks === null ) {
52 $this->existingLinks = [];
53 foreach ( $this->fetchExistingRows() as $row ) {
54 $this->existingLinks[$row->el_to_domain_index][$row->el_to_path] = true;
55 }
56 }
57 return $this->existingLinks;
58 }
59
61 protected function getNewLinkIDs() {
62 foreach ( $this->newLinks as $domainIndex => $paths ) {
63 foreach ( $paths as $path => $unused ) {
64 yield [ (string)$domainIndex, (string)$path ];
65 }
66 }
67 }
68
70 protected function getExistingLinkIDs() {
71 foreach ( $this->getExistingLinks() as $domainIndex => $paths ) {
72 foreach ( $paths as $path => $unused ) {
73 yield [ (string)$domainIndex, (string)$path ];
74 }
75 }
76 }
77
79 protected function isExisting( $linkId ) {
80 [ $domainIndex, $path ] = $linkId;
81 return isset( $this->getExistingLinks()[$domainIndex][$path] );
82 }
83
85 protected function isInNewSet( $linkId ) {
86 [ $domainIndex, $path ] = $linkId;
87 return isset( $this->newLinks[$domainIndex][$path] );
88 }
89
91 protected function insertLink( $linkId ) {
92 [ $domainIndex, $path ] = $linkId;
93 $params = [
94 'el_to_domain_index' => substr( $domainIndex, 0, 255 ),
95 'el_to_path' => $path,
96 ];
97 $this->insertRow( $params );
98 }
99
101 protected function deleteLink( $linkId ) {
102 [ $domainIndex, $path ] = $linkId;
103 $this->deleteRow( [
104 'el_to_domain_index' => substr( $domainIndex, 0, 255 ),
105 'el_to_path' => $path
106 ] );
107 if ( $path === '' ) {
108 // el_to_path is nullable, but null is not valid in php arrays,
109 // so both values are handled as one key, delete both rows when exists
110 $this->deleteRow( [
111 'el_to_domain_index' => substr( $domainIndex, 0, 255 ),
112 'el_to_path' => null
113 ] );
114 }
115 }
116
123 public function getStringArray( $setType ) {
124 $ids = $this->getLinkIDs( $setType );
125 $stringArray = [];
126 foreach ( $ids as $linkId ) {
127 [ $domainIndex, $path ] = $linkId;
128 $stringArray[] = LinkFilter::reverseIndexes( $domainIndex ) . $path;
129 }
130 return $stringArray;
131 }
132
134 protected function virtualDomain() {
136 }
137}
getFromField()
Get the name of the field which links to page_id.string
isInNewSet( $linkId)
Determine whether a link (from the existing set) is in the new set.bool
getExistingLinkIDs()
Get an array (or iterator) of link IDs for the existing state.The subclass should load the data from ...
getNewLinkIDs()
Get an array (or iterator) of link IDs for the new state.See the LinksTable doc comment for an explan...
getExistingFields()
Get the fields to be used in fetchExistingRows().Note that fetchExistingRows() is just a helper for s...
deleteLink( $linkId)
Delete a link identified by ID.The subclass is expected to queue the deletion by calling deleteRow().
getStringArray( $setType)
Get an array of URLs of the given type.
setParserOutput(ParserOutput $parserOutput)
Subclasses should implement this to extract the data they need from the ParserOutput.
virtualDomain()
What virtual domain should be used to read/write from the table.string|bool
insertLink( $linkId)
Insert a link identified by ID.The subclass is expected to queue the insertion by calling insertRow()...
isExisting( $linkId)
Determine whether a link (from the new set) is in the existing set.bool
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.
getLinkIDs( $setType)
Get an array or iterator of link IDs of a given type.
deleteRow( $conds)
Queue a deletion operation.
ParserOutput is a rendering of a Content object or a message.