]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialShortpages.php
MediaWiki 1.16.1-scripts
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialShortpages.php
1 <?php
2 /**
3  * @file
4  * @ingroup SpecialPage
5  */
6
7 /**
8  * SpecialShortpages extends QueryPage. It is used to return the shortest
9  * pages in the database.
10  * @ingroup 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                 global $wgContentNamespaces;
31
32                 $dbr = wfGetDB( DB_SLAVE );
33                 $page = $dbr->tableName( 'page' );
34                 $name = $dbr->addQuotes( $this->getName() );
35
36                 $forceindex = $dbr->useIndexClause("page_len");
37
38                 if ($wgContentNamespaces)
39                         $nsclause = "page_namespace IN (" . $dbr->makeList($wgContentNamespaces) . ")";
40                 else
41                         $nsclause = "page_namespace = " . NS_MAIN;
42
43                 return
44                         "SELECT $name as type,
45                                 page_namespace as namespace,
46                                 page_title as title,
47                                 page_len AS value
48                         FROM $page $forceindex
49                         WHERE $nsclause AND page_is_redirect=0";
50         }
51
52         function preprocessResults( $db, $res ) {
53                 # There's no point doing a batch check if we aren't caching results;
54                 # the page must exist for it to have been pulled out of the table
55                 if( $this->isCached() ) {
56                         $batch = new LinkBatch();
57                         while( $row = $db->fetchObject( $res ) )
58                                 $batch->add( $row->namespace, $row->title );
59                         $batch->execute();
60                         if( $db->numRows( $res ) > 0 )
61                                 $db->dataSeek( $res, 0 );
62                 }
63         }
64
65         function sortDescending() {
66                 return false;
67         }
68
69         function formatResult( $skin, $result ) {
70                 global $wgLang, $wgContLang;
71                 $dm = $wgContLang->getDirMark();
72
73                 $title = Title::makeTitleSafe( $result->namespace, $result->title );
74                 if ( !$title ) {
75                         return '<!-- Invalid title ' .  htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
76                 }
77                 $hlink = $skin->linkKnown(
78                         $title,
79                         wfMsgHtml( 'hist' ),
80                         array(),
81                         array( 'action' => 'history' )
82                 );
83                 $plink = $this->isCached()
84                                         ? $skin->link( $title )
85                                         : $skin->linkKnown( $title );
86                 $size = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->value ) ) );
87
88                 return $title->exists()
89                                 ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
90                                 : "<s>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</s>";
91         }
92 }
93
94 /**
95  * constructor
96  */
97 function wfSpecialShortpages() {
98         list( $limit, $offset ) = wfCheckLimits();
99
100         $spp = new ShortPagesPage();
101
102         return $spp->doQuery( $offset, $limit );
103 }