Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
PageQueryPage | |
0.00% |
0 / 12 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setLanguageConverter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLanguageConverter | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
formatResult | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * Variant of QueryPage which formats the result as a simple link to the page. |
4 | * |
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. |
9 | * |
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. |
14 | * |
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 |
19 | * |
20 | * @file |
21 | * @ingroup SpecialPage |
22 | */ |
23 | |
24 | namespace MediaWiki\SpecialPage; |
25 | |
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; |
36 | |
37 | /** |
38 | * Variant of QueryPage which formats the result as a simple link to the page |
39 | * |
40 | * @stable to extend |
41 | * @ingroup SpecialPage |
42 | */ |
43 | abstract class PageQueryPage extends QueryPage { |
44 | |
45 | /** @var ILanguageConverter|null */ |
46 | private $languageConverter = null; |
47 | |
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. |
52 | * |
53 | * @stable to override |
54 | * |
55 | * @param IDatabase $db |
56 | * @param IResultWrapper $res |
57 | */ |
58 | public function preprocessResults( $db, $res ) { |
59 | $this->executeLBFromResultWrapper( $res ); |
60 | } |
61 | |
62 | /** |
63 | * @since 1.36 |
64 | * @param ILanguageConverter $languageConverter |
65 | */ |
66 | final protected function setLanguageConverter( ILanguageConverter $languageConverter ) { |
67 | $this->languageConverter = $languageConverter; |
68 | } |
69 | |
70 | /** |
71 | * @note Call self::setLanguageConverter in your constructor when overriding |
72 | * |
73 | * @since 1.36 |
74 | * @return ILanguageConverter |
75 | */ |
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 | } |
85 | |
86 | /** |
87 | * Format the result as a simple link to the page |
88 | * |
89 | * @stable to override |
90 | * |
91 | * @param Skin $skin |
92 | * @param stdClass $row Result row |
93 | * @return string |
94 | */ |
95 | public function formatResult( $skin, $row ) { |
96 | $title = Title::makeTitleSafe( $row->namespace, $row->title ); |
97 | if ( $title instanceof Title ) { |
98 | |
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 | } |
107 | |
108 | /** @deprecated class alias since 1.41 */ |
109 | class_alias( PageQueryPage::class, 'PageQueryPage' ); |