Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[lhc/web/wiklou.git] / includes / specials / SpecialFewestrevisions.php
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 use MediaWiki\MediaWikiServices;
25
26 /**
27 * Special page for listing the articles with the fewest revisions.
28 *
29 * @ingroup SpecialPage
30 * @author Martin Drashkov
31 */
32 class FewestrevisionsPage extends QueryPage {
33 function __construct( $name = 'Fewestrevisions' ) {
34 parent::__construct( $name );
35 }
36
37 public function isExpensive() {
38 return true;
39 }
40
41 function isSyndicated() {
42 return false;
43 }
44
45 public function getQueryInfo() {
46 return [
47 'tables' => [ 'revision', 'page' ],
48 'fields' => [
49 'namespace' => 'page_namespace',
50 'title' => 'page_title',
51 'value' => 'COUNT(*)',
52 'redirect' => 'page_is_redirect'
53 ],
54 'conds' => [
55 'page_namespace' => MediaWikiServices::getInstance()->getNamespaceInfo()->
56 getContentNamespaces(),
57 'page_id = rev_page' ],
58 'options' => [
59 'GROUP BY' => [ 'page_namespace', 'page_title', 'page_is_redirect' ]
60 ]
61 ];
62 }
63
64 function sortDescending() {
65 return false;
66 }
67
68 /**
69 * @param Skin $skin
70 * @param object $result Database row
71 * @return string
72 */
73 function formatResult( $skin, $result ) {
74 $nt = Title::makeTitleSafe( $result->namespace, $result->title );
75 if ( !$nt ) {
76 return Html::element(
77 'span',
78 [ 'class' => 'mw-invalidtitle' ],
79 Linker::getInvalidTitleDescription(
80 $this->getContext(),
81 $result->namespace,
82 $result->title
83 )
84 );
85 }
86 $linkRenderer = $this->getLinkRenderer();
87 $text = MediaWikiServices::getInstance()->getContentLanguage()->
88 convert( htmlspecialchars( $nt->getPrefixedText() ) );
89 $plink = $linkRenderer->makeLink( $nt, new HtmlArmor( $text ) );
90
91 $nl = $this->msg( 'nrevisions' )->numParams( $result->value )->text();
92 $redirect = isset( $result->redirect ) && $result->redirect ?
93 ' - ' . $this->msg( 'isredirect' )->escaped() : '';
94 $nlink = $linkRenderer->makeKnownLink(
95 $nt,
96 $nl,
97 [],
98 [ 'action' => 'history' ]
99 ) . $redirect;
100
101 return $this->getLanguage()->specialList( $plink, $nlink );
102 }
103
104 protected function getGroupName() {
105 return 'maintenance';
106 }
107 }