URL-encode the content-disposition suggested filename for XML export data.
[lhc/web/wiklou.git] / includes / SpecialPopularpages.php
index 628a528..af0ed26 100644 (file)
@@ -1,42 +1,69 @@
-<?
+<?php
+/**
+ *
+ * @addtogroup SpecialPage
+ */
 
-function wfSpecialPopularpages()
-{
-       global $wgUser, $wgOut, $wgLang, $wgTitle;
-       $fname = "wfSpecialPopularpages";
+/**
+ * implements Special:Popularpages
+ * @addtogroup SpecialPage
+ */
+class PopularPagesPage extends QueryPage {
 
-       global $wgMiserMode;
-       if ( $wgMiserMode ) {
-               $wgOut->addWikiText( wfMsg( "perfdisabled" ) );
-               return;
+       function getName() {
+               return "Popularpages";
        }
 
-       list( $limit, $offset ) = wfCheckLimits();
+       function isExpensive() {
+               # page_counter is not indexed
+               return true;
+       }
+       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 = wfMsg( "nviews", $obj->cur_counter );
-               $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 );
+}
+
+