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