Ability to declare all query pages "expensive"
authorTim Starling <tstarling@users.mediawiki.org>
Sun, 25 Jan 2004 02:27:49 +0000 (02:27 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sun, 25 Jan 2004 02:27:49 +0000 (02:27 +0000)
includes/QueryPage.php
includes/SpecialAncientpages.php
includes/SpecialLongpages.php
includes/SpecialNewpages.php
includes/SpecialPopularpages.php
includes/SpecialShortpages.php
includes/SpecialWantedpages.php

index cbb9e7e..0195333 100644 (file)
@@ -7,90 +7,86 @@ include_once ( "LogPage.php" ) ;
 # subclasses derive from it.
 
 class QueryPage {
+       # Subclasses return their name here. Make sure the name is also
+       # specified in Language.php, both in the $wgValidSpecialPagesEn
+       # variable, and as a language message param.
 
-    # Subclasses return their name here. Make sure the name is also
-    # specified in Language.php, both in the $wgValidSpecialPagesEn
-    # variable, and as a language message param.
-    
-    function getName() {
-       return "";
-    }
-
-    # Subclasses return a SQL query here.
-    
-    function getSQL( $offset, $limit ) {
-       return "";
-    }
-
-    # Is this query expensive (for some definition of expensive)? Then we
-    # don't let it run in miser mode. The default is 0. Expensive
-    # subqueries should override this.
-    
-    function isExpensive( ) {
-       return 0;
-    }
-    
-    # Formats the results of the query for display. The skin is the current
-    # skin; you can use it for making links. The result is a single row of
-    # result data. You should be able to grab SQL results off of it.
-    
-    function formatResult( $skin, $result ) {
-       return "";
-    }
-
-    # This is the actual workhorse. It does everything needed to make a
-    # real, honest-to-gosh query page.
-    
-    function doQuery( $offset, $limit ) {
-       
-       global $wgUser, $wgOut, $wgLang, $wgMiserMode;
-
-       $sname = $this->getName();
-       $fname = get_class($this) . "::doQuery";
-       
-       if ( $this->isExpensive( ) ) {
-           
-           $vsp = $wgLang->getValidSpecialPages();
-           $logpage = new LogPage( $vsp[$sname] );
-           $logpage->mUpdateRecentChanges = false;
-           
-           if ( $wgMiserMode ) {
-               $logpage->showAsDisabledPage();
-               return;
-           }
+       function getName() {
+               return "";
        }
 
-       $sql = $this->getSQL( $offset, $limit+1 );
+       # Subclasses return a SQL query here.
 
-       $res = wfQuery( $sql, DB_READ, $fname );
-
-       $sk = $wgUser->getSkin( );
+       function getSQL( $offset, $limit ) {
+               return "";
+       }
 
-       $top = wfShowingResults( $offset, $limit );
-       $wgOut->addHTML( "<p>{$top}\n" );
+       # Is this query expensive (for some definition of expensive)? Then we
+       # don't let it run in miser mode. $wgDisableQueryPages causes all query
+       # pages to be declared expensive. Some query pages are always expensive.
+       function isExpensive( ) {
+               global $wgDisableQueryPages;
+               return $wgDisableQueryPages;
+       }
 
-       $sl = wfViewPrevNext( $offset, $limit, $wgLang->specialPage( $sname ), "",
-                               wfNumRows( $res ) < ($limit+1) );
-       $wgOut->addHTML( "<br>{$sl}\n" );
+       # Formats the results of the query for display. The skin is the current
+       # skin; you can use it for making links. The result is a single row of
+       # result data. You should be able to grab SQL results off of it.
 
-       $s = "<ol start=" . ( $offset + 1 ) . ">";
-       $i = 0;
-       while ( ($i<$limit) && ($obj = wfFetchObject( $res )) ) {
-           $format = $this->formatResult( $sk, $obj );
-           $s .= "<li>{$format}</li>\n";
-           $i++;
+       function formatResult( $skin, $result ) {
+               return "";
        }
-       wfFreeResult( $res );
-       $s .= "</ol>";
-       $wgOut->addHTML( $s );
-       $wgOut->addHTML( "<p>{$sl}\n" );
-
-       # Saving cache
-       
-       if ( $this->isExpensive() && $offset == 0 && $limit >= 50 ) {
-           $logpage->replaceContent( $s );
+
+       # This is the actual workhorse. It does everything needed to make a
+       # real, honest-to-gosh query page.
+
+       function doQuery( $offset, $limit ) {
+
+               global $wgUser, $wgOut, $wgLang, $wgMiserMode;
+
+               $sname = $this->getName();
+               $fname = get_class($this) . "::doQuery";
+
+               if ( $this->isExpensive( ) ) {
+
+                       $vsp = $wgLang->getValidSpecialPages();
+                       $logpage = new LogPage( "!" . $vsp[$sname] );
+                       $logpage->mUpdateRecentChanges = false;
+
+                       if ( $wgMiserMode ) {
+                               $logpage->showAsDisabledPage();
+                               return;
+                       }
+               }
+
+               $sql = $this->getSQL( $offset, $limit );
+
+               $res = wfQuery( $sql, DB_READ, $fname );
+
+               $sk = $wgUser->getSkin( );
+
+               $top = wfShowingResults( $offset, $limit );
+               $wgOut->addHTML( "<p>{$top}\n" );
+
+               $sl = wfViewPrevNext( $offset, $limit, $wgLang->specialPage( $sname ) );
+               $wgOut->addHTML( "<br>{$sl}\n" );
+
+               $s = "<ol start=" . ( $offset + 1 ) . ">";
+               while ( $obj = wfFetchObject( $res ) ) {
+                       $format = $this->formatResult( $sk, $obj );
+                       $s .= "<li>{$format}</li>\n";
+               }
+               wfFreeResult( $res );
+               $s .= "</ol>";
+               $wgOut->addHTML( $s );
+               $wgOut->addHTML( "<p>{$sl}\n" );
+
+               # Saving cache
+
+               if ( $this->isExpensive() && $offset == 0 && $limit >= 50 ) {
+                       $logpage->replaceContent( $s );
+               }
        }
-    }
 }
 
 # This is a subclass for very simple queries that are just looking for page
@@ -99,9 +95,9 @@ class QueryPage {
 
 class PageQueryPage extends QueryPage {
 
-    function formatResult( $skin, $result ) {
-       return $skin->makeKnownLink( $result->cur_title, "" );
-    }
+       function formatResult( $skin, $result ) {
+               return $skin->makeKnownLink( $result->cur_title, "" );
+       }
 }
 
 ?>
index a93a4eb..aadf79b 100644 (file)
@@ -4,37 +4,37 @@ include_once( "QueryPage.php" );
 
 class AncientPagesPage extends QueryPage {
 
-    function getName() {
-       return "Ancientpages";
-    }
-    
-    function isExpensive() {
-       return 0;
-    }
-
-    function getSQL( $offset, $limit ) {
-       return "SELECT cur_title, cur_timestamp " . 
-         "FROM cur USE INDEX (cur_timestamp) " .
-         "WHERE cur_namespace=0 AND cur_is_redirect=0 " .
-         " ORDER BY cur_timestamp LIMIT {$offset}, {$limit}";
-    }
-    
-    function formatResult( $skin, $result ) {
-       global $wgLang;
-       
-       $d = $wgLang->timeanddate( $result->cur_timestamp, true );
-       $link = $skin->makeKnownLink( $result->cur_title, "" );
-       return "{$link} ({$d})";
-    }
+       function getName() {
+               return "Ancientpages";
+       }
+
+       function isExpensive() {
+               return parent::isExpensive() ;
+       }
+
+       function getSQL( $offset, $limit ) {
+               return "SELECT cur_title, cur_timestamp " . 
+                 "FROM cur USE INDEX (cur_timestamp) " .
+                 "WHERE cur_namespace=0 AND cur_is_redirect=0 " .
+                 " ORDER BY cur_timestamp LIMIT {$offset}, {$limit}";
+       }
+
+       function formatResult( $skin, $result ) {
+               global $wgLang;
+
+               $d = $wgLang->timeanddate( $result->cur_timestamp, true );
+               $link = $skin->makeKnownLink( $result->cur_title, "" );
+               return "{$link} ({$d})";
+       }
 }
 
 function wfSpecialAncientpages()
 {
-    list( $limit, $offset ) = wfCheckLimits();
-    
-    $app = new AncientPagesPage();
-    
-    $app->doQuery( $offset, $limit );
+       list( $limit, $offset ) = wfCheckLimits();
+
+       $app = new AncientPagesPage();
+
+       $app->doQuery( $offset, $limit );
 }
 
 ?>
index 44fa88a..e4c0ed7 100644 (file)
@@ -3,26 +3,26 @@
 include_once( "QueryPage.php" );
 
 class LongPagesPage extends QueryPage {
-    
-    function getName() {
-       return "Longpages";
-    }
-    
-    function isExpensive() {
-       return 1;
-    }
-    
-    function getSQL( $offset, $limit ) {
-       return "SELECT cur_title, LENGTH(cur_text) AS len FROM cur " .
-         "WHERE cur_namespace=0 AND cur_is_redirect=0 ORDER BY " .
-         "LENGTH(cur_text) DESC LIMIT {$offset}, {$limit}";
-    }
-
-    function formatResult( $skin, $result ) {
-       $nb = wfMsg( "nbytes", $result->len );
-       $link = $skin->makeKnownLink( $result->cur_title, "" );
-       return "{$link} ({$nb})";
-    }
+
+       function getName() {
+               return "Longpages";
+       }
+
+       function isExpensive() {
+               return 1;
+       }
+
+       function getSQL( $offset, $limit ) {
+               return "SELECT cur_title, LENGTH(cur_text) AS len FROM cur " .
+                 "WHERE cur_namespace=0 AND cur_is_redirect=0 ORDER BY " .
+                 "LENGTH(cur_text) DESC LIMIT {$offset}, {$limit}";
+       }
+
+       function formatResult( $skin, $result ) {
+               $nb = wfMsg( "nbytes", $result->len );
+               $link = $skin->makeKnownLink( $result->cur_title, "" );
+               return "{$link} ({$nb})";
+       }
 }
 
 function wfSpecialLongpages()
index ddeafa2..8dbff5b 100644 (file)
@@ -4,48 +4,48 @@ include_once( "QueryPage.php" );
 
 class NewPagesPage extends QueryPage {
 
-    function getName() {
-       return "Newpages";
-    }
-    
-    function isExpensive() {
-       return 0;
-    }
-
-    function getSQL( $offset, $limit ) {
-       return "SELECT rc_title AS cur_title,rc_user AS cur_user,rc_user_text AS cur_user_text,rc_comment as cur_comment," .
-         "rc_timestamp AS cur_timestamp,length(cur_text) as cur_length FROM recentchanges,cur " .
-         "WHERE rc_cur_id=cur_id AND rc_new=1 AND rc_namespace=0 AND cur_is_redirect=0 " .
-         "ORDER BY rc_timestamp DESC LIMIT {$offset}, {$limit}";
-    }
-    
-    function formatResult( $skin, $result ) {
-       
-       global $wgLang;
-       
-       $u = $result->cur_user;
-       $ut = $result->cur_user_text;
-       
-       $length = wfmsg( "nbytes", $result->cur_length );
-       $c = wfEscapeHTML( $result->cur_comment );
-       
-       if ( 0 == $u ) { # not by a logged-in user
-           $ul = $ut;
+       function getName() {
+               return "Newpages";
        }
-       else {
-           $ul = $skin->makeLink( $wgLang->getNsText(2) . ":{$ut}", $ut );
+
+       function isExpensive() {
+               return parent::isExpensive();
        }
-       
-       $d = $wgLang->timeanddate( $result->cur_timestamp, true );
-       $link = $skin->makeKnownLink( $result->cur_title, "" );
-       $s = "{$d} {$link} ({$length}) . . {$ul}";
-       
-       if ( "" != $c && "*" != $c ) {
-           $s .= " <em>({$c})</em>";
+
+       function getSQL( $offset, $limit ) {
+               return "SELECT rc_title AS cur_title,rc_user AS cur_user,rc_user_text AS cur_user_text,rc_comment as cur_comment," .
+                 "rc_timestamp AS cur_timestamp,length(cur_text) as cur_length FROM recentchanges,cur " .
+                 "WHERE rc_cur_id=cur_id AND rc_new=1 AND rc_namespace=0 AND cur_is_redirect=0 " .
+                 "ORDER BY rc_timestamp DESC LIMIT {$offset}, {$limit}";
        }
 
-       return $s;
-    }
+       function formatResult( $skin, $result ) {
+
+               global $wgLang;
+
+               $u = $result->cur_user;
+               $ut = $result->cur_user_text;
+
+               $length = wfmsg( "nbytes", $result->cur_length );
+               $c = wfEscapeHTML( $result->cur_comment );
+
+               if ( 0 == $u ) { # not by a logged-in user
+                       $ul = $ut;
+               }
+               else {
+                       $ul = $skin->makeLink( $wgLang->getNsText(2) . ":{$ut}", $ut );
+               }
+
+               $d = $wgLang->timeanddate( $result->cur_timestamp, true );
+               $link = $skin->makeKnownLink( $result->cur_title, "" );
+               $s = "{$d} {$link} ({$length}) . . {$ul}";
+
+               if ( "" != $c && "*" != $c ) {
+                       $s .= " <em>({$c})</em>";
+               }
+
+               return $s;
+       }
 }
 
 function wfSpecialNewpages()
index 1e0db4e..5053750 100644 (file)
@@ -4,25 +4,25 @@ include_once( "QueryPage.php" );
 
 class PopularPagesPage extends QueryPage {
 
-    function getName() {
-       return "Popularpages";
-    }
-    
-    function isExpensive() {
-       return 1;
-    }
-    
-    function getSQL( $offset, $limit ) {
-       return "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}";
-    }
-    
-    function formatResult( $skin, $result ) {
-       $link = $skin->makeKnownLink( $result->cur_title, "" );
-       $nv = wfMsg( "nviews", $result->cur_counter );
-       return "{$link} ({$nv})";
-    }
+       function getName() {
+               return "Popularpages";
+       }
+
+       function isExpensive() {
+               return 1;
+       }
+
+       function getSQL( $offset, $limit ) {
+               return "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}";
+       }
+
+       function formatResult( $skin, $result ) {
+               $link = $skin->makeKnownLink( $result->cur_title, "" );
+               $nv = wfMsg( "nviews", $result->cur_counter );
+               return "{$link} ({$nv})";
+       }
 }
 
 function wfSpecialPopularpages()
index c74158f..c68e072 100644 (file)
@@ -3,35 +3,35 @@
 include_once("QueryPage.php");
 
 class ShortPagesPage extends QueryPage {
-    
-    function getName() {
-       return "Shortpages";
-    }
-    
-    function isExpensive() {
-       return 1;
-    }
-    
-    function getSQL( $offset, $limit ) {
-       return "SELECT cur_title, LENGTH(cur_text) AS len FROM cur " .
-         "WHERE cur_namespace=0 AND cur_is_redirect=0 ORDER BY " .
-         "LENGTH(cur_text) LIMIT {$offset}, {$limit}";
-    }
-    
-    function formatResult( $skin, $result ) {
-       $nb = wfMsg( "nbytes", $result->len );
-       $link = $skin->makeKnownLink( $result->cur_title, "" );
-       return "{$link} ({$nb})";
-    }
+
+       function getName() {
+               return "Shortpages";
+       }
+
+       function isExpensive() {
+               return 1;
+       }
+
+       function getSQL( $offset, $limit ) {
+               return "SELECT cur_title, LENGTH(cur_text) AS len FROM cur " .
+                 "WHERE cur_namespace=0 AND cur_is_redirect=0 ORDER BY " .
+                 "LENGTH(cur_text) LIMIT {$offset}, {$limit}";
+       }
+
+       function formatResult( $skin, $result ) {
+               $nb = wfMsg( "nbytes", $result->len );
+               $link = $skin->makeKnownLink( $result->cur_title, "" );
+               return "{$link} ({$nb})";
+       }
 }
 
 function wfSpecialShortpages()
 {
-    list( $limit, $offset ) = wfCheckLimits();
-    
-    $spp = new ShortPagesPage();
-    
-    return $spp->doQuery( $offset, $limit );
+       list( $limit, $offset ) = wfCheckLimits();
+
+       $spp = new ShortPagesPage();
+
+       return $spp->doQuery( $offset, $limit );
 }
 
 ?>
index acb11c6..6bc82a5 100644 (file)
@@ -3,42 +3,42 @@
 include_once ( "QueryPage.php" ) ;
 
 class WantedPagesPage extends QueryPage {
-    
-    function getName() {
-       return "Wantedpages";
-    }
-    
-    function isExpensive() {
-       return 1;
-    }
-    
-    function getSQL( $offset, $limit ) {
-       return "SELECT bl_to, COUNT( DISTINCT bl_from ) as nlinks " .
-         "FROM brokenlinks GROUP BY bl_to HAVING nlinks > 1 " .
-         "ORDER BY nlinks DESC LIMIT {$offset}, {$limit}";
-    }
-
-    function formatResult( $skin, $result ) {
-       global $wgLang;
-       
-       $nt = Title::newFromDBkey( $result->bl_to );
-
-       $plink = $skin->makeBrokenLink( $nt->getPrefixedText(), "" );
-       $nl = wfMsg( "nlinks", $result->nlinks );
-       $nlink = $skin->makeKnownLink( $wgLang->specialPage( "Whatlinkshere" ), $nl,
-                                    "target=" . $nt->getPrefixedURL() );
-       
-       return "{$plink} ({$nlink})";
-    }
+
+       function getName() {
+               return "Wantedpages";
+       }
+
+       function isExpensive() {
+               return 1;
+       }
+
+       function getSQL( $offset, $limit ) {
+               return "SELECT bl_to, COUNT( DISTINCT bl_from ) as nlinks " .
+                 "FROM brokenlinks GROUP BY bl_to HAVING nlinks > 1 " .
+                 "ORDER BY nlinks DESC LIMIT {$offset}, {$limit}";
+       }
+
+       function formatResult( $skin, $result ) {
+               global $wgLang;
+
+               $nt = Title::newFromDBkey( $result->bl_to );
+
+               $plink = $skin->makeBrokenLink( $nt->getPrefixedText(), "" );
+               $nl = wfMsg( "nlinks", $result->nlinks );
+               $nlink = $skin->makeKnownLink( $wgLang->specialPage( "Whatlinkshere" ), $nl,
+                 "target=" . $nt->getPrefixedURL() );
+
+               return "{$plink} ({$nlink})";
+       }
 }
 
 function wfSpecialWantedpages()
 {
-    list( $limit, $offset ) = wfCheckLimits();
-    
-    $wpp = new WantedPagesPage();
-    
-    $wpp->doQuery( $offset, $limit );
+       list( $limit, $offset ) = wfCheckLimits();
+
+       $wpp = new WantedPagesPage();
+
+       $wpp->doQuery( $offset, $limit );
 }
 
 ?>