Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
18 / 18 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
ParserOutputSearchDataExtractor | |
100.00% |
18 / 18 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
getCategories | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
getExternalLinks | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOutgoingLinks | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
getTemplates | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Search; |
4 | |
5 | use MediaWiki\Parser\ParserOutput; |
6 | use MediaWiki\Parser\ParserOutputLinkTypes; |
7 | use MediaWiki\Title\Title; |
8 | |
9 | /** |
10 | * Extracts data from ParserOutput for indexing in the search engine. |
11 | * |
12 | * This program is free software; you can redistribute it and/or modify |
13 | * it under the terms of the GNU General Public License as published by |
14 | * the Free Software Foundation; either version 2 of the License, or |
15 | * (at your option) any later version. |
16 | * |
17 | * This program is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | * GNU General Public License for more details. |
21 | * |
22 | * You should have received a copy of the GNU General Public License along |
23 | * with this program; if not, write to the Free Software Foundation, Inc., |
24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
25 | * http://www.gnu.org/copyleft/gpl.html |
26 | * |
27 | * @since 1.28 |
28 | */ |
29 | class ParserOutputSearchDataExtractor { |
30 | |
31 | /** |
32 | * Get a list of categories, as an array with title text strings. |
33 | * |
34 | * @param ParserOutput $parserOutput |
35 | * @return string[] |
36 | */ |
37 | public function getCategories( ParserOutput $parserOutput ) { |
38 | $categories = []; |
39 | |
40 | foreach ( |
41 | $parserOutput->getLinkList( ParserOutputLinkTypes::CATEGORY ) |
42 | as [ 'link' => $link ] |
43 | ) { |
44 | $categories[] = $link->getText(); |
45 | } |
46 | |
47 | return $categories; |
48 | } |
49 | |
50 | /** |
51 | * Get a list of external links from ParserOutput, as an array of strings. |
52 | * |
53 | * @param ParserOutput $parserOutput |
54 | * @return string[] |
55 | */ |
56 | public function getExternalLinks( ParserOutput $parserOutput ) { |
57 | return array_keys( $parserOutput->getExternalLinks() ); |
58 | } |
59 | |
60 | /** |
61 | * Get a list of outgoing wiki links (including interwiki links), as |
62 | * an array of prefixed title strings. |
63 | * |
64 | * @param ParserOutput $parserOutput |
65 | * @return string[] |
66 | */ |
67 | public function getOutgoingLinks( ParserOutput $parserOutput ) { |
68 | $outgoingLinks = []; |
69 | |
70 | foreach ( |
71 | $parserOutput->getLinkList( ParserOutputLinkTypes::LOCAL ) |
72 | as [ 'link' => $link ] |
73 | ) { |
74 | // XXX should use a TitleFormatter |
75 | // XXX why is this a DBkey when all of the others are text? |
76 | $outgoingLinks[] = |
77 | Title::newFromLinkTarget( $link )->getPrefixedDBkey(); |
78 | } |
79 | |
80 | return $outgoingLinks; |
81 | } |
82 | |
83 | /** |
84 | * Get a list of templates used in the ParserOutput content, as prefixed title strings |
85 | * |
86 | * @param ParserOutput $parserOutput |
87 | * @return string[] |
88 | */ |
89 | public function getTemplates( ParserOutput $parserOutput ) { |
90 | $templates = []; |
91 | |
92 | foreach ( |
93 | $parserOutput->getLinkList( ParserOutputLinkTypes::TEMPLATE ) |
94 | as [ 'link' => $link ] |
95 | ) { |
96 | // XXX should use a TitleFormatter |
97 | $templates[] = |
98 | Title::newFromLinkTarget( $link )->getPrefixedText(); |
99 | } |
100 | |
101 | return $templates; |
102 | } |
103 | |
104 | } |