MediaWiki REL1_31
ParserOutputSearchDataExtractor.php
Go to the documentation of this file.
1<?php
2
4
5use Category;
7use Title;
8
30
37 public function getCategories( ParserOutput $parserOutput ) {
38 $categories = [];
39
40 foreach ( $parserOutput->getCategoryLinks() as $key ) {
41 $categories[] = Category::newFromName( $key )->getTitle()->getText();
42 }
43
44 return $categories;
45 }
46
53 public function getExternalLinks( ParserOutput $parserOutput ) {
54 return array_keys( $parserOutput->getExternalLinks() );
55 }
56
64 public function getOutgoingLinks( ParserOutput $parserOutput ) {
65 $outgoingLinks = [];
66
67 foreach ( $parserOutput->getLinks() as $linkedNamespace => $namespaceLinks ) {
68 foreach ( array_keys( $namespaceLinks ) as $linkedDbKey ) {
69 $outgoingLinks[] =
70 Title::makeTitle( $linkedNamespace, $linkedDbKey )->getPrefixedDBkey();
71 }
72 }
73
74 return $outgoingLinks;
75 }
76
83 public function getTemplates( ParserOutput $parserOutput ) {
84 $templates = [];
85
86 foreach ( $parserOutput->getTemplates() as $tNS => $templatesInNS ) {
87 foreach ( array_keys( $templatesInNS ) as $tDbKey ) {
88 $templateTitle = Title::makeTitle( $tNS, $tDbKey );
89 $templates[] = $templateTitle->getPrefixedText();
90 }
91 }
92
93 return $templates;
94 }
95
96}
Category objects are immutable, strictly speaking.
Definition Category.php:31
static newFromName( $name)
Factory function.
Definition Category.php:126
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:39