More parameter documentation
[lhc/web/wiklou.git] / includes / api / ApiQueryRevisions.php
index 77c41b9..64db5be 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * API for MediaWiki 1.8+
+ *
  *
  * Created on Sep 7, 2006
  *
@@ -38,6 +38,9 @@ if ( !defined( 'MEDIAWIKI' ) ) {
  */
 class ApiQueryRevisions extends ApiQueryBase {
 
+       private $diffto, $difftotext, $expandTemplates, $generateXML, $section,
+               $token;
+
        public function __construct( $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'rv' );
        }
@@ -46,6 +49,8 @@ class ApiQueryRevisions extends ApiQueryBase {
                        $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
                        $fld_content = false, $fld_tags = false;
 
+       private $tokenFunctions;
+
        protected function getTokenFunctions() {
                // tokenname => function
                // function prototype is func($pageid, $title, $rev)
@@ -68,6 +73,13 @@ class ApiQueryRevisions extends ApiQueryBase {
                return $this->tokenFunctions;
        }
 
+       /**
+        * @static
+        * @param $pageid
+        * @param $title Title
+        * @param $rev Revision
+        * @return bool|String
+        */
        public static function getRollbackToken( $pageid, $title, $rev ) {
                global $wgUser;
                if ( !$wgUser->isAllowed( 'rollback' ) ) {
@@ -107,7 +119,6 @@ class ApiQueryRevisions extends ApiQueryBase {
                        $this->dieUsage( 'titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.', 'multpages' );
                }
 
-               $this->diffto = $this->difftotext = null;
                if ( !is_null( $params['difftotext'] ) ) {
                        $this->difftotext = $params['difftotext'];
                } elseif ( !is_null( $params['diffto'] ) ) {
@@ -136,7 +147,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' );
 
@@ -157,6 +168,15 @@ class ApiQueryRevisions extends ApiQueryBase {
                // Possible indexes used
                $index = array();
 
+               $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()->setParsedLimit( $this->getModuleName(), $limit );
+               }
+
+
                if ( !is_null( $this->token ) || $pageCount > 0 ) {
                        $this->addFields( Revision::selectPageFields() );
                }
@@ -195,6 +215,15 @@ class ApiQueryRevisions extends ApiQueryBase {
 
                        $this->expandTemplates = $params['expandtemplates'];
                        $this->generateXML = $params['generatexml'];
+                       $this->parseContent = $params['parse'];
+                       if ( $this->parseContent ) {
+                               // Must manually initialize unset limit
+                               if ( is_null( $limit ) ) {
+                                       $limit = 1;
+                               }
+                               // We are only going to parse 1 revision per request
+                               $this->validateLimit( 'limit', $limit, 1, 1, 1 );
+                       }
                        if ( isset( $params['section'] ) ) {
                                $this->section = $params['section'];
                        } else {
@@ -202,13 +231,9 @@ class ApiQueryRevisions extends ApiQueryBase {
                        }
                }
 
-               $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()->setParsedLimit( $this->getModuleName(), $limit );
-               }
+               // Bug 24166 - API error when using rvprop=tags
+               $this->addTables( 'revision' );
+
 
                if ( $enumRevMode ) {
                        // This is mostly to prevent parameter errors (and optimize SQL?)
@@ -372,13 +397,15 @@ class ApiQueryRevisions extends ApiQueryBase {
                        } else {
                                if ( $this->fld_user ) {
                                        $vals['user'] = $revision->getUserText();
-                               } else {
-                                       $user = User::newFromText( $revision->getUserText() );
-                                       $vals['userid'] = $user->getId();
                                }
-                               if ( !$revision->getUser() ) {
+                               $userid = $revision->getUser();
+                               if ( !$userid ) {
                                        $vals['anon'] = '';
                                }
+
+                               if ( $this->fld_userid ) {
+                                       $vals['userid'] = $userid;
+                               }
                        }
                }
 
@@ -455,9 +482,15 @@ class ApiQueryRevisions extends ApiQueryBase {
                                $vals['parsetree'] = $xml;
 
                        }
-                       if ( $this->expandTemplates ) {
+                       if ( $this->expandTemplates && !$this->parseContent ) {
                                $text = $wgParser->preprocess( $text, $title, new ParserOptions() );
                        }
+                       if ( $this->parseContent ) {
+                               $articleObj = new Article( $title );
+
+                               $p_result = $articleObj->getParserOutput();
+                               $text = $p_result->getText();
+                       }
                        ApiResult::setContent( $vals, $text );
                } elseif ( $this->fld_content ) {
                        $vals['texthidden'] = '';
@@ -551,6 +584,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                        'tag' => null,
                        'expandtemplates' => false,
                        'generatexml' => false,
+                       'parse' => false,
                        'section' => null,
                        'token' => array(
                                ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
@@ -571,7 +605,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                                ' flags          - Revision flags (minor)',
                                ' timestamp      - The timestamp of the revision',
                                ' user           - User that made the revision',
-                               ' userid                 - User id of revision creator',
+                               ' 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',
@@ -588,6 +622,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                        'excludeuser' => 'Exclude revisions made by user',
                        'expandtemplates' => 'Expand templates in revision content',
                        'generatexml' => 'Generate XML parse tree for revision content',
+                       'parse' => 'Parse revision content. For performance reasons if this option is used, rvlimit is enforced to 1.',
                        'section' => 'Only retrieve the content of this section number',
                        'token' => 'Which tokens to obtain for each revision',
                        'continue' => 'When more results are available, use this to continue',