MediaWiki master
ParserOutputSearchDataExtractor.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Search;
4
8
16
23 public function getCategories( ParserOutput $parserOutput ) {
24 $categories = [];
25
26 foreach (
27 $parserOutput->getLinkList( ParserOutputLinkTypes::CATEGORY )
28 as [ 'link' => $link ]
29 ) {
30 $categories[] = $link->getText();
31 }
32
33 return $categories;
34 }
35
42 public function getExternalLinks( ParserOutput $parserOutput ) {
43 return array_keys( $parserOutput->getExternalLinks() );
44 }
45
53 public function getOutgoingLinks( ParserOutput $parserOutput ) {
54 $outgoingLinks = [];
55
56 foreach (
57 $parserOutput->getLinkList( ParserOutputLinkTypes::LOCAL )
58 as [ 'link' => $link ]
59 ) {
60 // XXX should use a TitleFormatter
61 // XXX why is this a DBkey when all of the others are text?
62 $outgoingLinks[] =
63 Title::newFromLinkTarget( $link )->getPrefixedDBkey();
64 }
65
66 return $outgoingLinks;
67 }
68
75 public function getTemplates( ParserOutput $parserOutput ) {
76 $templates = [];
77
78 foreach (
79 $parserOutput->getLinkList( ParserOutputLinkTypes::TEMPLATE )
80 as [ 'link' => $link ]
81 ) {
82 // XXX should use a TitleFormatter
83 $templates[] =
84 Title::newFromLinkTarget( $link )->getPrefixedText();
85 }
86
87 return $templates;
88 }
89
90}
ParserOutput is a rendering of a Content object or a message.
getLinkList(string|ParserOutputLinkTypes $linkType, ?int $onlyNamespace=null)
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:69
Definition of a mapping for the search index field.