Fix the last assignment in conditional, bit of code duplication, as the next isn...
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index 4dfeb7f..5b0d325 100644 (file)
@@ -1,9 +1,8 @@
 <?php
-
 /**
- * Created on Sep 25, 2006
  *
- * API for MediaWiki 1.8+
+ *
+ * Created on Sep 25, 2006
  *
  * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
@@ -21,6 +20,8 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -40,15 +41,32 @@ class ApiQueryInfo extends ApiQueryBase {
                $fld_readable = false, $fld_watched = false,
                $fld_preload = false, $fld_displaytitle = false;
 
+       private $params, $titles, $missing, $everything, $pageCounter;
+
+       private $pageRestrictions, $pageIsRedir, $pageIsNew, $pageTouched,
+               $pageLatest, $pageLength;
+
+       private $protections, $watched, $talkids, $subjectids, $displaytitles;
+
+       private $tokenFunctions;
+
        public function __construct( $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'in' );
        }
 
+       /**
+        * @param $pageSet ApiPageSet
+        * @return void
+        */
        public function requestExtraData( $pageSet ) {
+               global $wgDisableCounters;
+
                $pageSet->requestField( 'page_restrictions' );
                $pageSet->requestField( 'page_is_redirect' );
                $pageSet->requestField( 'page_is_new' );
-               $pageSet->requestField( 'page_counter' );
+               if ( !$wgDisableCounters ) {
+                       $pageSet->requestField( 'page_counter' );
+               }
                $pageSet->requestField( 'page_touched' );
                $pageSet->requestField( 'page_latest' );
                $pageSet->requestField( 'page_len' );
@@ -242,7 +260,12 @@ class ApiQueryInfo extends ApiQueryBase {
                $this->pageRestrictions = $pageSet->getCustomField( 'page_restrictions' );
                $this->pageIsRedir = $pageSet->getCustomField( 'page_is_redirect' );
                $this->pageIsNew = $pageSet->getCustomField( 'page_is_new' );
-               $this->pageCounter = $pageSet->getCustomField( 'page_counter' );
+
+               global $wgDisableCounters;
+
+               if ( !$wgDisableCounters ) {
+                       $this->pageCounter = $pageSet->getCustomField( 'page_counter' );
+               }
                $this->pageTouched = $pageSet->getCustomField( 'page_touched' );
                $this->pageLatest = $pageSet->getCustomField( 'page_latest' );
                $this->pageLength = $pageSet->getCustomField( 'page_len' );
@@ -260,7 +283,7 @@ class ApiQueryInfo extends ApiQueryBase {
                if ( $this->fld_talkid || $this->fld_subjectid ) {
                        $this->getTSIDs();
                }
-               
+
                if ( $this->fld_displaytitle ) {
                        $this->getDisplayTitle();
                }
@@ -289,9 +312,13 @@ class ApiQueryInfo extends ApiQueryBase {
        private function extractPageInfo( $pageid, $title ) {
                $pageInfo = array();
                if ( $title->exists() ) {
+                       global $wgDisableCounters;
+
                        $pageInfo['touched'] = wfTimestamp( TS_ISO_8601, $this->pageTouched[$pageid] );
                        $pageInfo['lastrevid'] = intval( $this->pageLatest[$pageid] );
-                       $pageInfo['counter'] = intval( $this->pageCounter[$pageid] );
+                       $pageInfo['counter'] = $wgDisableCounters
+                               ? ""
+                               : intval( $this->pageCounter[$pageid] );
                        $pageInfo['length'] = intval( $this->pageLength[$pageid] );
 
                        if ( $this->pageIsRedir[$pageid] ) {
@@ -354,7 +381,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                $pageInfo['preload'] = $text;
                        }
                }
-               
+
                if ( $this->fld_displaytitle ) {
                        if ( isset( $this->displaytitles[$title->getArticleId()] ) ) {
                                $pageInfo['displaytitle'] = $this->displaytitles[$title->getArticleId()];
@@ -370,6 +397,7 @@ class ApiQueryInfo extends ApiQueryBase {
         * Get information about protections and put it in $protections
         */
        private function getProtectionInfo() {
+               global $wgContLang;
                $this->protections = array();
                $db = $this->getDB();
 
@@ -388,7 +416,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                $a = array(
                                        'type' => $row->pr_type,
                                        'level' => $row->pr_level,
-                                       'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 )
+                                       'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 )
                                );
                                if ( $row->pr_cascade ) {
                                        $a['cascade'] = '';
@@ -445,7 +473,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                $this->protections[$row->pt_namespace][$row->pt_title][] = array(
                                        'type' => 'create',
                                        'level' => $row->pt_create_perm,
-                                       'expiry' => Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 )
+                                       'expiry' => $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 )
                                );
                        }
                }
@@ -479,7 +507,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                $this->protections[$row->tl_namespace][$row->tl_title][] = array(
                                        'type' => $row->pr_type,
                                        'level' => $row->pr_level,
-                                       'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ),
+                                       'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
                                        'source' => $source->getPrefixedText()
                                );
                        }
@@ -502,7 +530,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                $this->protections[NS_FILE][$row->il_to][] = array(
                                        'type' => $row->pr_type,
                                        'level' => $row->pr_level,
-                                       'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ),
+                                       'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
                                        'source' => $source->getPrefixedText()
                                );
                        }
@@ -528,7 +556,7 @@ class ApiQueryInfo extends ApiQueryBase {
                if ( !count( $getTitles ) ) {
                        return;
                }
-               
+
                $db = $this->getDB();
 
                // Construct a custom WHERE clause that matches
@@ -549,12 +577,12 @@ class ApiQueryInfo extends ApiQueryBase {
                        }
                }
        }
-       
+
        private function getDisplayTitle() {
                $this->displaytitles = array();
-               
+
                $pageIds = array_keys( $this->titles );
-       
+
                if ( !count( $pageIds ) ) {
                        return;
                }
@@ -565,7 +593,7 @@ class ApiQueryInfo extends ApiQueryBase {
                $this->addWhereFld( 'pp_page', $pageIds );
                $this->addWhereFld( 'pp_propname', 'displaytitle' );
                $res = $this->select( __METHOD__ );
-               
+
                foreach ( $res as $row ) {
                        $this->displaytitles[$row->pp_page] = $row->pp_value;
                }
@@ -577,29 +605,27 @@ class ApiQueryInfo extends ApiQueryBase {
        private function getWatchedInfo() {
                global $wgUser;
 
-               if ( $wgUser->isAnon() || count( $this->titles ) == 0 ) {
+               if ( $wgUser->isAnon() || count( $this->everything ) == 0 ) {
                        return;
                }
 
                $this->watched = array();
                $db = $this->getDB();
 
-               $lb = new LinkBatch( $this->titles );
+               $lb = new LinkBatch( $this->everything );
 
                $this->resetQueryParams();
-               $this->addTables( array( 'page', 'watchlist' ) );
-               $this->addFields( array( 'page_title', 'page_namespace' ) );
+               $this->addTables( array( 'watchlist' ) );
+               $this->addFields( array( 'wl_title', 'wl_namespace' ) );
                $this->addWhere( array(
-                       $lb->constructSet( 'page', $db ),
-                       'wl_namespace=page_namespace',
-                       'wl_title=page_title',
+                       $lb->constructSet( 'wl', $db ),
                        'wl_user' => $wgUser->getID()
                ) );
 
                $res = $this->select( __METHOD__ );
 
                foreach ( $res as $row ) {
-                       $this->watched[$row->page_namespace][$row->page_title] = true;
+                       $this->watched[$row->wl_namespace][$row->wl_title] = true;
                }
        }
 
@@ -639,7 +665,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                        'readable', # private
                                        'preload',
                                        'displaytitle',
-                                       // If you add more properties here, please consider whether they 
+                                       // If you add more properties here, please consider whether they
                                        // need to be added to getCacheMode()
                                ) ),
                        'token' => array(