00001 <?php
00011 class PopularPagesPage extends QueryPage {
00012
00013 function getName() {
00014 return "Popularpages";
00015 }
00016
00017 function isExpensive() {
00018 # page_counter is not indexed
00019 return true;
00020 }
00021 function isSyndicated() { return false; }
00022
00023 function getSQL() {
00024 $dbr = wfGetDB( DB_SLAVE );
00025 $page = $dbr->tableName( 'page' );
00026
00027 $query =
00028 "SELECT 'Popularpages' as type,
00029 page_namespace as namespace,
00030 page_title as title,
00031 page_counter as value
00032 FROM $page ";
00033 $where =
00034 "WHERE page_is_redirect=0 AND page_namespace";
00035
00036 global $wgContentNamespaces;
00037 if( empty( $wgContentNamespaces ) ) {
00038 $where .= '='.NS_MAIN;
00039 } else if( count( $wgContentNamespaces ) > 1 ) {
00040 $where .= ' in (' . implode( ', ', $wgContentNamespaces ) . ')';
00041 } else {
00042 $where .= '='.$wgContentNamespaces[0];
00043 }
00044
00045 return $query . $where;
00046 }
00047
00048 function formatResult( $skin, $result ) {
00049 global $wgLang, $wgContLang;
00050 $title = Title::makeTitle( $result->namespace, $result->title );
00051 $link = $skin->makeKnownLinkObj( $title, htmlspecialchars( $wgContLang->convert( $title->getPrefixedText() ) ) );
00052 $nv = wfMsgExt( 'nviews', array( 'parsemag', 'escape'),
00053 $wgLang->formatNum( $result->value ) );
00054 return wfSpecialList($link, $nv);
00055 }
00056 }
00057
00061 function wfSpecialPopularpages() {
00062 list( $limit, $offset ) = wfCheckLimits();
00063
00064 $ppp = new PopularPagesPage();
00065
00066 return $ppp->doQuery( $offset, $limit );
00067 }