Coding style
[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 getName() {
33 return 'Shortpages';
34 }
35
36 /**
37 * This query is indexed as of 1.5
38 */
39 function isExpensive() {
40 return true;
41 }
42
43 function isSyndicated() {
44 return false;
45 }
46
47 function getSQL() {
48 global $wgContentNamespaces;
49
50 $dbr = wfGetDB( DB_SLAVE );
51 $page = $dbr->tableName( 'page' );
52 $name = $dbr->addQuotes( $this->getName() );
53
54 $forceindex = $dbr->useIndexClause("page_len");
55
56 if ($wgContentNamespaces)
57 $nsclause = "page_namespace IN (" . $dbr->makeList($wgContentNamespaces) . ")";
58 else
59 $nsclause = "page_namespace = " . NS_MAIN;
60
61 return
62 "SELECT $name as type,
63 page_namespace as namespace,
64 page_title as title,
65 page_len AS value
66 FROM $page $forceindex
67 WHERE $nsclause AND page_is_redirect=0";
68 }
69
70 function preprocessResults( $db, $res ) {
71 # There's no point doing a batch check if we aren't caching results;
72 # the page must exist for it to have been pulled out of the table
73 if( $this->isCached() ) {
74 $batch = new LinkBatch();
75 foreach ( $res as $row ) {
76 $batch->add( $row->namespace, $row->title );
77 }
78 $batch->execute();
79 if ( $db->numRows( $res ) > 0 ) {
80 $db->dataSeek( $res, 0 );
81 }
82 }
83 }
84
85 function sortDescending() {
86 return false;
87 }
88
89 function formatResult( $skin, $result ) {
90 global $wgLang, $wgContLang;
91 $dm = $wgContLang->getDirMark();
92
93 $title = Title::makeTitleSafe( $result->namespace, $result->title );
94 if ( !$title ) {
95 return '<!-- Invalid title ' . htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
96 }
97 $hlink = $skin->linkKnown(
98 $title,
99 wfMsgHtml( 'hist' ),
100 array(),
101 array( 'action' => 'history' )
102 );
103 $plink = $this->isCached()
104 ? $skin->link( $title )
105 : $skin->linkKnown( $title );
106 $size = wfMessage( 'nbytes', $wgLang->formatNum( $result->value ) )->escaped();
107
108 return $title->exists()
109 ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
110 : "<del>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</del>";
111 }
112 }
113
114 /**
115 * constructor
116 */
117 function wfSpecialShortpages() {
118 list( $limit, $offset ) = wfCheckLimits();
119
120 $spp = new ShortPagesPage();
121
122 return $spp->doQuery( $offset, $limit );
123 }