X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/search/ParserOutputSearchDataExtractor.php diff --git a/includes/search/ParserOutputSearchDataExtractor.php b/includes/search/ParserOutputSearchDataExtractor.php new file mode 100644 index 00000000..4b60a0c5 --- /dev/null +++ b/includes/search/ParserOutputSearchDataExtractor.php @@ -0,0 +1,96 @@ +getCategoryLinks() as $key ) { + $categories[] = Category::newFromName( $key )->getTitle()->getText(); + } + + return $categories; + } + + /** + * Get a list of external links from ParserOutput, as an array of strings. + * + * @param ParserOutput $parserOutput + * @return string[] + */ + public function getExternalLinks( ParserOutput $parserOutput ) { + return array_keys( $parserOutput->getExternalLinks() ); + } + + /** + * Get a list of outgoing wiki links (including interwiki links), as + * an array of prefixed title strings. + * + * @param ParserOutput $parserOutput + * @return string[] + */ + public function getOutgoingLinks( ParserOutput $parserOutput ) { + $outgoingLinks = []; + + foreach ( $parserOutput->getLinks() as $linkedNamespace => $namespaceLinks ) { + foreach ( array_keys( $namespaceLinks ) as $linkedDbKey ) { + $outgoingLinks[] = + Title::makeTitle( $linkedNamespace, $linkedDbKey )->getPrefixedDBkey(); + } + } + + return $outgoingLinks; + } + + /** + * Get a list of templates used in the ParserOutput content, as prefixed title strings + * + * @param ParserOutput $parserOutput + * @return string[] + */ + public function getTemplates( ParserOutput $parserOutput ) { + $templates = []; + + foreach ( $parserOutput->getTemplates() as $tNS => $templatesInNS ) { + foreach ( array_keys( $templatesInNS ) as $tDbKey ) { + $templateTitle = Title::makeTitle( $tNS, $tDbKey ); + $templates[] = $templateTitle->getPrefixedText(); + } + } + + return $templates; + } + +}