break;
}
- $vals = $this->addRowInfo('log', $row);
+ $vals = $this->extractRowInfo($row);
if($vals)
$data[] = $vals;
}
$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'
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());
));
$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');
$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) {
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);
}
}
+ 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 (