From beb5c4c02696cc4b3b405bd8ce312fc76d2b9541 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 20 May 2007 08:34:47 +0000 Subject: [PATCH] API: * query=images - error when no valid pages * log - added proper showing of the patrol events * revisions - code cleanup --- includes/api/ApiQueryImages.php | 6 +++ includes/api/ApiQueryLogEvents.php | 67 +++++++++++++++++++++++------ includes/api/ApiQueryRevisions.php | 68 +++++++++++++++++++++--------- 3 files changed, 108 insertions(+), 33 deletions(-) diff --git a/includes/api/ApiQueryImages.php b/includes/api/ApiQueryImages.php index 7d0c756f4b..b2aef25cf0 100644 --- a/includes/api/ApiQueryImages.php +++ b/includes/api/ApiQueryImages.php @@ -47,6 +47,9 @@ class ApiQueryImages extends ApiQueryGeneratorBase { private function run($resultPageSet = null) { + if ($this->getPageSet()->getGoodTitleCount() == 0) + return; // nothing to do + $this->addFields(array ( 'il_from', 'il_to' @@ -73,6 +76,9 @@ class ApiQueryImages extends ApiQueryGeneratorBase { } $title = Title :: makeTitle(NS_IMAGE, $row->il_to); + // do not check userCanRead() -- page content is already accessible, + // and images are listed there. + $vals = array(); ApiQueryBase :: addTitleInfo($vals, $title); $data[] = $vals; diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 69af898f1c..df30c39c39 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -94,7 +94,7 @@ class ApiQueryLogEvents extends ApiQueryBase { break; } - $vals = $this->addRowInfo('log', $row); + $vals = $this->extractRowInfo($row); if($vals) $data[] = $vals; } @@ -104,22 +104,63 @@ class ApiQueryLogEvents extends ApiQueryBase { $this->getResult()->addValue('query', $this->getModuleName(), $data); } + private function extractRowInfo($row) { + $title = Title :: makeTitle($row->log_namespace, $row->log_title); + if (!$title->userCanRead()) + return false; + + $vals = array(); + + $vals['pageid'] = intval($row->page_id); + ApiQueryBase :: addTitleInfo($vals, $title); + $vals['type'] = $row->log_type; + $vals['action'] = $row->log_action; + + if ($row->log_params !== '') { + $params = explode("\n", $row->log_params); + switch ($row->log_type) { + case 'move': + if (isset ($params[0])) { + $title = Title :: newFromText($params[0]); + if ($title) { + ApiQueryBase :: addTitleInfo($vals, $title, "new_"); + $params = null; + } + } + break; + case 'patrol': + list( $cur, $prev, $auto ) = $params; + $vals['patrol_prev'] = $prev; + $vals['patrol_cur'] = $cur; + $vals['patrol_auto'] = $auto; + $params = null; + break; + } + + if (!empty ($params)) { + $this->getResult()->setIndexedTagName($params, 'param'); + $vals = array_merge($vals, $params); + } + } + + $vals['user'] = $row->user_name; + if(!$row->log_user) + $vals['anon'] = ''; + $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->log_timestamp); + + if (!empty ($row->log_comment)) + $vals['comment'] = $row->log_comment; + + return $vals; + } + + protected function getAllowedParams() { + global $wgLogTypes; return array ( 'type' => array ( ApiBase :: PARAM_ISMULTI => true, - ApiBase :: PARAM_TYPE => array ( - 'block', - 'protect', - 'rights', - 'delete', - 'upload', - 'move', - 'import', - 'renameuser', - 'newusers', - 'makebot' - ) + ApiBase :: PARAM_TYPE => $wgLogTypes ), 'start' => array ( ApiBase :: PARAM_TYPE => 'timestamp' diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 13ae6e56e0..c54250969f 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -37,6 +37,8 @@ class ApiQueryRevisions extends ApiQueryBase { parent :: __construct($query, $moduleName, 'rv'); } + private $fld_timestamp = false, $fld_comment = false, $fld_user = false, $fld_content = false; + public function execute() { $limit = $startid = $endid = $start = $end = $dir = $prop = $user = $excludeuser = null; extract($this->extractRequestParams()); @@ -70,15 +72,14 @@ class ApiQueryRevisions extends ApiQueryBase { )); $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'])); + $this->fld_timestamp = $this->addFieldsIf('rev_timestamp', isset ($prop['timestamp'])); + $this->fld_comment = $this->addFieldsIf('rev_comment', isset ($prop['comment'])); if (isset ($prop['user'])) { $this->addFields('rev_user'); $this->addFields('rev_user_text'); + $this->fld_user = true; } if (isset ($prop['content'])) { $this->addTables('text'); @@ -86,12 +87,12 @@ class ApiQueryRevisions extends ApiQueryBase { $this->addFields('old_id'); $this->addFields('old_text'); $this->addFields('old_flags'); - $showContent = true; + $this->fld_content = true; } } - $userMax = ($showContent ? 50 : 500); - $botMax = ($showContent ? 200 : 10000); + $userMax = ($this->fld_content ? 50 : 500); + $botMax = ($this->fld_content ? 200 : 10000); if ($enumRevMode) { @@ -171,19 +172,14 @@ class ApiQueryRevisions extends ApiQueryBase { break; } - $vals = $this->addRowInfo('rev', $row); - if ($vals) { - if ($showContent) - ApiResult :: setContent($vals, Revision :: getRevisionText($row)); - - $this->getResult()->addValue( - array ( - 'query', - 'pages', - intval($row->rev_page), - 'revisions'), - null, $vals); - } + $this->getResult()->addValue( + array ( + 'query', + 'pages', + intval($row->rev_page), + 'revisions'), + null, + $this->extractRowInfo($row)); } $db->freeResult($res); @@ -199,6 +195,38 @@ class ApiQueryRevisions extends ApiQueryBase { } } + private function extractRowInfo($row) { + + $vals = array (); + + $vals['revid'] = intval( $row->rev_id ); + $vals['pageid'] = intval($row->rev_page); + $vals['oldid'] = intval($row->rev_text_id); + + if ($row->rev_minor_edit) + $vals['minor'] = ''; + + if ($this->fld_user) { + $vals['user'] = $row->rev_user_text; + if (!$row->rev_user) + $vals['anon'] = ''; + } + + if ($this->fld_timestamp) { + $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rev_timestamp); + } + + if ($this->fld_comment && !empty ($row->rev_comment)) { + $vals['comment'] = $row->rev_comment; + } + + if ($this->fld_content) { + ApiResult :: setContent($vals, Revision :: getRevisionText($row)); + } + + return $vals; + } + protected function getAllowedParams() { return array ( 'prop' => array ( -- 2.20.1