r24108 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24107‎ | r24108 | r24109 >
Date:06:26, 15 July 2007
Author:yurik
Status:old
Tags:
Comment:
API: improved list=logevents - added leprop, decoded some log types
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryLogEvents.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryLogEvents.php
@@ -40,11 +40,18 @@
4141 }
4242
4343 public function execute() {
44 - $limit = $type = $start = $end = $dir = $user = $title = null;
45 - extract($this->extractRequestParams());
46 -
 44+ $params = $this->extractRequestParams();
4745 $db = $this->getDB();
4846
 47+ $prop = $params['prop'];
 48+ $this->fld_ids = in_array('ids', $prop);
 49+ $this->fld_title = in_array('title', $prop);
 50+ $this->fld_type = in_array('type', $prop);
 51+ $this->fld_user = in_array('user', $prop);
 52+ $this->fld_timestamp = in_array('timestamp', $prop);
 53+ $this->fld_comment = in_array('comment', $prop);
 54+ $this->fld_details = in_array('details', $prop);
 55+
4956 list($tbl_logging, $tbl_page, $tbl_user) = $db->tableNamesN('logging', 'page', 'user');
5057
5158 $this->addOption('STRAIGHT_JOIN');
@@ -56,20 +63,26 @@
5764 'log_type',
5865 'log_action',
5966 'log_timestamp',
60 - 'log_user',
61 - 'user_name',
62 - 'log_namespace',
63 - 'log_title',
64 - 'page_id',
65 - 'log_comment',
66 - 'log_params'
6767 ));
 68+
 69+ $this->addFieldsIf('log_id', $this->fld_ids);
 70+ $this->addFieldsIf('page_id', $this->fld_ids);
 71+ $this->addFieldsIf('log_user', $this->fld_user);
 72+ $this->addFieldsIf('user_name', $this->fld_user);
 73+ $this->addFieldsIf('log_namespace', $this->fld_title);
 74+ $this->addFieldsIf('log_title', $this->fld_title);
 75+ $this->addFieldsIf('log_comment', $this->fld_comment);
 76+ $this->addFieldsIf('log_params', $this->fld_details);
 77+
6878
6979 $this->addWhereFld('log_deleted', 0);
70 - $this->addWhereFld('log_type', $type);
71 - $this->addWhereRange('log_timestamp', $dir, $start, $end);
 80+ $this->addWhereFld('log_type', $params['type']);
 81+ $this->addWhereRange('log_timestamp', $params['dir'], $params['start'], $params['end']);
 82+
 83+ $limit = $params['limit'];
7284 $this->addOption('LIMIT', $limit +1);
7385
 86+ $user = $params['user'];
7487 if (!is_null($user)) {
7588 $userid = $db->selectField('user', 'user_id', array (
7689 'user_name' => $user
@@ -79,6 +92,7 @@
8093 $this->addWhereFld('log_user', $userid);
8194 }
8295
 96+ $title = $params['title'];
8397 if (!is_null($title)) {
8498 $titleObj = Title :: newFromText($title);
8599 if (is_null($titleObj))
@@ -110,46 +124,72 @@
111125 private function extractRowInfo($row) {
112126 $vals = array();
113127
114 - $vals['pageid'] = intval($row->page_id);
115 - $title = Title :: makeTitle($row->log_namespace, $row->log_title);
116 - ApiQueryBase :: addTitleInfo($vals, $title);
117 - $vals['type'] = $row->log_type;
118 - $vals['action'] = $row->log_action;
119 -
120 - if ($row->log_params !== '') {
 128+ if ($this->fld_ids) {
 129+ $vals['logid'] = intval($row->log_id);
 130+ $vals['pageid'] = intval($row->page_id);
 131+ }
 132+
 133+ if ($this->fld_title) {
 134+ $title = Title :: makeTitle($row->log_namespace, $row->log_title);
 135+ ApiQueryBase :: addTitleInfo($vals, $title);
 136+ }
 137+
 138+ if ($this->fld_type) {
 139+ $vals['type'] = $row->log_type;
 140+ $vals['action'] = $row->log_action;
 141+ }
 142+
 143+ if ($this->fld_details && $row->log_params !== '') {
121144 $params = explode("\n", $row->log_params);
122145 switch ($row->log_type) {
123146 case 'move':
124147 if (isset ($params[0])) {
125148 $title = Title :: newFromText($params[0]);
126149 if ($title) {
127 - ApiQueryBase :: addTitleInfo($vals, $title, "new_");
 150+ $vals2 = array();
 151+ ApiQueryBase :: addTitleInfo($vals2, $title, "new_");
 152+ $vals[$row->log_type] = $vals2;
128153 $params = null;
129154 }
130155 }
131156 break;
132157 case 'patrol':
133 - list( $cur, $prev, $auto ) = $params;
134 - $vals['patrol_prev'] = $prev;
135 - $vals['patrol_cur'] = $cur;
136 - $vals['patrol_auto'] = $auto;
 158+ $vals2 = array();
 159+ list( $vals2['cur'], $vals2['prev'], $vals2['auto'] ) = $params;
 160+ $vals[$row->log_type] = $vals2;
137161 $params = null;
138162 break;
 163+ case 'rights':
 164+ $vals2 = array();
 165+ list( $vals2['old'], $vals2['new'] ) = $params;
 166+ $vals[$row->log_type] = $vals2;
 167+ $params = null;
 168+ break;
 169+ case 'block':
 170+ $vals2 = array();
 171+ list( $vals2['duration'], $vals2['flags'] ) = $params;
 172+ $vals[$row->log_type] = $vals2;
 173+ $params = null;
 174+ break;
139175 }
140176
141 - if (!empty ($params)) {
 177+ if (isset($params)) {
142178 $this->getResult()->setIndexedTagName($params, 'param');
143179 $vals = array_merge($vals, $params);
144180 }
145181 }
146182
147 - $vals['user'] = $row->user_name;
148 - if(!$row->log_user)
149 - $vals['anon'] = '';
150 - $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->log_timestamp);
151 -
152 - if (!empty ($row->log_comment))
 183+ if ($this->fld_user) {
 184+ $vals['user'] = $row->user_name;
 185+ if(!$row->log_user)
 186+ $vals['anon'] = '';
 187+ }
 188+ if ($this->fld_timestamp) {
 189+ $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->log_timestamp);
 190+ }
 191+ if ($this->fld_comment && !empty ($row->log_comment)) {
153192 $vals['comment'] = $row->log_comment;
 193+ }
154194
155195 return $vals;
156196 }
@@ -158,6 +198,19 @@
159199 protected function getAllowedParams() {
160200 global $wgLogTypes;
161201 return array (
 202+ 'prop' => array (
 203+ ApiBase :: PARAM_ISMULTI => true,
 204+ ApiBase :: PARAM_DFLT => 'ids|title|type|user|timestamp|comment|details',
 205+ ApiBase :: PARAM_TYPE => array (
 206+ 'ids',
 207+ 'title',
 208+ 'type',
 209+ 'user',
 210+ 'timestamp',
 211+ 'comment',
 212+ 'details',
 213+ )
 214+ ),
162215 'type' => array (
163216 ApiBase :: PARAM_ISMULTI => true,
164217 ApiBase :: PARAM_TYPE => $wgLogTypes

Follow-up revisions

RevisionCommit summaryAuthorDate
r24215Merged revisions 24095-24212 via svnmerge from...david21:19, 17 July 2007

Status & tagging log