Remove double escaping
[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 while( $row = $db->fetchObject( $res ) )
76 $batch->add( $row->namespace, $row->title );
77 $batch->execute();
78 if( $db->numRows( $res ) > 0 )
79 $db->dataSeek( $res, 0 );
80 }
81 }
82
83 function sortDescending() {
84 return false;
85 }
86
87 function formatResult( $skin, $result ) {
88 global $wgLang, $wgContLang;
89 $dm = $wgContLang->getDirMark();
90
91 $title = Title::makeTitleSafe( $result->namespace, $result->title );
92 if ( !$title ) {
93 return '<!-- Invalid title ' . htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
94 }
95 $hlink = $skin->linkKnown(
96 $title,
97 wfMsgHtml( 'hist' ),
98 array(),
99 array( 'action' => 'history' )
100 );
101 $plink = $this->isCached()
102 ? $skin->link( $title )
103 : $skin->linkKnown( $title );
104 $size = wfMessage( 'nbytes', $wgLang->formatNum( $result->value ) )->escaped();
105
106 return $title->exists()
107 ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
108 : "<del>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</del>";
109 }
110 }
111
112 /**
113 * constructor
114 */
115 function wfSpecialShortpages() {
116 list( $limit, $offset ) = wfCheckLimits();
117
118 $spp = new ShortPagesPage();
119
120 return $spp->doQuery( $offset, $limit );
121 }