Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
61.54% |
8 / 13 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
TitleLinksTable | |
61.54% |
8 / 13 |
|
25.00% |
1 / 4 |
9.79 | |
0.00% |
0 / 1 |
makePageReferenceValue | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
makeTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
deduplicateLinkIds | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getDeduplicatedLinkIds | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
getTitleArray | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
getPageReferenceIterator | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Deferred\LinksUpdate; |
4 | |
5 | use MediaWiki\Page\PageReferenceValue; |
6 | use MediaWiki\Title\Title; |
7 | |
8 | /** |
9 | * An abstract base class for tables that link to local titles. |
10 | * |
11 | * @stable to extend |
12 | * @since 1.38 |
13 | */ |
14 | abstract class TitleLinksTable extends LinksTable { |
15 | /** |
16 | * Convert a link ID to a PageReferenceValue |
17 | * |
18 | * @param mixed $linkId |
19 | * @return PageReferenceValue |
20 | */ |
21 | abstract protected function makePageReferenceValue( $linkId ): PageReferenceValue; |
22 | |
23 | /** |
24 | * Convert a link ID to a Title |
25 | * |
26 | * @stable to override |
27 | * @param mixed $linkId |
28 | * @return Title |
29 | */ |
30 | protected function makeTitle( $linkId ): Title { |
31 | return Title::newFromPageReference( $this->makePageReferenceValue( $linkId ) ); |
32 | } |
33 | |
34 | /** |
35 | * Given an iterator over link IDs, remove links which go to the same |
36 | * title, leaving only one link per title. |
37 | * |
38 | * @param iterable<mixed> $linkIds |
39 | * @return iterable<mixed> |
40 | */ |
41 | abstract protected function deduplicateLinkIds( $linkIds ); |
42 | |
43 | /** |
44 | * Get link IDs for a given set type, filtering out duplicate links to the |
45 | * same title. |
46 | * |
47 | * @param int $setType |
48 | * @return iterable<mixed> |
49 | */ |
50 | protected function getDeduplicatedLinkIds( $setType ) { |
51 | $linkIds = $this->getLinkIDs( $setType ); |
52 | // Only the CHANGED set type should have duplicates |
53 | if ( $setType === self::CHANGED ) { |
54 | $linkIds = $this->deduplicateLinkIds( $linkIds ); |
55 | } |
56 | return $linkIds; |
57 | } |
58 | |
59 | /** |
60 | * Get a link set as an array of Title objects. This is memory-inefficient. |
61 | * |
62 | * @deprecated since 1.38 |
63 | * @param int $setType |
64 | * @return Title[] |
65 | */ |
66 | public function getTitleArray( $setType ) { |
67 | $linkIds = $this->getDeduplicatedLinkIds( $setType ); |
68 | $titles = []; |
69 | foreach ( $linkIds as $linkId ) { |
70 | $titles[] = $this->makeTitle( $linkId ); |
71 | } |
72 | return $titles; |
73 | } |
74 | |
75 | /** |
76 | * Get a link set as an iterator over PageReferenceValue objects. |
77 | * |
78 | * @param int $setType |
79 | * @return iterable<PageReferenceValue> |
80 | * @phan-return \Traversable |
81 | */ |
82 | public function getPageReferenceIterator( $setType ) { |
83 | $linkIds = $this->getDeduplicatedLinkIds( $setType ); |
84 | foreach ( $linkIds as $linkId ) { |
85 | yield $this->makePageReferenceValue( $linkId ); |
86 | } |
87 | } |
88 | } |