-<?
-
-function wfSpecialPopularpages()
-{
- global $wgUser, $wgOut, $wgLang, $wgTitle;
- global $limit, $offset; # From query string
- $fname = "wfSpecialPopularpages";
-
- global $wgMiserMode;
- if ( $wgMiserMode ) {
- $wgOut->addWikiText( wfMsg( "perfdisabled" ) );
- return;
+<?php
+/**
+ *
+ * @addtogroup SpecialPage
+ */
+
+/**
+ * implements Special:Popularpages
+ * @addtogroup SpecialPage
+ */
+class PopularPagesPage extends QueryPage {
+
+ function getName() {
+ return "Popularpages";
}
- if ( ! $limit ) {
- $limit = $wgUser->getOption( "rclimit" );
- if ( ! $limit ) { $limit = 50; }
+ function isExpensive() {
+ # page_counter is not indexed
+ return true;
}
- if ( ! $offset ) { $offset = 0; }
+ function isSyndicated() { return false; }
- $sql = "SELECT DISTINCT cur_title, cur_counter FROM cur " .
- "WHERE cur_namespace=0 AND cur_is_redirect=0 ORDER BY " .
- "cur_counter DESC LIMIT {$offset}, {$limit}";
- $res = wfQuery( $sql, $fname );
+ function getSQL() {
+ $dbr = wfGetDB( DB_SLAVE );
+ $page = $dbr->tableName( 'page' );
- $sk = $wgUser->getSkin();
+ $query =
+ "SELECT 'Popularpages' as type,
+ page_namespace as namespace,
+ page_title as title,
+ page_counter as value
+ FROM $page ";
+ $where =
+ "WHERE page_is_redirect=0 AND page_namespace";
- $top = wfShowingResults( $offset, $limit );
- $wgOut->addHTML( "<p>{$top}\n" );
+ global $wgContentNamespaces;
+ if( empty( $wgContentNamespaces ) ) {
+ $where .= '='.NS_MAIN;
+ } else if( count( $wgContentNamespaces ) > 1 ) {
+ $where .= ' in (' . implode( ', ', $wgContentNamespaces ) . ')';
+ } else {
+ $where .= '='.$wgContentNamespaces[0];
+ }
- $sl = wfViewPrevNext( $offset, $limit,
- $wgLang->specialPage( "Popularpages" ) );
- $wgOut->addHTML( "<br>{$sl}\n" );
+ return $query . $where;
+ }
- $s = "<ol start=" . ( $offset + 1 ) . ">";
- while ( $obj = wfFetchObject( $res ) ) {
- $nv = str_replace( "$1", $obj->cur_counter, wfMsg( "nviews" ) );
- $link = $sk->makeKnownLink( $obj->cur_title, "" );
- $s .= "<li>{$link} ({$nv})</li>\n";
+ function formatResult( $skin, $result ) {
+ global $wgLang, $wgContLang;
+ $title = Title::makeTitle( $result->namespace, $result->title );
+ $link = $skin->makeKnownLinkObj( $title, htmlspecialchars( $wgContLang->convert( $title->getPrefixedText() ) ) );
+ $nv = wfMsgExt( 'nviews', array( 'parsemag', 'escape'),
+ $wgLang->formatNum( $result->value ) );
+ return wfSpecialList($link, $nv);
}
- wfFreeResult( $res );
- $s .= "</ol>";
- $wgOut->addHTML( $s );
- $wgOut->addHTML( "<p>{$sl}\n" );
}
-?>
+/**
+ * Constructor
+ */
+function wfSpecialPopularpages() {
+ list( $limit, $offset ) = wfCheckLimits();
+
+ $ppp = new PopularPagesPage();
+
+ return $ppp->doQuery( $offset, $limit );
+}
+
+