Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
42.86% |
6 / 14 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
TitleLinksTable | |
42.86% |
6 / 14 |
|
25.00% |
1 / 4 |
16.14 | |
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 | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
getPageReferenceIterator | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
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, hard-deprecated since 1.43 |
63 | * @param int $setType |
64 | * @return Title[] |
65 | */ |
66 | public function getTitleArray( $setType ) { |
67 | wfDeprecated( __METHOD__, '1.43' ); |
68 | $linkIds = $this->getDeduplicatedLinkIds( $setType ); |
69 | $titles = []; |
70 | foreach ( $linkIds as $linkId ) { |
71 | $titles[] = $this->makeTitle( $linkId ); |
72 | } |
73 | return $titles; |
74 | } |
75 | |
76 | /** |
77 | * Get a link set as an iterator over PageReferenceValue objects. |
78 | * |
79 | * @param int $setType |
80 | * @return iterable<PageReferenceValue> |
81 | * @phan-return \Traversable |
82 | */ |
83 | public function getPageReferenceIterator( $setType ) { |
84 | $linkIds = $this->getDeduplicatedLinkIds( $setType ); |
85 | foreach ( $linkIds as $linkId ) { |
86 | yield $this->makePageReferenceValue( $linkId ); |
87 | } |
88 | } |
89 | } |