Committed a bunch of live hacks from Wikimedia servers
[lhc/web/wiklou.git] / includes / SpecialShortpages.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * SpecialShortpages extends QueryPage. It is used to return the shortest
10 * pages in the database.
11 * @package MediaWiki
12 * @subpackage SpecialPage
13 */
14 class ShortPagesPage extends QueryPage {
15
16 function getName() {
17 return "Shortpages";
18 }
19
20 /**
21 * This query is indexed as of 1.5
22 */
23 function isExpensive() {
24 return true;
25 }
26
27 function isSyndicated() {
28 return false;
29 }
30
31 function getSQL() {
32 $dbr =& wfGetDB( DB_SLAVE );
33 $page = $dbr->tableName( 'page' );
34 $name = $dbr->addQuotes( $this->getName() );
35
36 $forceindex = $dbr->useIndexClause("page_len");
37 return
38 "SELECT $name as type,
39 page_namespace as namespace,
40 page_title as title,
41 page_len AS value
42 FROM $page $forceindex
43 WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0";
44 }
45
46 function preprocessResults( &$dbo, $res ) {
47 # There's no point doing a batch check if we aren't caching results;
48 # the page must exist for it to have been pulled out of the table
49 if( $this->isCached() ) {
50 $batch = new LinkBatch();
51 while( $row = $dbo->fetchObject( $res ) )
52 $batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
53 $batch->execute();
54 if( $dbo->numRows( $res ) > 0 )
55 $dbo->dataSeek( $res, 0 );
56 }
57 }
58
59 function sortDescending() {
60 return false;
61 }
62
63 function formatResult( $skin, $result ) {
64 global $wgLang, $wgContLang;
65 $dm = $wgContLang->getDirMark();
66
67 $title = Title::makeTitleSafe( $result->namespace, $result->title );
68 if ( !$title ) {
69 return '<!-- Invalid title ' . htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
70 }
71 $hlink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
72 $plink = $this->isCached()
73 ? $skin->makeLinkObj( $title )
74 : $skin->makeKnownLinkObj( $title );
75 $size = wfMsgHtml( 'nbytes', $wgLang->formatNum( htmlspecialchars( $result->value ) ) );
76
77 return $title->exists()
78 ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
79 : "<s>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</s>";
80 }
81 }
82
83 /**
84 * constructor
85 */
86 function wfSpecialShortpages() {
87 list( $limit, $offset ) = wfCheckLimits();
88
89 $spp = new ShortPagesPage();
90
91 return $spp->doQuery( $offset, $limit );
92 }
93
94 ?>