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