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->linkKnown( 00052 $title, 00053 htmlspecialchars( $wgContLang->convert( $title->getPrefixedText() ) ) 00054 ); 00055 $nv = wfMsgExt( 00056 'nviews', 00057 array( 'parsemag', 'escape'), 00058 $wgLang->formatNum( $result->value ) 00059 ); 00060 return wfSpecialList($link, $nv); 00061 } 00062 } 00063 00067 function wfSpecialPopularpages() { 00068 list( $limit, $offset ) = wfCheckLimits(); 00069 00070 $ppp = new PopularPagesPage(); 00071 00072 return $ppp->doQuery( $offset, $limit ); 00073 }