MediaWiki  master
ParserOutputSearchDataExtractor.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Search;
4 
5 use Category;
6 use ParserOutput;
7 use 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 }
ParserOutput
Definition: ParserOutput.php:25
MediaWiki\Search\ParserOutputSearchDataExtractor\getCategories
getCategories(ParserOutput $parserOutput)
Get a list of categories, as an array with title text strings.
Definition: ParserOutputSearchDataExtractor.php:37
Category
Category objects are immutable, strictly speaking.
Definition: Category.php:32
MediaWiki\Search\ParserOutputSearchDataExtractor
Extracts data from ParserOutput for indexing in the search engine.
Definition: ParserOutputSearchDataExtractor.php:29
ParserOutput\getCategoryLinks
getCategoryLinks()
Definition: ParserOutput.php:555
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:592
ParserOutput\getExternalLinks
& getExternalLinks()
Definition: ParserOutput.php:607
MediaWiki\Search\ParserOutputSearchDataExtractor\getExternalLinks
getExternalLinks(ParserOutput $parserOutput)
Get a list of external links from ParserOutput, as an array of strings.
Definition: ParserOutputSearchDataExtractor.php:53
ParserOutput\getTemplates
& getTemplates()
Definition: ParserOutput.php:591
MediaWiki\Search
Title
Represents a title within MediaWiki.
Definition: Title.php:42
MediaWiki\Search\ParserOutputSearchDataExtractor\getOutgoingLinks
getOutgoingLinks(ParserOutput $parserOutput)
Get a list of outgoing wiki links (including interwiki links), as an array of prefixed title strings.
Definition: ParserOutputSearchDataExtractor.php:64
Category\newFromName
static newFromName( $name)
Factory function.
Definition: Category.php:133
ParserOutput\getLinks
& getLinks()
Definition: ParserOutput.php:579
MediaWiki\Search\ParserOutputSearchDataExtractor\getTemplates
getTemplates(ParserOutput $parserOutput)
Get a list of templates used in the ParserOutput content, as prefixed title strings.
Definition: ParserOutputSearchDataExtractor.php:83