http://www.mediawiki.org/wiki/Special:Code/MediaWiki/65311

Revision: 65311
Author:   reedy
Date:     2010-04-20 13:49:27 +0000 (Tue, 20 Apr 2010)

Log Message:
-----------
querypage-work2: Merge r49084 skip r49527 (already in trunk)

Modified Paths:
--------------
    branches/querypage-work2/phase3/includes/QueryPage.php
    branches/querypage-work2/phase3/includes/specials/SpecialAncientpages.php
    branches/querypage-work2/phase3/includes/specials/SpecialBrokenRedirects.php
    branches/querypage-work2/phase3/includes/specials/SpecialDeadendpages.php

Property Changed:
----------------
    branches/querypage-work2/
    branches/querypage-work2/phase3/
    branches/querypage-work2/phase3/includes/
    branches/querypage-work2/phase3/includes/ChangesList.php
    branches/querypage-work2/phase3/includes/ConfEditor.php
    branches/querypage-work2/phase3/includes/OutputPage.php
    branches/querypage-work2/phase3/includes/api/
    branches/querypage-work2/phase3/includes/specials/
    branches/querypage-work2/phase3/maintenance/cleanupTable.inc
    branches/querypage-work2/phase3/skins/common/jquery.js
    branches/querypage-work2/phase3/skins/common/jquery.min.js


Property changes on: branches/querypage-work2
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/querypage-work:49084


Property changes on: branches/querypage-work2/phase3
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/REL1_15/phase3:51646
/branches/sqlite:58211-58321
   + /branches/REL1_15/phase3:51646
/branches/querypage-work/phase3:49084
/branches/sqlite:58211-58321


Property changes on: branches/querypage-work2/phase3/includes
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/REL1_15/phase3/includes:51646
/branches/sqlite/includes:58211-58321
/branches/wmf-deployment/includes:53381
   + /branches/REL1_15/phase3/includes:51646
/branches/querypage-work/phase3/includes:49084
/branches/sqlite/includes:58211-58321
/branches/wmf-deployment/includes:53381


Property changes on: branches/querypage-work2/phase3/includes/ChangesList.php
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/REL1_15/phase3/includes/ChangesList.php:51646
/branches/wmf-deployment/includes/ChangesList.php:53381,57589
   + /branches/REL1_15/phase3/includes/ChangesList.php:51646
/branches/querypage-work/phase3/includes/ChangesList.php:49084
/branches/wmf-deployment/includes/ChangesList.php:53381,57589


Property changes on: branches/querypage-work2/phase3/includes/ConfEditor.php
___________________________________________________________________
Modified: svn:mergeinfo
   - 
   + /branches/querypage-work/phase3/includes/ConfEditor.php:49084


Property changes on: branches/querypage-work2/phase3/includes/OutputPage.php
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/REL1_15/phase3/includes/OutputPage.php:51646
/branches/wmf-deployment/includes/OutputPage.php:53381,57468
   + /branches/REL1_15/phase3/includes/OutputPage.php:51646
/branches/querypage-work/phase3/includes/OutputPage.php:49084
/branches/wmf-deployment/includes/OutputPage.php:53381,57468

Modified: branches/querypage-work2/phase3/includes/QueryPage.php
===================================================================
--- branches/querypage-work2/phase3/includes/QueryPage.php      2010-04-20 
13:13:07 UTC (rev 65310)
+++ branches/querypage-work2/phase3/includes/QueryPage.php      2010-04-20 
13:49:27 UTC (rev 65311)
@@ -60,7 +60,7 @@
  * subclasses derive from it.
  * @ingroup SpecialPage
  */
