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