Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / search / ParserOutputSearchDataExtractor.php
blob4bb0ebea545d119e5ded8fd05be5ce5eb10b5fab
1 <?php
3 namespace MediaWiki\Search;
5 use MediaWiki\Parser\ParserOutput;
6 use MediaWiki\Parser\ParserOutputLinkTypes;
7 use MediaWiki\Title\Title;
9 /**
10 * Extracts data from ParserOutput for indexing in the search engine.
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.
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.
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
27 * @since 1.28
29 class ParserOutputSearchDataExtractor {
31 /**
32 * Get a list of categories, as an array with title text strings.
34 * @param ParserOutput $parserOutput
35 * @return string[]
37 public function getCategories( ParserOutput $parserOutput ) {
38 $categories = [];
40 foreach (
41 $parserOutput->getLinkList( ParserOutputLinkTypes::CATEGORY )
42 as [ 'link' => $link ]
43 ) {
44 $categories[] = $link->getText();
47 return $categories;
50 /**
51 * Get a list of external links from ParserOutput, as an array of strings.
53 * @param ParserOutput $parserOutput
54 * @return string[]
56 public function getExternalLinks( ParserOutput $parserOutput ) {
57 return array_keys( $parserOutput->getExternalLinks() );
60 /**
61 * Get a list of outgoing wiki links (including interwiki links), as
62 * an array of prefixed title strings.
64 * @param ParserOutput $parserOutput
65 * @return string[]
67 public function getOutgoingLinks( ParserOutput $parserOutput ) {
68 $outgoingLinks = [];
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();
80 return $outgoingLinks;
83 /**
84 * Get a list of templates used in the ParserOutput content, as prefixed title strings
86 * @param ParserOutput $parserOutput
87 * @return string[]
89 public function getTemplates( ParserOutput $parserOutput ) {
90 $templates = [];
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();
101 return $templates;