-class QueryPage {
+abstract class QueryPage {
        /**
         * Whether or not we want plain listoutput rather than an ordered list
         *
@@ -106,8 +106,14 @@
        }
 
        /**
-        * Subclasses return an SQL query here.
-        *
+        * Subclasses return an SQL query here, formatted as an array with the
+        * following keys:
+        *    tables => Table(s) for passing to Database::select()
+        *    fields => Field(s) for passing to Database::select(), may be *
+        *    conds => WHERE conditions
+        *    options => options
+        *    join_conds => JOIN conditions
+        * 
         * Note that the query itself should return the following four columns:
         * 'type' (your special page's name), 'namespace', 'title', and 'value'
         * *in that order*. 'value' is used for sorting.
@@ -118,10 +124,19 @@
         * an integer; non-numeric values are useful only for sorting the 
initial
         * query.
         *
-        * Don't include an ORDER or LIMIT clause, this will be added.
+        * Don't include an ORDER or LIMIT clause, they will be added
+        * @return array
         */
-       function getSQL() {
-               return "SELECT 'sample' as type, 0 as namespace, 'Sample 
result' as title, 42 as value";
+       abstract function getQueryInfo();
+       
+       /**
+        * Subclasses return an array of fields to order by here. Don't append
+        * DESC to the field names, that'll be done automatically if
+        * sortDescending() returns true
+        * @return array
+        */
+       function getOrderFields() {
+               return array('value');
        }
 
        /**
@@ -133,11 +148,6 @@
                return true;
        }
 
-       function getOrder() {
-               return ' ORDER BY value ' .
-                       ($this->sortDescending() ? 'DESC' : '');
-       }
-
        /**
         * Is this query expensive (for some definition of expensive)? Then we
         * don't let it run in miser mode. $wgDisableQueryPages causes all query
@@ -151,7 +161,7 @@
        }
 
        /**
-        * Whether or not the output of the page in question is retrived from
+        * Whether or not the output of the page in question is retrieved from
         * the database cache.
         *
         * @return Boolean
@@ -175,14 +185,15 @@
         * 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.
-        * If the function return "false", the line output will be skipped.
+        * If the function returns false, the line output will be skipped.
+        * @param $skin Skin
+        * @param $result object Result row
+        * @return mixed String or false to skip
         *
         * @param $skin Skin object
         * @param $result Object: database row
         */
-       function formatResult( $skin, $result ) {
-               return '';
-       }
+       abstract function formatResult( $skin, $result );
 
        /**
         * The content returned by this function will be output before any 
result
@@ -207,8 +218,9 @@
        /**
         * Some special pages (for example SpecialListusers) might not return 
the
         * current object formatted, but return the previous one instead.
-        * Setting this to return true, will call one more time wfFormatResult 
to
-        * be sure that the very last result is formatted and shown.
+        * Setting this to return true will ensure formatResult() is called
+        * one more time to make sure that the very last result is formatted
+        * as well.
         */
        function tryLastResult() {
                return false;
@@ -228,8 +240,6 @@
                        return false;
                }
 
-               $querycache = $dbr->tableName( 'querycache' );
-
                if ( $ignoreErrors ) {
                        $ignoreW = $dbw->ignoreErrors( true );
                        $ignoreR = $dbr->ignoreErrors( true );
@@ -238,10 +248,7 @@
                # Clear out any old cached data
                $dbw->delete( 'querycache', array( 'qc_type' => 
$this->getName() ), $fname );
                # Do query
-               $sql = $this->getSQL() . $this->getOrder();
-               if ( $limit !== false )
-                       $sql = $dbr->limitResult( $sql, $limit, 0 );
-               $res = $dbr->query( $sql, $fname );
+               $res = $this->reallyDoQuery( $limit, false );
                $num = false;
                if ( $res ) {
                        $num = $dbr->numRows( $res );
@@ -265,7 +272,7 @@
                                if ( !$dbw->insert( 'querycache', $vals, 
__METHOD__ ) ) {
                                        // Set result to false to indicate error
                                        $dbr->freeResult( $res );
-                                       $res = false;
+                                       $num = false;
                                }
                        }
                        if ( $res ) {
@@ -283,6 +290,68 @@
                }
                return $num;
        }
+       
+       /**
+        * Run the query and return the result
+        * @param $limit mixed Numerical limit or false for no limit
+        * @param $offset mixed Numerical offset or false for no offset
+        * @return ResultWrapper
+        */
+       function reallyDoQuery( $limit, $offset = false ) {
+               $fname = get_class( $this ) . "::reallyDoQuery";
+               $query = $this->getQueryInfo();
+               $order = $this->getOrderFields();
+               if( $this->sortDescending() ) {
+                       foreach( $order as &$field ) {
+                               $field .= ' DESC';
+                       }
+               }
+               if( !is_array( $query['options'] ) ) {
+                       $options = array ();
+               }
+               if( count( $order ) ) {
+                       $query['options']['ORDER BY'] = implode( ', ', $order );
+               }
+               if( $limit !== false) {
+                       $query['options']['LIMIT'] = intval( $limit );
+               }
+               if( $offset !== false) {
+                       $query['options']['OFFSET'] = intval( $offset );
+               }
+               
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( (array)$query['tables'],
+                               (array)$query['fields'],
+                               (array)$query['conds'], $fname,
+                               $query['options'], (array)$query['join_conds']
+               );
+               return $dbr->resultObject( $res );
+       }
+       
+       /**
+        * Fetch the query results from the query cache
+        * @param $limit mixed Numerical limit or false for no limit
+        * @param $offset mixed Numerical offset or false for no offset
+        * @return ResultWrapper
+        */
+       function fetchFromCache( $limit, $offset = false ) {
+               $dbr = wfGetDB( DB_SLAVE );
+               $options = array ();
+               if( $limit !== false ) {
+                       $options['LIMIT'] = intval( $limit );
+               }
+               if( $offset !== false) {
+                       $options['OFFSET'] = intval( $offset );
+               }
+               $res = $dbr->select( 'querycache', array( 'qc_type',
+                               'qc_namespace AS namespace',
+                               'qc_title AS title',
+                               'qc_value AS value' ),
+                               array( 'qc_type' => $this->getName() ),
+                               __METHOD__, $options
+               );
+               return $dbr->resultObject( $res );
+       }
 
        /**
         * This is the actual workhorse. It does everything needed to make a
@@ -304,16 +373,12 @@
 
                $wgOut->setSyndicated( $this->isSyndicated() );
 
+               //$res = null;
                if ( !$this->isCached() ) {
-                       $sql = $this->getSQL();
+                       $res = $this->reallyDoQuery( $limit, $offset );
                } else {
                        # Get the cached result
-                       $querycache = $dbr->tableName( 'querycache' );
-                       $type = $dbr->strencode( $sname );
-                       $sql =
-                               "SELECT qc_type as type, qc_namespace as 
namespace,qc_title as title, qc_value as value
-                                FROM $querycache WHERE qc_type='$type'";
-
+                       $res = $this->fetchFromCache( $limit, $offset );
                        if( !$this->listoutput ) {
 
                                # Fetch the timestamp of this update
@@ -342,9 +407,6 @@
 
                }
 
-               $sql .= $this->getOrder();
-               $sql = $dbr->limitResult($sql, $limit, $offset);
-               $res = $dbr->query( $sql );
                $num = $dbr->numRows($res);
 
                $this->preprocessResults( $dbr, $res );
@@ -485,9 +547,7 @@
                        $feed->outHeader();
 
                        $dbr = wfGetDB( DB_SLAVE );
-                       $sql = $this->getSQL() . $this->getOrder();
-                       $sql = $dbr->limitResult( $sql, $limit, 0 );
-                       $res = $dbr->query( $sql, 'QueryPage::doFeed' );
+                       $res = $this->reallyDoQuery( $limit, 0 );
                        while( $obj = $dbr->fetchObject( $res ) ) {
                                $item = $this->feedResult( $obj );
                                if( $item ) $feed->outItem( $item );


Property changes on: branches/querypage-work2/phase3/includes/api
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/REL1_15/phase3/includes/api:51646
/branches/REL1_16/phase3/includes/api:63621-63636
/branches/sqlite/includes/api:58211-58321
/branches/wmf-deployment/includes/api:53381,59952
   + /branches/REL1_15/phase3/includes/api:51646
/branches/REL1_16/phase3/includes/api:63621-63636
/branches/querypage-work/phase3/includes/api:49084
/branches/sqlite/includes/api:58211-58321
/branches/wmf-deployment/includes/api:53381,59952


Property changes on: branches/querypage-work2/phase3/includes/specials
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/REL1_15/phase3/includes/specials:51646
/branches/sqlite/includes/specials:58211-58321
/branches/wmf-deployment/includes/specials:53381,56967
   + /branches/REL1_15/phase3/includes/specials:51646
/branches/querypage-work/phase3/includes/specials:49084
/branches/sqlite/includes/specials:58211-58321
/branches/wmf-deployment/includes/specials:53381,56967

Modified: 
branches/querypage-work2/phase3/includes/specials/SpecialAncientpages.php
===================================================================
--- branches/querypage-work2/phase3/includes/specials/SpecialAncientpages.php   
2010-04-20 13:13:07 UTC (rev 65310)
+++ branches/querypage-work2/phase3/includes/specials/SpecialAncientpages.php   
2010-04-20 13:49:27 UTC (rev 65311)
@@ -20,38 +20,23 @@
 
        function isSyndicated() { return false; }
 
-       function getSQL() {
+       function getQueryInfo() {
+               // FIXME convert timestamps elsewhere
+               // Possibly add bool returnsTimestamps()
+               // FIXME standardize 'name' AS type ?
                global $wgDBtype;
-               $db = wfGetDB( DB_SLAVE );
-               $page = $db->tableName( 'page' );
-               $revision = $db->tableName( 'revision' );
-
-               switch ($wgDBtype) {
-                       case 'mysql': 
-                               $epoch = 'UNIX_TIMESTAMP(rev_timestamp)'; 
-                               break;
-                       case 'ibm_db2':
-                               // TODO implement proper conversion to a Unix 
epoch
-                               $epoch = 'rev_timestamp';
-                               break;
-                       case 'oracle': 
-                               $epoch = '((trunc(rev_timestamp) - 
to_date(\'19700101\',\'YYYYMMDD\')) * 86400)'; 
-                               break;
-                       case 'sqlite':
-                               $epoch = 'rev_timestamp';
-                               break;
-                       default:
-                               $epoch = 'EXTRACT(epoch FROM rev_timestamp)';
-               }
-
-               return
-                       "SELECT 'Ancientpages' as type,
-                                       page_namespace as namespace,
-                               page_title as title,
-                               $epoch as value
-                       FROM $page, $revision
-                       WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0
-                         AND page_latest=rev_id";
+               $epoch = $wgDBtype == 'mysql' ? 'UNIX_TIMESTAMP(rev_timestamp)' 
:
+                               'EXTRACT(epoch FROM rev_timestamp)';
+               return array(
+                       'tables' => array( 'page', 'revision' ),
+                       'fields' => array( "'{$this->getName()}' AS type",
+                                       'page_namespace AS namespace',
+                                       'page_title AS title',
+                                       "$epoch AS value" ),
+                       'conds' => array( 'page_namespace' => NS_MAIN,
+                                       'page_is_redirect' => 0,
+                                       'page_latest=rev_id' )
+               );
        }
 
        function sortDescending() {

Modified: 
branches/querypage-work2/phase3/includes/specials/SpecialBrokenRedirects.php
===================================================================
--- 
branches/querypage-work2/phase3/includes/specials/SpecialBrokenRedirects.php    
    2010-04-20 13:13:07 UTC (rev 65310)
+++ 
branches/querypage-work2/phase3/includes/specials/SpecialBrokenRedirects.php    
    2010-04-20 13:49:27 UTC (rev 65311)
@@ -39,9 +39,33 @@
                                    AND p2.page_namespace IS NULL";
                return $sql;
        }
+       
+       function getQueryInfo() {
+               return array(
+                       'tables' => array( 'redirect', 'page AS p1', 'page AS 
p2' ),
+                       'fields' => array( "'{$this->getName()}' AS type",
+                                       'p1.page_namespace AS namespace',
+                                       'p1.page_title AS title',
+                                       'rd_namespace',
+                                       'rd_title'
+                       ),
+                       'conds' => array( 'rd_namespace >= 0',
+                                       'p2.page_namespace IS NULL'
+                       ),
+                       // TODO test this join
+                       'join_conds' => array( 'page AS p1' => array( 'LEFT 
JOIN', array(
+                                               'rd_from=p1.page_id',
+                                       ) ),
+                                       'page AS p2' => array( 'LEFT JOIN', 
array(
+                                               
'rd_namespace=p2.page_namespace',
+                                               'rd_title=p2.page_title'
+                                       ) )
+                       )
+               );
+       }
 
        function getOrder() {
-               return '';
+               return array ();
        }
 
        function formatResult( $skin, $result ) {

Modified: 
branches/querypage-work2/phase3/includes/specials/SpecialDeadendpages.php
===================================================================
--- branches/querypage-work2/phase3/includes/specials/SpecialDeadendpages.php   
2010-04-20 13:13:07 UTC (rev 65310)
+++ branches/querypage-work2/phase3/includes/specials/SpecialDeadendpages.php   
2010-04-20 13:49:27 UTC (rev 65311)
@@ -47,6 +47,24 @@
        "AND page_namespace = 0 " .
        "AND page_is_redirect = 0";
        }
+       
+       function getQueryInfo() {
+               return array(
+                       'tables' => array( 'page', 'pagelinks' ),
+                       'fields' => array( "'{$this->getName()} AS type",
+                                       'page_namespace AS namespace',
+                                       'page_title AS title',
+                                       'page_title AS value'
+                       ),
+                       'conds' => array( 'pl_from IS NULL',
+                                       'page_namespace' => NS_MAIN,
+                                       'page_is_redirect' => 0
+                       ),
+                       'join_conds' => array( 'pagelinks' => array( 'LEFT 
JOIN', array(
+                                       'page_id=pl_from'
+                       ) ) )
+               );
+       }
 }
 
 /**


Property changes on: 
branches/querypage-work2/phase3/maintenance/cleanupTable.inc
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/REL1_15/phase3/maintenance/cleanupTable.inc:51646
/branches/wmf-deployment/maintenance/cleanupTable.inc:56715
   + /branches/REL1_15/phase3/maintenance/cleanupTable.inc:51646
/branches/querypage-work/phase3/maintenance/cleanupTable.inc:49084
/branches/wmf-deployment/maintenance/cleanupTable.inc:56715


Property changes on: branches/querypage-work2/phase3/skins/common/jquery.js
___________________________________________________________________
Modified: svn:mergeinfo
   - 
   + /branches/querypage-work/phase3/skins/common/jquery.js:49084


Property changes on: branches/querypage-work2/phase3/skins/common/jquery.min.js
___________________________________________________________________
Modified: svn:mergeinfo
   - 
   + /branches/querypage-work/phase3/skins/common/jquery.min.js:49084



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to