Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / specialpage / PageQueryPage.php
blob8cd79b9a555386df4da214ef437a3837f838d526
1 <?php
2 /**
3 * Variant of QueryPage which formats the result as a simple link to the page.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
24 namespace MediaWiki\SpecialPage;
26 use HtmlArmor;
27 use MediaWiki\Html\Html;
28 use MediaWiki\Language\ILanguageConverter;
29 use MediaWiki\Linker\Linker;
30 use MediaWiki\MediaWikiServices;
31 use MediaWiki\Title\Title;
32 use Skin;
33 use stdClass;
34 use Wikimedia\Rdbms\IDatabase;
35 use Wikimedia\Rdbms\IResultWrapper;
37 /**
38 * Variant of QueryPage which formats the result as a simple link to the page
40 * @stable to extend
41 * @ingroup SpecialPage
43 abstract class PageQueryPage extends QueryPage {
45 /** @var ILanguageConverter|null */
46 private $languageConverter = null;
48 /**
49 * Run a LinkBatch to pre-cache LinkCache information,
50 * like page existence and information for stub color and redirect hints.
51 * This should be done for live data and cached data.
53 * @stable to override
55 * @param IDatabase $db
56 * @param IResultWrapper $res
58 public function preprocessResults( $db, $res ) {
59 $this->executeLBFromResultWrapper( $res );
62 /**
63 * @since 1.36
64 * @param ILanguageConverter $languageConverter
66 final protected function setLanguageConverter( ILanguageConverter $languageConverter ) {
67 $this->languageConverter = $languageConverter;
70 /**
71 * @note Call self::setLanguageConverter in your constructor when overriding
73 * @since 1.36
74 * @return ILanguageConverter
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() );
83 return $this->languageConverter;
86 /**
87 * Format the result as a simple link to the page
89 * @stable to override
91 * @param Skin $skin
92 * @param stdClass $row Result row
93 * @return string
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 ) );
108 /** @deprecated class alias since 1.41 */
109 class_alias( PageQueryPage::class, 'PageQueryPage' );