From a58285fd06c8113c45377c655dd43cef6337e815 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 11 Jan 2007 19:06:07 +0000 Subject: Aktualisierung auf MediaWiki 1.9.0 --- includes/api/ApiQueryRevisions.php | 194 ++++++++++++++----------------------- 1 file changed, 71 insertions(+), 123 deletions(-) (limited to 'includes/api/ApiQueryRevisions.php') diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index f6097bad..3f678ff7 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -39,16 +39,11 @@ class ApiQueryRevisions extends ApiQueryBase { $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 = ($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 = ($limit !== 0 || $startid !== 0 || $endid !== 0 || $dirNewer || isset ($start) || isset ($end)); + $enumRevMode = (!is_null($limit) || !is_null($startid) || !is_null($endid) || $dir === 'newer' || !is_null($start) || !is_null($end)); $pageSet = $this->getPageSet(); $pageCount = $pageSet->getGoodTitleCount(); @@ -58,57 +53,38 @@ class ApiQueryRevisions extends ApiQueryBase { if ($revCount === 0 && $pageCount === 0) return; - if ($revCount > 0 && $pageCount > 0) - $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 (limit, startid, endid, dirNewer, start, end).', 'revids'); - if ($revCount === 0 && $pageCount > 1 && $enumRevMode) + if ($pageCount > 1 && $enumRevMode) $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' - ); - $fields = array ( + $this->addTables('revision'); + $this->addFields(array ( 'rev_id', 'rev_page', 'rev_text_id', 'rev_minor_edit' - ); - $conds = array ( - 'rev_deleted' => 0 - ); - $options = array (); - - $showTimestamp = $showUser = $showComment = $showContent = false; - if (isset ($prop)) { - foreach ($prop as $p) { - switch ($p) { - case 'timestamp' : - $fields[] = 'rev_timestamp'; - $showTimestamp = true; - break; - case 'user' : - $fields[] = 'rev_user'; - $fields[] = 'rev_user_text'; - $showUser = true; - break; - case 'comment' : - $fields[] = 'rev_comment'; - $showComment = true; - break; - case 'content' : - $tables[] = 'text'; - $conds[] = 'rev_text_id=old_id'; - $fields[] = 'old_id'; - $fields[] = 'old_text'; - $fields[] = 'old_flags'; - $showContent = true; - break; - default : - ApiBase :: dieDebug(__METHOD__, "unknown prop $p"); - } + )); + $this->addWhere('rev_deleted=0'); + + $showContent = false; + + if (!is_null($prop)) { + $prop = array_flip($prop); + $this->addFieldsIf('rev_timestamp', isset ($prop['timestamp'])); + $this->addFieldsIf('rev_comment', isset ($prop['comment'])); + if (isset ($prop['user'])) { + $this->addFields('rev_user'); + $this->addFields('rev_user_text'); + } + if (isset ($prop['content'])) { + $this->addTables('text'); + $this->addWhere('rev_text_id=old_id'); + $this->addFields('old_id'); + $this->addFields('old_text'); + $this->addFields('old_flags'); + $showContent = true; } } @@ -118,10 +94,10 @@ class ApiQueryRevisions extends ApiQueryBase { if ($enumRevMode) { // This is mostly to prevent parameter errors (and optimize sql?) - if ($startid !== 0 && isset ($start)) + if (!is_null($startid) && !is_null($start)) $this->dieUsage('start and startid cannot be used together', 'badparams'); - if ($endid !== 0 && isset ($end)) + if (!is_null($endid) && !is_null($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 @@ -130,40 +106,30 @@ 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'] = ($startid !== 0 ? 'rev_id' : 'rev_timestamp') . ($dirNewer ? '' : ' DESC'); - - $before = ($dirNewer ? '<=' : '>='); - $after = ($dirNewer ? '>=' : '<='); - 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); + if (is_null($startid)) + $this->addWhereRange('rev_timestamp', $dir, $start, $end); + else + $this->addWhereRange('rev_id', $dir, $startid, $endid); // must manually initialize unset limit - if (!isset ($limit)) + if (is_null($limit)) $limit = 10; - $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())); - + $this->addWhereFld('rev_page', current(array_keys($pageSet->getGoodTitles()))); } elseif ($pageCount > 0) { // When working in multi-page non-enumeration mode, // limit to the latest revision only - $tables[] = 'page'; - $conds[] = 'page_id=rev_page'; - $conds[] = 'page_latest=rev_id'; + $this->addTables('page'); + $this->addWhere('page_id=rev_page'); + $this->addWhere('page_latest=rev_id'); $this->validateLimit('page_count', $pageCount, 1, $userMax, $botMax); // Get all page IDs - $conds['page_id'] = array_keys($pageSet->getGoodTitles()); + $this->addWhereFld('page_id', array_keys($pageSet->getGoodTitles())); $limit = $pageCount; // assumption testing -- we should never get more then $pageCount rows. } @@ -171,72 +137,51 @@ class ApiQueryRevisions extends ApiQueryBase { $this->validateLimit('rev_count', $revCount, 1, $userMax, $botMax); // Get all revision IDs - $conds['rev_id'] = array_keys($pageSet->getRevisionIDs()); + $this->addWhereFld('rev_id', array_keys($pageSet->getRevisionIDs())); $limit = $revCount; // assumption testing -- we should never get more then $revCount rows. } else ApiBase :: dieDebug(__METHOD__, 'param validation?'); - $options['LIMIT'] = $limit +1; - - $this->profileDBIn(); - $res = $db->select($tables, $fields, $conds, __METHOD__, $options); - $this->profileDBOut(); + $this->addOption('LIMIT', $limit +1); $data = array (); $count = 0; + $res = $this->select(__METHOD__); + + $db = & $this->getDB(); while ($row = $db->fetchObject($res)) { 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 = 'startid=' . $row->rev_id; - $msg = array ( - 'continue' => $startStr - ); - $this->getResult()->addValue('query-status', 'revisions', $msg); + $this->setContinueEnumParameter('startid', $row->rev_id); break; } - $vals = array ( - 'revid' => intval($row->rev_id - ), 'oldid' => intval($row->rev_text_id)); - - if ($row->rev_minor_edit) { - $vals['minor'] = ''; - } - - if ($showTimestamp) - $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rev_timestamp); - - if ($showUser) { - $vals['user'] = $row->rev_user_text; - if (!$row->rev_user) - $vals['anon'] = ''; - } - - if ($showComment) - $vals['comment'] = $row->rev_comment; + $vals = $this->addRowInfo('rev', $row); + if ($vals) { + if ($showContent) + ApiResult :: setContent($vals, Revision :: getRevisionText($row)); - if ($showContent) { - ApiResult :: setContent($vals, Revision :: getRevisionText($row)); + $this->getResult()->addValue(array ( + 'query', + 'pages', + intval($row->rev_page + ), 'revisions'), intval($row->rev_id), $vals); } - - $this->getResult()->addValue(array ( - 'query', - 'pages', - intval($row->rev_page - ), 'revisions'), intval($row->rev_id), $vals); } $db->freeResult($res); - // Ensure that all revisions are shown as '' elements - $data = & $this->getResultData(); - foreach ($data['query']['pages'] as & $page) { - if (is_array($page) && array_key_exists('revisions', $page)) { - ApiResult :: setIndexedTagName($page['revisions'], 'rev'); + // Ensure that all revisions are shown as '' elements + $result = $this->getResult(); + if ($result->getIsRawMode()) { + $data = $result->getData(); + foreach ($data['query']['pages'] as & $page) { + if (is_array($page) && array_key_exists('revisions', $page)) { + $result->setIndexedTagName($page['revisions'], 'rev'); + } } } } @@ -253,14 +198,17 @@ class ApiQueryRevisions extends ApiQueryBase { ) ), 'limit' => array ( - ApiBase :: PARAM_DFLT => 0, ApiBase :: PARAM_TYPE => 'limit', - ApiBase :: PARAM_MIN => 0, - ApiBase :: PARAM_MAX1 => 50, - ApiBase :: PARAM_MAX2 => 500 + ApiBase :: PARAM_MIN => 1, + ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_SML1, + ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_SML2 + ), + 'startid' => array ( + ApiBase :: PARAM_TYPE => 'integer' + ), + 'endid' => array ( + ApiBase :: PARAM_TYPE => 'integer' ), - 'startid' => 0, - 'endid' => 0, 'start' => array ( ApiBase :: PARAM_TYPE => 'timestamp' ), @@ -279,7 +227,7 @@ class ApiQueryRevisions extends ApiQueryBase { protected function getParamDescription() { return array ( - 'prop' => 'Which properties to get for each revision: user|timestamp|comment|content', + 'prop' => 'Which properties to get for each revision.', '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)', @@ -314,7 +262,7 @@ class ApiQueryRevisions extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryRevisions.php 16757 2006-10-03 05:41:55Z yurik $'; + return __CLASS__ . ': $Id: ApiQueryRevisions.php 17374 2006-11-03 06:53:47Z yurik $'; } } -?> \ No newline at end of file +?> -- cgit v1.2.3-54-g00ecf