* changed variable list as per comment on r79954 left only wgDBtype
[lhc/web/wiklou.git] / includes / QueryPage.php
index eab73a4..f656949 100644 (file)
@@ -85,6 +85,8 @@ abstract class QueryPage extends SpecialPage {
         */
        protected $numRows;
 
+       protected $cachedTimestamp = null;
+
        /**
         * Wheter to show prev/next links
         */
@@ -109,8 +111,7 @@ abstract class QueryPage extends SpecialPage {
         *    join_conds => JOIN conditions
         *
         * Note that the query itself should return the following three columns:
-        * 'namespace', 'title', and 'value'
-        * *in that order*. 'value' is used for sorting.
+        * 'namespace', 'title', and 'value'. 'value' is used for sorting.
         *
         * These may be stored in the querycache table for expensive queries,
         * and that cached data will be returned sometimes, so the presence of
@@ -134,9 +135,9 @@ abstract class QueryPage extends SpecialPage {
         * For back-compat, subclasses may return a raw SQL query here, as a string.
         * This is stronly deprecated; getQueryInfo() should be overridden instead.
         * @return string
-        * @deprecated since 1.18
         */
        function getSQL() {
+               /* Implement getQueryInfo() instead */
                throw new MWException( "Bug in a QueryPage: doesn't implement getQueryInfo() nor getQuery() properly" );
        }
 
@@ -342,6 +343,7 @@ abstract class QueryPage extends SpecialPage {
         */
        function reallyDoQuery( $limit, $offset = false ) {
                $fname = get_class( $this ) . "::reallyDoQuery";
+               $dbr = wfGetDB( DB_SLAVE );
                $query = $this->getQueryInfo();
                $order = $this->getOrderFields();
                if ( $this->sortDescending() ) {
@@ -365,7 +367,6 @@ abstract class QueryPage extends SpecialPage {
                                $options['OFFSET'] = intval( $offset );
                        }
 
-                       $dbr = wfGetDB( DB_SLAVE );
                        $res = $dbr->select( $tables, $fields, $conds, $fname,
                                        $options, $join_conds
                        );
@@ -374,7 +375,7 @@ abstract class QueryPage extends SpecialPage {
                        $sql = $this->getSQL();
                        $sql .= ' ORDER BY ' . implode( ', ', $order );
                        $sql = $dbr->limitResult( $sql, $limit, $offset );
-                       $res = $dbr->query( $sql );
+                       $res = $dbr->query( $sql, $fname );
                }
                return $dbr->resultObject( $res );
        }
@@ -415,6 +416,16 @@ abstract class QueryPage extends SpecialPage {
                );
                return $dbr->resultObject( $res );
        }
+       
+       public function getCachedTimestamp() {
+               if ( !is_null( $this->cachedTimestamp ) ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $fname = get_class( $this ) . '::getCachedTimestamp';
+                       $this->cachedTimestamp = $dbr->selectField( 'querycache_info', 'qci_timestamp',
+                               array( 'qci_type' => $this->getName() ), $fname );
+               }
+               return $this->cachedTimestamp;
+       }
 
        /**
         * This is the actual workhorse. It does everything needed to make a
@@ -430,8 +441,6 @@ abstract class QueryPage extends SpecialPage {
 
                if ( $this->limit == 0 && $this->offset == 0 )
                        list( $this->limit, $this->offset ) = wfCheckLimits();
-               $sname = $this->getName();
-               $fname = get_class( $this ) . '::doQuery';
                $dbr = wfGetDB( DB_SLAVE );
 
                $this->setHeaders();
@@ -453,15 +462,14 @@ abstract class QueryPage extends SpecialPage {
                        if ( !$this->listoutput ) {
 
                                # Fetch the timestamp of this update
-                               $tRes = $dbr->select( 'querycache_info', array( 'qci_timestamp' ), array( 'qci_type' => $sname ), $fname );
-                               $tRow = $dbr->fetchObject( $tRes );
-
-                               if ( $tRow ) {
-                                       $updated = $wgLang->timeanddate( $tRow->qci_timestamp, true, true );
-                                       $updateddate = $wgLang->date( $tRow->qci_timestamp, true, true );
-                                       $updatedtime = $wgLang->time( $tRow->qci_timestamp, true, true );
-                                       $wgOut->addMeta( 'Data-Cache-Time', $tRow->qci_timestamp );
-                                       $wgOut->addInlineScript( "var dataCacheTime = '{$tRow->qci_timestamp}';" );
+                               $ts = $this->getCachedTimestamp();
+
+                               if ( $ts ) {
+                                       $updated = $wgLang->timeanddate( $ts, true, true );
+                                       $updateddate = $wgLang->date( $ts, true, true );
+                                       $updatedtime = $wgLang->time( $ts, true, true );
+                                       $wgOut->addMeta( 'Data-Cache-Time', $ts );
+                                       $wgOut->addInlineScript( "var dataCacheTime = '$ts';" );
                                        $wgOut->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime );
                                } else {
                                        $wgOut->addWikiMsg( 'perfcached' );