MediaWiki master
ParserOutputSearchDataExtractor.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Search;
4
8
30
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
56 public function getExternalLinks( ParserOutput $parserOutput ) {
57 return array_keys( $parserOutput->getExternalLinks() );
58 }
59
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
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}
ParserOutput is a rendering of a Content object or a message.
getLinkList(string $linkType)
Get a list of links of the given type.
Extracts data from ParserOutput for indexing in the search engine.
getExternalLinks(ParserOutput $parserOutput)
Get a list of external links from ParserOutput, as an array of strings.
getCategories(ParserOutput $parserOutput)
Get a list of categories, as an array with title text strings.
getOutgoingLinks(ParserOutput $parserOutput)
Get a list of outgoing wiki links (including interwiki links), as an array of prefixed title strings.
getTemplates(ParserOutput $parserOutput)
Get a list of templates used in the ParserOutput content, as prefixed title strings.
Represents a title within MediaWiki.
Definition Title.php:78