9a8d7c8ce934bae933b36784de54590c8c212eef
[lhc/web/wiklou.git] / includes / specials / SpecialFewestrevisions.php
1 <?php
2 /**
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 /**
21 * Special page for listing the articles with the fewest revisions.
22 *
23 * @file
24 * @ingroup SpecialPage
25 * @author Martin Drashkov
26 */
27 class FewestrevisionsPage extends QueryPage {
28
29 function getName() {
30 return 'Fewestrevisions';
31 }
32
33 function isExpensive() {
34 return true;
35 }
36
37 function isSyndicated() {
38 return false;
39 }
40
41 function getSql() {
42 $dbr = wfGetDB( DB_SLAVE );
43 list( $revision, $page ) = $dbr->tableNamesN( 'revision', 'page' );
44
45 return "SELECT 'Fewestrevisions' as type,
46 page_namespace as namespace,
47 page_title as title,
48 page_is_redirect as redirect,
49 COUNT(*) as value
50 FROM $revision
51 JOIN $page ON page_id = rev_page
52 WHERE page_namespace = " . NS_MAIN . "
53 GROUP BY page_namespace, page_title, page_is_redirect
54 HAVING COUNT(*) > 1";
55 // ^^^ This was probably here to weed out redirects.
56 // Since we mark them as such now, it might be
57 // useful to remove this. People _do_ create pages
58 // and never revise them, they aren't necessarily
59 // redirects.
60 }
61
62 function sortDescending() {
63 return false;
64 }
65
66 function formatResult( $skin, $result ) {
67 global $wgLang, $wgContLang;
68
69 $nt = Title::makeTitleSafe( $result->namespace, $result->title );
70 if( !$nt ) {
71 return '<!-- bad title -->';
72 }
73
74 $text = $wgContLang->convert( $nt->getPrefixedText() );
75
76 $plink = $skin->linkKnown(
77 $nt,
78 $text
79 );
80
81 $nl = wfMsgExt( 'nrevisions', array( 'parsemag', 'escape' ),
82 $wgLang->formatNum( $result->value ) );
83 $redirect = $result->redirect ? ' - ' . wfMsgHtml( 'isredirect' ) : '';
84 $nlink = $skin->linkKnown(
85 $nt,
86 $nl,
87 array(),
88 array( 'action' => 'history' )
89 ) . $redirect;
90
91 return wfSpecialList( $plink, $nlink );
92 }
93 }
94
95 function wfSpecialFewestrevisions() {
96 list( $limit, $offset ) = wfCheckLimits();
97 $frp = new FewestrevisionsPage();
98 $frp->doQuery( $offset, $limit );
99 }