MediaWiki  master
Go to the documentation of this file.
1 <?php
24 namespace MediaWiki\SpecialPage;
26 use HtmlArmor;
32 use Skin;
33 use stdClass;
43 abstract class PageQueryPage extends QueryPage {
46  private $languageConverter = null;
58  public function preprocessResults( $db, $res ) {
59  $this->executeLBFromResultWrapper( $res );
60  }
66  final protected function setLanguageConverter( ILanguageConverter $languageConverter ) {
67  $this->languageConverter = $languageConverter;
68  }
76  final protected function getLanguageConverter(): ILanguageConverter {
77  if ( $this->languageConverter === null ) {
78  // Fallback if not provided
79  // TODO Change to wfWarn in a future release
80  $this->languageConverter = MediaWikiServices::getInstance()->getLanguageConverterFactory()
81  ->getLanguageConverter( $this->getContentLanguage() );
82  }
83  return $this->languageConverter;
84  }
95  public function formatResult( $skin, $row ) {
96  $title = Title::makeTitleSafe( $row->namespace, $row->title );
97  if ( $title instanceof Title ) {
99  $text = $this->getLanguageConverter()->convertHtml( $title->getPrefixedText() );
100  return $this->getLinkRenderer()->makeLink( $title, new HtmlArmor( $text ) );
101  } else {
102  return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
103  Linker::getInvalidTitleDescription( $this->getContext(), $row->namespace, $row->title ) );
104  }
105  }
106 }
112 class_alias( PageQueryPage::class, 'PageQueryPage' );
Definition: WebStart.php:88
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:30
This class is a collection of static functions that serve two purposes:
Definition: Html.php:57
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:264
Some internal bits split of from Skin.php.
Definition: Linker.php:65
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:229
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Variant of QueryPage which formats the result as a simple link to the page.
formatResult( $skin, $row)
Format the result as a simple link to the page.
setLanguageConverter(ILanguageConverter $languageConverter)
preprocessResults( $db, $res)
Run a LinkBatch to pre-cache LinkCache information, like page existence and information for stub colo...
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition: QueryPage.php:88
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
Definition: QueryPage.php:946
Shortcut to get content language.
Represents a title within MediaWiki.
Definition: Title.php:76
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:650
The base class for all skins.
Definition: Skin.php:60
The shared interface for all language converters.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:36
Result wrapper for grabbing data queried from an IDatabase object.