API: Really fixing bug 10898 this time
[lhc/web/wiklou.git] / includes / api / ApiQueryRevisions.php
index 7a50400..dc63c20 100644 (file)
@@ -41,7 +41,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                parent :: __construct($query, $moduleName, 'rv');
        }
 
-       private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, 
+       private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false,
                        $fld_comment = false, $fld_user = false, $fld_content = false;
 
        public function execute() {
@@ -83,6 +83,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                $this->fld_flags = $this->addFieldsIf('rev_minor_edit', isset ($prop['flags']));
                $this->fld_timestamp = $this->addFieldsIf('rev_timestamp', isset ($prop['timestamp']));
                $this->fld_comment = $this->addFieldsIf('rev_comment', isset ($prop['comment']));
+               $this->fld_size = $this->addFieldsIf('rev_len', isset ($prop['size']));
 
                if (isset ($prop['user'])) {
                        $this->addFields('rev_user');
@@ -90,6 +91,15 @@ class ApiQueryRevisions extends ApiQueryBase {
                        $this->fld_user = true;
                }
                if (isset ($prop['content'])) {
+
+                       // For each page we will request, the user must have read rights for that page
+                       foreach ($pageSet->getGoodTitles() as $title) {
+                               if( !$title->userCanRead() )
+                                       $this->dieUsage(
+                                               'The current user is not allowed to read ' . $title->getPrefixedText(),
+                                               'accessdenied');
+                       }
+
                        $this->addTables('text');
                        $this->addWhere('rev_text_id=old_id');
                        $this->addFields('old_id');
@@ -128,13 +138,13 @@ class ApiQueryRevisions extends ApiQueryBase {
                        // must manually initialize unset limit
                        if (is_null($limit))
                                $limit = 10;
-                       $this->validateLimit($this->encodeParamName('limit'), $limit, 1, $userMax, $botMax);
+                       $this->validateLimit('limit', $limit, 1, $userMax, $botMax);
 
                        // There is only one ID, use it
                        $this->addWhereFld('rev_page', current(array_keys($pageSet->getGoodTitles())));
-
+                       
                        if(!is_null($user)) {
-                               $this->addWhere('rev_user_text', $user);
+                               $this->addWhereFld('rev_user_text', $user);
                        } elseif (!is_null( $excludeuser)) {
                                $this->addWhere('rev_user_text != ' . $this->getDB()->addQuotes($excludeuser));
                        }
@@ -210,7 +220,6 @@ class ApiQueryRevisions extends ApiQueryBase {
 
                if ($this->fld_ids) {
                        $vals['revid'] = intval($row->rev_id);
-                       $vals['pageid'] = intval($row->rev_page);
                        // $vals['oldid'] = intval($row->rev_text_id);  // todo: should this be exposed?
                }
                
@@ -227,6 +236,10 @@ class ApiQueryRevisions extends ApiQueryBase {
                        $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rev_timestamp);
                }
                
+               if ($this->fld_size && !is_null($row->rev_len)) {
+                       $vals['size'] = intval($row->rev_len);
+               }
+
                if ($this->fld_comment && !empty ($row->rev_comment)) {
                        $vals['comment'] = $row->rev_comment;
                }
@@ -248,8 +261,9 @@ class ApiQueryRevisions extends ApiQueryBase {
                                        'flags',
                                        'timestamp',
                                        'user',
+                                       'size',
                                        'comment',
-                                       'content'
+                                       'content',
                                )
                        ),
                        'limit' => array (
@@ -332,4 +346,4 @@ class ApiQueryRevisions extends ApiQueryBase {
                return __CLASS__ . ': $Id$';
        }
 }
-?>
+