Refactored parser output handling slightly, and added a hook function, to allow exten...
[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 $hlink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
69 $plink = $this->isCached()
70 ? $skin->makeLinkObj( $title )
71 : $skin->makeKnownLinkObj( $title );
72 $size = wfMsgHtml( 'nbytes', $wgLang->formatNum( htmlspecialchars( $result->value ) ) );
73
74 return $title->exists()
75 ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
76 : "<s>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</s>";
77 }
78 }
79
80 /**
81 * constructor
82 */
83 function wfSpecialShortpages() {
84 list( $limit, $offset ) = wfCheckLimits();
85
86 $spp = new ShortPagesPage();
87
88 return $spp->doQuery( $offset, $limit );
89 }
90
91 ?>