Debian Codegraph @

includes/specials/SpecialFewestRevisions.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Specials;
22
23 use HtmlArmor;
24 use MediaWiki\Cache\LinkBatchFactory;
25 use MediaWiki\Html\Html;
26 use MediaWiki\Language\ILanguageConverter;
27 use MediaWiki\Languages\LanguageConverterFactory;
28 use MediaWiki\Linker\Linker;
29 use MediaWiki\SpecialPage\QueryPage;
30 use MediaWiki\Title\NamespaceInfo;
31 use MediaWiki\Title\Title;
32 use Skin;
33 use stdClass;
34 use Wikimedia\Rdbms\IConnectionProvider;
35 use Wikimedia\Rdbms\IDatabase;
36 use Wikimedia\Rdbms\IResultWrapper;
37
38 /**
39 * List articles with the fewest revisions.
40 *
41 * @ingroup SpecialPage
42 * @author Martin Drashkov
43 */
44 class SpecialFewestRevisions extends QueryPage {
45
46 private NamespaceInfo $namespaceInfo;
47 private ILanguageConverter $languageConverter;
48
49 /**
50 * @param NamespaceInfo $namespaceInfo
51 * @param IConnectionProvider $dbProvider
52 * @param LinkBatchFactory $linkBatchFactory
53 * @param LanguageConverterFactory $languageConverterFactory
54 */
55 public function __construct(
56 NamespaceInfo $namespaceInfo,
57 IConnectionProvider $dbProvider,
58 LinkBatchFactory $linkBatchFactory,
59 LanguageConverterFactory $languageConverterFactory
60 ) {
61 parent::__construct( 'Fewestrevisions' );
62 $this->namespaceInfo = $namespaceInfo;
63 $this->setDatabaseProvider( $dbProvider );
64 $this->setLinkBatchFactory( $linkBatchFactory );
65 $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() );
66 }
67
68 public function isExpensive() {
69 return true;
70 }
71
72 public function isSyndicated() {
73 return false;
74 }
75
76 public function getQueryInfo() {
77 return [
78 'tables' => [ 'revision', 'page' ],
79 'fields' => [
80 'namespace' => 'page_namespace',
81 'title' => 'page_title',
82 'value' => 'COUNT(*)',
83 ],
84 'conds' => [
85 'page_namespace' => $this->namespaceInfo->getContentNamespaces(),
86 'page_id = rev_page',
87 'page_is_redirect' => 0,
88 ],
89 'options' => [
90 'GROUP BY' => [ 'page_namespace', 'page_title' ]
91 ]
92 ];
93 }
94
95 protected function sortDescending() {
96 return false;
97 }
98
99 /**
100 * @param Skin $skin
101 * @param stdClass $result Database row
102 * @return string
103 */
104 public function formatResult( $skin, $result ) {
105 $nt = Title::makeTitleSafe( $result->namespace, $result->title );
106 if ( !$nt ) {
107 return Html::element(
108 'span',
109 [ 'class' => 'mw-invalidtitle' ],
110 Linker::getInvalidTitleDescription(
111 $this->getContext(),
112 $result->namespace,
113 $result->title
114 )
115 );
116 }
117 $linkRenderer = $this->getLinkRenderer();
118
119 $text = $this->languageConverter->convertHtml( $nt->getPrefixedText() );
120 $plink = $linkRenderer->makeLink( $nt, new HtmlArmor( $text ) );
121
122 $nl = $this->msg( 'nrevisions' )->numParams( $result->value )->text();
123 $redirect = isset( $result->redirect ) && $result->redirect ?
124 ' - ' . $this->msg( 'isredirect' )->escaped() : '';
125 $nlink = $linkRenderer->makeKnownLink(
126 $nt,
127 $nl,
128 [],
129 [ 'action' => 'history' ]
130 ) . $redirect;
131
132 return $this->getLanguage()->specialList( $plink, $nlink );
133 }
134
135 /**
136 * Cache page existence for performance
137 *
138 * @param IDatabase $db
139 * @param IResultWrapper $res
140 */
141 protected function preprocessResults( $db, $res ) {
142 $this->executeLBFromResultWrapper( $res );
143 }
144
145 protected function getGroupName() {
146 return 'maintenance';
147 }
148 }
149
150 /** @deprecated class alias since 1.41 */
151 class_alias( SpecialFewestRevisions::class, 'SpecialFewestRevisions' );