]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/SpecialPopularpages.php
MediaWiki 1.11.0
[autoinstalls/mediawiki.git] / includes / SpecialPopularpages.php
1 <?php
2 /**
3  *
4  * @addtogroup SpecialPage
5  */
6
7 /**
8  * implements Special:Popularpages
9  * @addtogroup SpecialPage
10  */
11 class PopularPagesPage extends QueryPage {
12
13         function getName() {
14                 return "Popularpages";
15         }
16
17         function isExpensive() {
18                 # page_counter is not indexed
19                 return true;
20         }
21         function isSyndicated() { return false; }
22
23         function getSQL() {
24                 $dbr = wfGetDB( DB_SLAVE );
25                 $page = $dbr->tableName( 'page' );
26
27                 $query = 
28                         "SELECT 'Popularpages' as type,
29                                 page_namespace as namespace,
30                                 page_title as title,
31                                 page_counter as value
32                         FROM $page ";
33                 $where =
34                         "WHERE page_is_redirect=0 AND page_namespace";
35
36                 global $wgContentNamespaces;
37                 if( empty( $wgContentNamespaces ) ) {
38                         $where .= '='.NS_MAIN;
39                 } else if( count( $wgContentNamespaces ) > 1 ) {
40                         $where .= ' in (' . implode( ', ', $wgContentNamespaces ) . ')';
41                 } else {
42                         $where .= '='.$wgContentNamespaces[0];
43                 }
44
45                 return $query . $where;
46         }
47
48         function formatResult( $skin, $result ) {
49                 global $wgLang, $wgContLang;
50                 $title = Title::makeTitle( $result->namespace, $result->title );
51                 $link = $skin->makeKnownLinkObj( $title, htmlspecialchars( $wgContLang->convert( $title->getPrefixedText() ) ) );
52                 $nv = wfMsgExt( 'nviews', array( 'parsemag', 'escape'),
53                         $wgLang->formatNum( $result->value ) );
54                 return wfSpecialList($link, $nv);
55         }
56 }
57
58 /**
59  * Constructor
60  */
61 function wfSpecialPopularpages() {
62         list( $limit, $offset ) = wfCheckLimits();
63
64         $ppp = new PopularPagesPage();
65
66         return $ppp->doQuery( $offset, $limit );
67 }
68
69