*API: rewired generator (more work needed)
[lhc/web/wiklou.git] / includes / api / ApiQueryRevisions.php
index 51270cb..dce0a8d 100644 (file)
@@ -31,24 +31,24 @@ if (!defined('MEDIAWIKI')) {
 
 class ApiQueryRevisions extends ApiQueryBase {
 
-       public function __construct($query, $moduleName, $generator = false) {
-               parent :: __construct($query, $moduleName, $generator);
+       public function __construct($query, $moduleName) {
+               parent :: __construct($query, $moduleName, 'rv');
        }
 
        public function execute() {
-               $rvlimit = $rvstartid = $rvendid = $rvstart = $rvend = $rvdir = $rvprop = null;
+               $limit = $startid = $endid = $start = $end = $dir = $prop = null;
                extract($this->extractRequestParams());
 
                $db = $this->getDB();
 
                // true when ordered by timestamp from older to newer, false otherwise
-               $dirNewer = ($rvdir === 'newer');
+               $dirNewer = ($dir === 'newer');
 
                // If any of those parameters are used, work in 'enumeration' mode.
                // Enum mode can only be used when exactly one page is provided.
                // Enumerating revisions on multiple pages make it extremelly 
                // difficult to manage continuations and require additional sql indexes  
-               $enumRevMode = ($rvlimit !== 0 || $rvstartid !== 0 || $rvendid !== 0 || $dirNewer || isset ($rvstart) || isset ($rvend));
+               $enumRevMode = ($limit !== 0 || $startid !== 0 || $endid !== 0 || $dirNewer || isset ($start) || isset ($end));
 
                $pageSet = $this->getPageSet();
                $pageCount = $pageSet->getGoodTitleCount();
@@ -59,13 +59,13 @@ class ApiQueryRevisions extends ApiQueryBase {
                        return;
 
                if ($revCount > 0 && $pageCount > 0)
-                       $this->dieUsage('The revids= parameter may not be used with titles, pageids, or generator options.', 'rv_revids');
+                       $this->dieUsage('The revids= parameter may not be used with titles, pageids, or generator options.', 'revids');
 
                if ($revCount > 0 && $enumRevMode)
-                       $this->dieUsage('The revids= parameter may not be used with the list options (rvlimit, rvstartid, rvendid, dirNewer, rvstart, rvend).', 'rv_revids');
+                       $this->dieUsage('The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids');
 
                if ($revCount === 0 && $pageCount > 1 && $enumRevMode)
-                       $this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the rvlimit, rvstartid, rvendid, dirNewer, rvstart, and rvend parameters may only be used on a single page.', 'rv_multpages');
+                       $this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, start, and end parameters may only be used on a single page.', 'multpages');
 
                $tables = array (
                        'revision'
@@ -82,9 +82,9 @@ class ApiQueryRevisions extends ApiQueryBase {
                $options = array ();
 
                $showTimestamp = $showUser = $showComment = $showContent = false;
-               if (isset ($rvprop)) {
-                       foreach ($rvprop as $prop) {
-                               switch ($prop) {
+               if (isset ($prop)) {
+                       foreach ($prop as $p) {
+                               switch ($p) {
                                        case 'timestamp' :
                                                $fields[] = 'rev_timestamp';
                                                $showTimestamp = true;
@@ -107,7 +107,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                                                $showContent = true;
                                                break;
                                        default :
-                                               ApiBase :: dieDebug(__METHOD__, "unknown rvprop $prop");
+                                               ApiBase :: dieDebug(__METHOD__, "unknown prop $p");
                                }
                        }
                }
@@ -118,11 +118,11 @@ class ApiQueryRevisions extends ApiQueryBase {
                if ($enumRevMode) {
 
                        // This is mostly to prevent parameter errors (and optimize sql?)
-                       if ($rvstartid !== 0 && isset ($rvstart))
-                               $this->dieUsage('rvstart and rvstartid cannot be used together', 'rv_badparams');
+                       if ($startid !== 0 && isset ($start))
+                               $this->dieUsage('start and startid cannot be used together', 'badparams');
 
-                       if ($rvendid !== 0 && isset ($rvend))
-                               $this->dieUsage('rvend and rvend cannot be used together', 'rv_badparams');
+                       if ($endid !== 0 && isset ($end))
+                               $this->dieUsage('end and endid cannot be used together', 'badparams');
 
                        // This code makes an assumption that sorting by rev_id and rev_timestamp produces
                        // the same result. This way users may request revisions starting at a given time,
@@ -130,25 +130,25 @@ class ApiQueryRevisions extends ApiQueryBase {
                        // Switching to rev_id removes the potential problem of having more than 
                        // one row with the same timestamp for the same page. 
                        // The order needs to be the same as start parameter to avoid SQL filesort.
-                       $options['ORDER BY'] = ($rvstartid !== 0 ? 'rev_id' : 'rev_timestamp') . ($dirNewer ? '' : ' DESC');
+                       $options['ORDER BY'] = ($startid !== 0 ? 'rev_id' : 'rev_timestamp') . ($dirNewer ? '' : ' DESC');
 
                        $before = ($dirNewer ? '<=' : '>=');
                        $after = ($dirNewer ? '>=' : '<=');
 
-                       if ($rvstartid !== 0)
-                               $conds[] = 'rev_id' . $after . intval($rvstartid);
-                       if ($rvendid !== 0)
-                               $conds[] = 'rev_id' . $before . intval($rvendid);
-                       if (isset ($rvstart))
-                               $conds[] = 'rev_timestamp' . $after . $db->addQuotes($rvstart);
-                       if (isset ($rvend))
-                               $conds[] = 'rev_timestamp' . $before . $db->addQuotes($rvend);
+                       if ($startid !== 0)
+                               $conds[] = 'rev_id' . $after . intval($startid);
+                       if ($endid !== 0)
+                               $conds[] = 'rev_id' . $before . intval($endid);
+                       if (isset ($start))
+                               $conds[] = 'rev_timestamp' . $after . $db->addQuotes($start);
+                       if (isset ($end))
+                               $conds[] = 'rev_timestamp' . $before . $db->addQuotes($end);
 
-                       // must manually initialize unset rvlimit
-                       if (!isset ($rvlimit))
-                               $rvlimit = 10;
+                       // must manually initialize unset limit
+                       if (!isset ($limit))
+                               $limit = 10;
 
-                       $this->validateLimit('rvlimit', $rvlimit, 1, $userMax, $botMax);
+                       $this->validateLimit($this->encodeParamName('limit'), $limit, 1, $userMax, $botMax);
 
                        // There is only one ID, use it
                        $conds['rev_page'] = array_pop(array_keys($pageSet->getGoodTitles()));
@@ -165,7 +165,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                        // Get all page IDs
                        $conds['page_id'] = array_keys($pageSet->getGoodTitles());
 
-                       $rvlimit = $pageCount; // assumption testing -- we should never get more then $pageCount rows.
+                       $limit = $pageCount; // assumption testing -- we should never get more then $pageCount rows.
                }
                elseif ($revCount > 0) {
                        $this->validateLimit('rev_count', $revCount, 1, $userMax, $botMax);
@@ -173,11 +173,11 @@ class ApiQueryRevisions extends ApiQueryBase {
                        // Get all revision IDs
                        $conds['rev_id'] = array_keys($pageSet->getRevisionIDs());
 
-                       $rvlimit = $revCount; // assumption testing -- we should never get more then $revCount rows.
+                       $limit = $revCount; // assumption testing -- we should never get more then $revCount rows.
                } else
                        ApiBase :: dieDebug(__METHOD__, 'param validation?');
 
-               $options['LIMIT'] = $rvlimit +1;
+               $options['LIMIT'] = $limit +1;
 
                $this->profileDBIn();
                $res = $db->select($tables, $fields, $conds, __METHOD__, $options);
@@ -187,12 +187,12 @@ class ApiQueryRevisions extends ApiQueryBase {
                $count = 0;
                while ($row = $db->fetchObject($res)) {
 
-                       if (++ $count > $rvlimit) {
+                       if (++ $count > $limit) {
                                // We've reached the one extra which shows that there are additional pages to be had. Stop here...
                                if (!$enumRevMode)
                                        ApiBase :: dieDebug(__METHOD__, 'Got more rows then expected'); // bug report
 
-                               $startStr = 'rvstartid=' . $row->rev_id;
+                               $startStr = 'startid=' . $row->rev_id;
                                $msg = array (
                                        'continue' => $startStr
                                );
@@ -243,7 +243,7 @@ class ApiQueryRevisions extends ApiQueryBase {
 
        protected function getAllowedParams() {
                return array (
-                       'rvprop' => array (
+                       'prop' => array (
                                ApiBase :: PARAM_ISMULTI => true,
                                ApiBase :: PARAM_TYPE => array (
                                        'timestamp',
@@ -252,22 +252,22 @@ class ApiQueryRevisions extends ApiQueryBase {
                                        'content'
                                )
                        ),
-                       'rvlimit' => array (
+                       'limit' => array (
                                ApiBase :: PARAM_DFLT => 0,
                                ApiBase :: PARAM_TYPE => 'limit',
                                ApiBase :: PARAM_MIN => 0,
                                ApiBase :: PARAM_MAX1 => 50,
                                ApiBase :: PARAM_MAX2 => 500
                        ),
-                       'rvstartid' => 0,
-                       'rvendid' => 0,
-                       'rvstart' => array (
+                       'startid' => 0,
+                       'endid' => 0,
+                       'start' => array (
                                ApiBase :: PARAM_TYPE => 'timestamp'
                        ),
-                       'rvend' => array (
+                       'end' => array (
                                ApiBase :: PARAM_TYPE => 'timestamp'
                        ),
-                       'rvdir' => array (
+                       'dir' => array (
                                ApiBase :: PARAM_DFLT => 'older',
                                ApiBase :: PARAM_TYPE => array (
                                        'newer',
@@ -279,13 +279,13 @@ class ApiQueryRevisions extends ApiQueryBase {
 
        protected function getParamDescription() {
                return array (
-                       'rvprop' => 'Which properties to get for each revision: user|timestamp|comment|content',
-                       'rvlimit' => 'limit how many revisions will be returned (enum)',
-                       'rvstartid' => 'from which revision id to start enumeration (enum)',
-                       'rvendid' => 'stop revision enumeration on this revid (enum)',
-                       'rvstart' => 'from which revision timestamp to start enumeration (enum)',
-                       'rvend' => 'enumerate up to this timestamp (enum)',
-                       'rvdir' => 'direction of enumeration - towards "newer" or "older" revisions (enum)'
+                       'prop' => 'Which properties to get for each revision: user|timestamp|comment|content',
+                       'limit' => 'limit how many revisions will be returned (enum)',
+                       'startid' => 'from which revision id to start enumeration (enum)',
+                       'endid' => 'stop revision enumeration on this revid (enum)',
+                       'start' => 'from which revision timestamp to start enumeration (enum)',
+                       'end' => 'enumerate up to this timestamp (enum)',
+                       'dir' => 'direction of enumeration - towards "newer" or "older" revisions (enum)'
                );
        }
 
@@ -294,7 +294,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                        'Get revision information.',
                        'This module may be used in several ways:',
                        ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter.',
-                       ' 2) Get revisions for one given page, by using titles/pageids with rvstart/rvend/rvlimit params.',
+                       ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params.',
                        ' 3) Get data about a set of revisions by setting their IDs with revids parameter.',
                        'All parameters marked as (enum) may only be used with a single page (#2).'
                );