Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
30 / 30 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
InterwikiLinksTable | |
100.00% |
30 / 30 |
|
100.00% |
11 / 11 |
17 | |
100.00% |
1 / 1 |
setParserOutput | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTableName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFromField | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getExistingFields | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getNewLinkIDs | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
getExistingLinks | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
getExistingLinkIDs | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
isExisting | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
isInNewSet | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
insertLink | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
deleteLink | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Deferred\LinksUpdate; |
4 | |
5 | use MediaWiki\Parser\ParserOutput; |
6 | |
7 | /** |
8 | * iwlinks |
9 | * |
10 | * Link ID format: string[] |
11 | * - 0: Interwiki prefix |
12 | * - 1: Foreign title |
13 | * |
14 | * @since 1.38 |
15 | */ |
16 | class InterwikiLinksTable extends LinksTable { |
17 | /** @var array */ |
18 | private $newLinks = []; |
19 | |
20 | /** @var array|null */ |
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 | |
47 | /** |
48 | * Get the existing links as a 2-d array, with the prefix in the first key, |
49 | * the title in the second key, and the value arbitrary. |
50 | * |
51 | * @return array|null |
52 | */ |
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 | } |