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
21 * @ingroup SpecialPage
24 namespace MediaWiki\SpecialPage
;
27 use MediaWiki\Html\Html
;
28 use MediaWiki\Language\ILanguageConverter
;
29 use MediaWiki\Linker\Linker
;
30 use MediaWiki\MediaWikiServices
;
31 use MediaWiki\Title\Title
;
34 use Wikimedia\Rdbms\IDatabase
;
35 use Wikimedia\Rdbms\IResultWrapper
;
38 * Variant of QueryPage which formats the result as a simple link to the page
41 * @ingroup SpecialPage
43 abstract class PageQueryPage
extends QueryPage
{
45 /** @var ILanguageConverter|null */
46 private $languageConverter = null;
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.
55 * @param IDatabase $db
56 * @param IResultWrapper $res
58 public function preprocessResults( $db, $res ) {
59 $this->executeLBFromResultWrapper( $res );
64 * @param ILanguageConverter $languageConverter
66 final protected function setLanguageConverter( ILanguageConverter
$languageConverter ) {
67 $this->languageConverter
= $languageConverter;
71 * @note Call self::setLanguageConverter in your constructor when overriding
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
;
87 * Format the result as a simple link to the page
92 * @param stdClass $row Result row
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 ) );
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' );