Fix some bad "Implements Special:*" comments in includes/specials/ files.
[lhc/web/wiklou.git] / includes / specials / SpecialShortpages.php
1 <?php
2 /**
3 * Implements Special:Shortpages
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 * SpecialShortpages extends QueryPage. It is used to return the shortest
26 * pages in the database.
27 *
28 * @ingroup SpecialPage
29 */
30 class ShortPagesPage extends QueryPage {
31
32 function __construct( $name = 'Shortpages' ) {
33 parent::__construct( $name );
34 }
35
36 // inexpensive?
37 /**
38 * This query is indexed as of 1.5
39 */
40 function isExpensive() {
41 return true;
42 }
43
44 function isSyndicated() {
45 return false;
46 }
47
48 function getQueryInfo() {
49 return array (
50 'tables' => array ( 'page' ),
51 'fields' => array ( 'page_namespace AS namespace',
52 'page_title AS title',
53 'page_len AS value' ),
54 'conds' => array ( 'page_namespace' => MWNamespace::getContentNamespaces(),
55 'page_is_redirect' => 0 ),
56 'options' => array ( 'USE INDEX' => 'page_len' )
57 );
58 }
59
60 function getOrderFields() {
61 return array( 'page_len' );
62 }
63
64 /**
65 * @param $db DatabaseBase
66 * @param $res
67 * @return void
68 */
69 function preprocessResults( $db, $res ) {
70 # There's no point doing a batch check if we aren't caching results;
71 # the page must exist for it to have been pulled out of the table
72 if( $this->isCached() ) {
73 $batch = new LinkBatch();
74 foreach ( $res as $row ) {
75 $batch->add( $row->namespace, $row->title );
76 }
77 $batch->execute();
78 if ( $db->numRows( $res ) > 0 ) {
79 $db->dataSeek( $res, 0 );
80 }
81 }
82 }
83
84 function sortDescending() {
85 return false;
86 }
87
88 function formatResult( $skin, $result ) {
89 global $wgLang;
90 $dm = $wgLang->getDirMark();
91
92 $title = Title::makeTitle( $result->namespace, $result->title );
93 if ( !$title ) {
94 return '<!-- Invalid title ' . htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
95 }
96 $hlink = $skin->linkKnown(
97 $title,
98 wfMsgHtml( 'hist' ),
99 array(),
100 array( 'action' => 'history' )
101 );
102 $plink = $this->isCached()
103 ? $skin->link( $title )
104 : $skin->linkKnown( $title );
105 $size = wfMessage( 'nbytes', $wgLang->formatNum( $result->value ) )->escaped();
106
107 return $title->exists()
108 ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
109 : "<del>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</del>";
110 }
111 }