3 namespace MediaWiki\Search
;
5 use MediaWiki\Parser\ParserOutput
;
6 use MediaWiki\Parser\ParserOutputLinkTypes
;
7 use MediaWiki\Title\Title
;
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
29 class ParserOutputSearchDataExtractor
{
32 * Get a list of categories, as an array with title text strings.
34 * @param ParserOutput $parserOutput
37 public function getCategories( ParserOutput
$parserOutput ) {
41 $parserOutput->getLinkList( ParserOutputLinkTypes
::CATEGORY
)
42 as [ 'link' => $link ]
44 $categories[] = $link->getText();
51 * Get a list of external links from ParserOutput, as an array of strings.
53 * @param ParserOutput $parserOutput
56 public function getExternalLinks( ParserOutput
$parserOutput ) {
57 return array_keys( $parserOutput->getExternalLinks() );
61 * Get a list of outgoing wiki links (including interwiki links), as
62 * an array of prefixed title strings.
64 * @param ParserOutput $parserOutput
67 public function getOutgoingLinks( ParserOutput
$parserOutput ) {
71 $parserOutput->getLinkList( ParserOutputLinkTypes
::LOCAL
)
72 as [ 'link' => $link ]
74 // XXX should use a TitleFormatter
75 // XXX why is this a DBkey when all of the others are text?
77 Title
::newFromLinkTarget( $link )->getPrefixedDBkey();
80 return $outgoingLinks;
84 * Get a list of templates used in the ParserOutput content, as prefixed title strings
86 * @param ParserOutput $parserOutput
89 public function getTemplates( ParserOutput
$parserOutput ) {
93 $parserOutput->getLinkList( ParserOutputLinkTypes
::TEMPLATE
)
94 as [ 'link' => $link ]
96 // XXX should use a TitleFormatter
98 Title
::newFromLinkTarget( $link )->getPrefixedText();