(bug 27862; follow-up r77714) Make emailuser api module not freak out when SpecialEma...
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index 12f47d3..d96808f 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,19 +260,22 @@ 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' );
 
-               $db = $this->getDB();
                // Get protection info if requested
                if ( $this->fld_protection ) {
                        $this->getProtectionInfo();
                }
 
                if ( $this->fld_watched ) {
-                       $this->getMain()->setVaryCookie();
                        $this->getWatchedInfo();
                }
 
@@ -262,7 +283,7 @@ class ApiQueryInfo extends ApiQueryBase {
                if ( $this->fld_talkid || $this->fld_subjectid ) {
                        $this->getTSIDs();
                }
-               
+
                if ( $this->fld_displaytitle ) {
                        $this->getDisplayTitle();
                }
@@ -291,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] ) {
@@ -305,9 +330,6 @@ class ApiQueryInfo extends ApiQueryBase {
                }
 
                if ( !is_null( $this->params['token'] ) ) {
-                       // Don't cache tokens
-                       $this->getMain()->setCachePrivate();
-                       
                        $tokenFunctions = $this->getTokenFunctions();
                        $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601, time() );
                        foreach ( $this->params['token'] as $t ) {
@@ -359,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()];
@@ -533,7 +555,7 @@ class ApiQueryInfo extends ApiQueryBase {
                if ( !count( $getTitles ) ) {
                        return;
                }
-               
+
                $db = $this->getDB();
 
                // Construct a custom WHERE clause that matches
@@ -554,17 +576,15 @@ class ApiQueryInfo extends ApiQueryBase {
                        }
                }
        }
-       
+
        private function getDisplayTitle() {
                $this->displaytitles = array();
-               
+
                $pageIds = array_keys( $this->titles );
-       
+
                if ( !count( $pageIds ) ) {
                        return;
                }
-               
-               $db = $this->getDB();
 
                $this->resetQueryParams();
                $this->addTables( 'page_props' );
@@ -572,7 +592,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;
                }
@@ -584,30 +604,50 @@ 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;
+               }
+       }
+
+       public function getCacheMode( $params ) {
+               $publicProps = array(
+                       'protection',
+                       'talkid',
+                       'subjectid',
+                       'url',
+                       'preload',
+                       'displaytitle',
+               );
+               if ( !is_null( $params['prop'] ) ) {
+                       foreach ( $params['prop'] as $prop ) {
+                               if ( !in_array( $prop, $publicProps ) ) {
+                                       return 'private';
+                               }
+                       }
+               }
+               if ( !is_null( $params['token'] ) ) {
+                       return 'private';
                }
+               return 'public';
        }
 
        public function getAllowedParams() {
@@ -618,12 +658,14 @@ class ApiQueryInfo extends ApiQueryBase {
                                ApiBase::PARAM_TYPE => array(
                                        'protection',
                                        'talkid',
-                                       'watched',
+                                       'watched', # private
                                        'subjectid',
                                        'url',
-                                       'readable',
+                                       'readable', # private
                                        'preload',
                                        'displaytitle',
+                                       // If you add more properties here, please consider whether they
+                                       // need to be added to getCacheMode()
                                ) ),
                        'token' => array(
                                ApiBase::PARAM_DFLT => null,