API: sinumberingroup now gives correct size of 'user' group, and omits size of implic...
[lhc/web/wiklou.git] / includes / api / ApiQueryRevisions.php
index f80b685..3f97a33 100644 (file)
@@ -1,10 +1,9 @@
 <?php
-
 /**
- * Created on Sep 7, 2006
- *
  * API for MediaWiki 1.8+
  *
+ * Created on Sep 7, 2006
+ *
  * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
@@ -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' ) ) {
@@ -42,7 +43,8 @@ class ApiQueryRevisions extends ApiQueryBase {
        }
 
        private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false,
-                       $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_content = false, $fld_tags = false;
+                       $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
+                       $fld_content = false, $fld_tags = false;
 
        protected function getTokenFunctions() {
                // tokenname => function
@@ -134,7 +136,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                }
 
                $db = $this->getDB();
-               $this->addTables( array( 'page', 'revision' ) );
+               $this->addTables( 'page' );
                $this->addFields( Revision::selectFields() );
                $this->addWhere( 'page_id = rev_page' );
 
@@ -148,6 +150,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                $this->fld_comment = isset ( $prop['comment'] );
                $this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
                $this->fld_size = isset ( $prop['size'] );
+               $this->fld_userid = isset( $prop['userid'] );
                $this->fld_user = isset ( $prop['user'] );
                $this->token = $params['token'];
 
@@ -199,12 +202,15 @@ class ApiQueryRevisions extends ApiQueryBase {
                        }
                }
 
+               //Bug 24166 - API error when using rvprop=tags
+               $this->addTables( 'revision' );
+
                $userMax = ( $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
                $botMax  = ( $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
                $limit = $params['limit'];
                if ( $limit == 'max' ) {
                        $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
-                       $this->getResult()->addValue( 'limits', $this->getModuleName(), $limit );
+                       $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
                }
 
                if ( $enumRevMode ) {
@@ -318,7 +324,6 @@ class ApiQueryRevisions extends ApiQueryBase {
                $this->addOption( 'LIMIT', $limit + 1 );
                $this->addOption( 'USE INDEX', $index );
 
-               $data = array();
                $count = 0;
                $res = $this->select( __METHOD__ );
 
@@ -364,11 +369,17 @@ class ApiQueryRevisions extends ApiQueryBase {
                        $vals['minor'] = '';
                }
 
-               if ( $this->fld_user ) {
+               if ( $this->fld_user || $this->fld_userid ) {
                        if ( $revision->isDeleted( Revision::DELETED_USER ) ) {
                                $vals['userhidden'] = '';
                        } else {
-                               $vals['user'] = $revision->getUserText();
+                               if ( $this->fld_user ) {
+                                       $vals['user'] = $revision->getUserText();
+                               }
+                               if ( $this->fld_userid ) {
+                                       $user = User::newFromText( $revision->getUserText() );
+                                       $vals['userid'] = $user->getId();
+                               }
                                if ( !$revision->getUser() ) {
                                        $vals['anon'] = '';
                                }
@@ -388,7 +399,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                                $vals['commenthidden'] = '';
                        } else {
                                $comment = $revision->getComment();
-                               
+
                                if ( $this->fld_comment ) {
                                        $vals['comment'] = $comment;
                                }
@@ -411,9 +422,6 @@ class ApiQueryRevisions extends ApiQueryBase {
                }
 
                if ( !is_null( $this->token ) ) {
-                       // Don't cache tokens
-                       $this->getMain()->setCachePrivate();
-                       
                        $tokenFunctions = $this->getTokenFunctions();
                        foreach ( $this->token as $t ) {
                                $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
@@ -426,14 +434,13 @@ class ApiQueryRevisions extends ApiQueryBase {
                }
 
                $text = null;
+               global $wgParser;
                if ( $this->fld_content || !is_null( $this->difftotext ) ) {
                        $text = $revision->getText();
                        // Expand templates after getting section content because
                        // template-added sections don't count and Parser::preprocess()
                        // will have less input
                        if ( $this->section !== false ) {
-                               global $wgParser;
-
                                $text = $wgParser->getSection( $text, $this->section, false );
                                if ( $text === false ) {
                                        $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
@@ -442,7 +449,6 @@ class ApiQueryRevisions extends ApiQueryBase {
                }
                if ( $this->fld_content && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
                        if ( $this->generateXML ) {
-                               global $wgParser;
                                $wgParser->startExternalParse( $title, new ParserOptions(), OT_PREPROCESS );
                                $dom = $wgParser->preprocessToDom( $text );
                                if ( is_callable( array( $dom, 'saveXML' ) ) ) {
@@ -486,6 +492,17 @@ class ApiQueryRevisions extends ApiQueryBase {
                return $vals;
        }
 
+       public function getCacheMode( $params ) {
+               if ( isset( $params['token'] ) ) {
+                       return 'private';
+               }
+               if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
+                       // formatComment() calls wfMsg() among other things
+                       return 'anon-public-user-private';
+               }
+               return 'public';
+       }
+
        public function getAllowedParams() {
                return array(
                        'prop' => array(
@@ -496,6 +513,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                                        'flags',
                                        'timestamp',
                                        'user',
+                                       'userid',
                                        'size',
                                        'comment',
                                        'parsedcomment',
@@ -556,7 +574,8 @@ class ApiQueryRevisions extends ApiQueryBase {
                                ' ids            - The ID of the revision',
                                ' flags          - Revision flags (minor)',
                                ' timestamp      - The timestamp of the revision',
-                               ' user           - Gives user to make the revision',
+                               ' user           - User that made the revision',
+                               ' userid                 - User id of revision creator',
                                ' size           - Length of the revision',
                                ' comment        - Comment by the user for revision',
                                ' parsedcomment  - Parsed comment by the user for the revision',