-<?
-
-function wfSpecialPopularpages()
-{
- global $wgUser, $wgOut, $wgLang, $wgTitle;
- $fname = "wfSpecialPopularpages";
-
- global $wgMiserMode;
- if ( $wgMiserMode ) {
- $wgOut->addWikiText( wfMsg( "perfdisabled" ) );
- return;
+<?php
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+class PopularPagesPage extends QueryPage {
+
+ function getName() {
+ return "Popularpages";
}
- list( $limit, $offset ) = wfCheckLimits();
-
- $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, DB_READ, $fname );
+ function isExpensive() {
+ # page_counter is not indexed
+ return true;
+ }
+ function isSyndicated() { return false; }
+
+ function getSQL() {
+ $dbr =& wfGetDB( DB_SLAVE );
+ $page = $dbr->tableName( 'page' );
+
+ return
+ "SELECT 'Popularpages' as type,
+ page_namespace as namespace,
+ page_title as title,
+ page_counter as value
+ FROM $page
+ WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0";
+ }
- $sk = $wgUser->getSkin();
+ function formatResult( $result ) {
+ global $wgLang, $wgContLang;
+ $title = Title::makeTitle( $result->namespace, $result->title );
+ $link = Linker::makeKnownLinkObj( $title, htmlspecialchars( $wgContLang->convert( $title->getPrefixedText() ) ) );
+ $nv = wfMsgExt( 'nviews', array( 'parsemag', 'escape'),
+ $wgLang->formatNum( $result->value ) );
+ return wfSpecialList($link, $nv);
+ }
+}
- $top = wfShowingResults( $offset, $limit );
- $wgOut->addHTML( "<p>{$top}\n" );
+/**
+ * Constructor
+ */
+function wfSpecialPopularpages() {
+ list( $limit, $offset ) = wfCheckLimits();
- $sl = wfViewPrevNext( $offset, $limit,
- $wgLang->specialPage( "Popularpages" ) );
- $wgOut->addHTML( "<br>{$sl}\n" );
+ $ppp = new PopularPagesPage();
- $s = "<ol start=" . ( $offset + 1 ) . ">";
- while ( $obj = wfFetchObject( $res ) ) {
- $nv = wfMsg( "nviews", $obj->cur_counter );
- $link = $sk->makeKnownLink( $obj->cur_title, "" );
- $s .= "<li>{$link} ({$nv})</li>\n";
- }
- wfFreeResult( $res );
- $s .= "</ol>";
- $wgOut->addHTML( $s );
- $wgOut->addHTML( "<p>{$sl}\n" );
+ return $ppp->doQuery( $offset, $limit );
}
?>