Index: trunk/phase3/includes/api/ApiQueryLogEvents.php |
— | — | @@ -40,11 +40,18 @@ |
41 | 41 | } |
42 | 42 | |
43 | 43 | public function execute() { |
44 | | - $limit = $type = $start = $end = $dir = $user = $title = null; |
45 | | - extract($this->extractRequestParams()); |
46 | | - |
| 44 | + $params = $this->extractRequestParams(); |
47 | 45 | $db = $this->getDB(); |
48 | 46 | |
| 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 | + |
49 | 56 | list($tbl_logging, $tbl_page, $tbl_user) = $db->tableNamesN('logging', 'page', 'user'); |
50 | 57 | |
51 | 58 | $this->addOption('STRAIGHT_JOIN'); |
— | — | @@ -56,20 +63,26 @@ |
57 | 64 | 'log_type', |
58 | 65 | 'log_action', |
59 | 66 | 'log_timestamp', |
60 | | - 'log_user', |
61 | | - 'user_name', |
62 | | - 'log_namespace', |
63 | | - 'log_title', |
64 | | - 'page_id', |
65 | | - 'log_comment', |
66 | | - 'log_params' |
67 | 67 | )); |
| 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 | + |
68 | 78 | |
69 | 79 | $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']; |
72 | 84 | $this->addOption('LIMIT', $limit +1); |
73 | 85 | |
| 86 | + $user = $params['user']; |
74 | 87 | if (!is_null($user)) { |
75 | 88 | $userid = $db->selectField('user', 'user_id', array ( |
76 | 89 | 'user_name' => $user |
— | — | @@ -79,6 +92,7 @@ |
80 | 93 | $this->addWhereFld('log_user', $userid); |
81 | 94 | } |
82 | 95 | |
| 96 | + $title = $params['title']; |
83 | 97 | if (!is_null($title)) { |
84 | 98 | $titleObj = Title :: newFromText($title); |
85 | 99 | if (is_null($titleObj)) |
— | — | @@ -110,46 +124,72 @@ |
111 | 125 | private function extractRowInfo($row) { |
112 | 126 | $vals = array(); |
113 | 127 | |
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 !== '') { |
121 | 144 | $params = explode("\n", $row->log_params); |
122 | 145 | switch ($row->log_type) { |
123 | 146 | case 'move': |
124 | 147 | if (isset ($params[0])) { |
125 | 148 | $title = Title :: newFromText($params[0]); |
126 | 149 | if ($title) { |
127 | | - ApiQueryBase :: addTitleInfo($vals, $title, "new_"); |
| 150 | + $vals2 = array(); |
| 151 | + ApiQueryBase :: addTitleInfo($vals2, $title, "new_"); |
| 152 | + $vals[$row->log_type] = $vals2; |
128 | 153 | $params = null; |
129 | 154 | } |
130 | 155 | } |
131 | 156 | break; |
132 | 157 | 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; |
137 | 161 | $params = null; |
138 | 162 | 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; |
139 | 175 | } |
140 | 176 | |
141 | | - if (!empty ($params)) { |
| 177 | + if (isset($params)) { |
142 | 178 | $this->getResult()->setIndexedTagName($params, 'param'); |
143 | 179 | $vals = array_merge($vals, $params); |
144 | 180 | } |
145 | 181 | } |
146 | 182 | |
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)) { |
153 | 192 | $vals['comment'] = $row->log_comment; |
| 193 | + } |
154 | 194 | |
155 | 195 | return $vals; |
156 | 196 | } |
— | — | @@ -158,6 +198,19 @@ |
159 | 199 | protected function getAllowedParams() { |
160 | 200 | global $wgLogTypes; |
161 | 201 | 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 | + ), |
162 | 215 | 'type' => array ( |
163 | 216 | ApiBase :: PARAM_ISMULTI => true, |
164 | 217 | ApiBase :: PARAM_TYPE => $wgLogTypes |