Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
SpecialFewestRevisions | |
0.00% |
0 / 50 |
|
0.00% |
0 / 8 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
isExpensive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isSyndicated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
sortDescending | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
formatResult | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
20 | |||
preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Implements Special:Fewestrevisions |
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\Specials; |
25 | |
26 | use HtmlArmor; |
27 | use ILanguageConverter; |
28 | use MediaWiki\Cache\LinkBatchFactory; |
29 | use MediaWiki\Html\Html; |
30 | use MediaWiki\Languages\LanguageConverterFactory; |
31 | use MediaWiki\Linker\Linker; |
32 | use MediaWiki\SpecialPage\QueryPage; |
33 | use MediaWiki\Title\NamespaceInfo; |
34 | use MediaWiki\Title\Title; |
35 | use Skin; |
36 | use stdClass; |
37 | use Wikimedia\Rdbms\IConnectionProvider; |
38 | use Wikimedia\Rdbms\IDatabase; |
39 | use Wikimedia\Rdbms\IResultWrapper; |
40 | |
41 | /** |
42 | * Special page for listing the articles with the fewest revisions. |
43 | * |
44 | * @ingroup SpecialPage |
45 | * @author Martin Drashkov |
46 | */ |
47 | class SpecialFewestRevisions extends QueryPage { |
48 | |
49 | private NamespaceInfo $namespaceInfo; |
50 | private ILanguageConverter $languageConverter; |
51 | |
52 | /** |
53 | * @param NamespaceInfo $namespaceInfo |
54 | * @param IConnectionProvider $dbProvider |
55 | * @param LinkBatchFactory $linkBatchFactory |
56 | * @param LanguageConverterFactory $languageConverterFactory |
57 | */ |
58 | public function __construct( |
59 | NamespaceInfo $namespaceInfo, |
60 | IConnectionProvider $dbProvider, |
61 | LinkBatchFactory $linkBatchFactory, |
62 | LanguageConverterFactory $languageConverterFactory |
63 | ) { |
64 | parent::__construct( 'Fewestrevisions' ); |
65 | $this->namespaceInfo = $namespaceInfo; |
66 | $this->setDatabaseProvider( $dbProvider ); |
67 | $this->setLinkBatchFactory( $linkBatchFactory ); |
68 | $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() ); |
69 | } |
70 | |
71 | public function isExpensive() { |
72 | return true; |
73 | } |
74 | |
75 | public function isSyndicated() { |
76 | return false; |
77 | } |
78 | |
79 | public function getQueryInfo() { |
80 | return [ |
81 | 'tables' => [ 'revision', 'page' ], |
82 | 'fields' => [ |
83 | 'namespace' => 'page_namespace', |
84 | 'title' => 'page_title', |
85 | 'value' => 'COUNT(*)', |
86 | ], |
87 | 'conds' => [ |
88 | 'page_namespace' => $this->namespaceInfo->getContentNamespaces(), |
89 | 'page_id = rev_page', |
90 | 'page_is_redirect = 0', |
91 | ], |
92 | 'options' => [ |
93 | 'GROUP BY' => [ 'page_namespace', 'page_title' ] |
94 | ] |
95 | ]; |
96 | } |
97 | |
98 | protected function sortDescending() { |
99 | return false; |
100 | } |
101 | |
102 | /** |
103 | * @param Skin $skin |
104 | * @param stdClass $result Database row |
105 | * @return string |
106 | */ |
107 | public function formatResult( $skin, $result ) { |
108 | $nt = Title::makeTitleSafe( $result->namespace, $result->title ); |
109 | if ( !$nt ) { |
110 | return Html::element( |
111 | 'span', |
112 | [ 'class' => 'mw-invalidtitle' ], |
113 | Linker::getInvalidTitleDescription( |
114 | $this->getContext(), |
115 | $result->namespace, |
116 | $result->title |
117 | ) |
118 | ); |
119 | } |
120 | $linkRenderer = $this->getLinkRenderer(); |
121 | |
122 | $text = $this->languageConverter->convertHtml( $nt->getPrefixedText() ); |
123 | $plink = $linkRenderer->makeLink( $nt, new HtmlArmor( $text ) ); |
124 | |
125 | $nl = $this->msg( 'nrevisions' )->numParams( $result->value )->text(); |
126 | $redirect = isset( $result->redirect ) && $result->redirect ? |
127 | ' - ' . $this->msg( 'isredirect' )->escaped() : ''; |
128 | $nlink = $linkRenderer->makeKnownLink( |
129 | $nt, |
130 | $nl, |
131 | [], |
132 | [ 'action' => 'history' ] |
133 | ) . $redirect; |
134 | |
135 | return $this->getLanguage()->specialList( $plink, $nlink ); |
136 | } |
137 | |
138 | /** |
139 | * Cache page existence for performance |
140 | * |
141 | * @param IDatabase $db |
142 | * @param IResultWrapper $res |
143 | */ |
144 | protected function preprocessResults( $db, $res ) { |
145 | $this->executeLBFromResultWrapper( $res ); |
146 | } |
147 | |
148 | protected function getGroupName() { |
149 | return 'maintenance'; |
150 | } |
151 | } |
152 | |
153 | /** @deprecated class alias since 1.41 */ |
154 | class_alias( SpecialFewestRevisions::class, 'SpecialFewestRevisions' ); |