r46842 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46841‎ | r46842 | r46843 >
Date:11:44, 5 February 2009
Author:catrope
Status:deferred (Comments)
Tags:
Comment:
* API: Listing (semi-)deleted revisions and log entries (with rev_/log_deleted != 0) as well in prop=revisions and list=logevents, with commenthidden/userhidden/actionhidden/texthidden flags where appropriate
* Still honors the paranoia checks added in r46807
* Use $index consistently in ApiQueryLogEvents
* Some whitespace consistency
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiPageSet.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryLogEvents.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryLogEvents.php
@@ -65,12 +65,13 @@
6666 array( 'log_namespace=page_namespace',
6767 'log_title=page_title'))));
6868 $this->addWhere('user_id=log_user');
69 - $this->addOption('USE INDEX', array('logging' => 'times')); // default, may change
 69+ $index = 'times'; // default, may change
7070
7171 $this->addFields(array (
7272 'log_type',
7373 'log_action',
7474 'log_timestamp',
 75+ 'log_deleted',
7576 ));
7677
7778 $this->addFieldsIf('log_id', $this->fld_ids);
@@ -81,12 +82,10 @@
8283 $this->addFieldsIf('log_title', $this->fld_title);
8384 $this->addFieldsIf('log_comment', $this->fld_comment);
8485 $this->addFieldsIf('log_params', $this->fld_details);
85 -
86 - $this->addWhereFld('log_deleted', 0);
8786
8887 if( !is_null($params['type']) ) {
8988 $this->addWhereFld('log_type', $params['type']);
90 - $this->addOption('USE INDEX', array('logging' => array('type_time')));
 89+ $index = 'type_time';
9190 }
9291
9392 $this->addWhereRange('log_timestamp', $params['dir'], $params['start'], $params['end']);
@@ -118,8 +117,14 @@
119118 if ( $index ) {
120119 $this->addOption( 'USE INDEX', array( 'logging' => $index ) );
121120 }
 121+ // Paranoia: avoid brute force searches (bug 17342)
 122+ if (!is_null($title) || !is_null($params['type'])) {
 123+ $this->addWhere('log_deleted & ' . LogPage::DELETED_ACTION . ' = 0');
 124+ }
 125+ if (!is_null($user)) {
 126+ $this->addWhere('log_deleted & ' . LogPage::DELETED_USER . ' = 0');
 127+ }
122128
123 -
124129 $data = array ();
125130 $count = 0;
126131 $res = $this->select(__METHOD__);
@@ -196,26 +201,42 @@
197202 }
198203
199204 if ($this->fld_type) {
200 - $vals['type'] = $row->log_type;
201 - $vals['action'] = $row->log_action;
 205+ if (LogEventsList::isDeleted($row, LogPage::DELETED_ACTION)) {
 206+ $vals['actionhidden'] = '';
 207+ } else {
 208+ $vals['type'] = $row->log_type;
 209+ $vals['action'] = $row->log_action;
 210+ }
202211 }
203212
204213 if ($this->fld_details && $row->log_params !== '') {
205 - self::addLogParams($this->getResult(), $vals,
206 - $row->log_params, $row->log_type,
207 - $row->log_timestamp);
 214+ if (LogEventsList::isDeleted($row, LogPage::DELETED_ACTION)) {
 215+ $vals['actionhidden'] = '';
 216+ } else {
 217+ self::addLogParams($this->getResult(), $vals,
 218+ $row->log_params, $row->log_type,
 219+ $row->log_timestamp);
 220+ }
208221 }
209222
210223 if ($this->fld_user) {
211 - $vals['user'] = $row->user_name;
212 - if(!$row->log_user)
213 - $vals['anon'] = '';
 224+ if (LogEventsList::isDeleted($row, LogPage::DELETED_USER)) {
 225+ $vals['userhidden'] = '';
 226+ } else {
 227+ $vals['user'] = $row->user_name;
 228+ if(!$row->log_user)
 229+ $vals['anon'] = '';
 230+ }
214231 }
215232 if ($this->fld_timestamp) {
216233 $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->log_timestamp);
217234 }
218235 if ($this->fld_comment && isset($row->log_comment)) {
219 - $vals['comment'] = $row->log_comment;
 236+ if (LogEventsList::isDeleted($row, LogPage::DELETED_COMMENT)) {
 237+ $vals['commenthidden'] = '';
 238+ } else {
 239+ $vals['comment'] = $row->log_comment;
 240+ }
220241 }
221242
222243 return $vals;
Index: trunk/phase3/includes/api/ApiPageSet.php
@@ -457,9 +457,9 @@
458458 $pageids = array();
459459 $remaining = array_flip($revids);
460460
461 - $tables = array('revision','page');
462 - $fields = array('rev_id','rev_page');
463 - $where = array('rev_deleted' => 0, 'rev_id' => $revids,'rev_page = page_id');
 461+ $tables = array('revision', 'page');
 462+ $fields = array('rev_id', 'rev_page');
 463+ $where = array('rev_id' => $revids, 'rev_page = page_id');
464464
465465 // Get pageIDs data from the `page` table
466466 $this->profileDBIn();
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -101,8 +101,8 @@
102102 $this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.', 'multpages');
103103
104104 $this->addTables('revision');
105 - $this->addFields( Revision::selectFields() );
106 - $this->addTables( 'page' );
 105+ $this->addFields(Revision::selectFields());
 106+ $this->addTables('page');
107107 $this->addWhere('page_id = rev_page');
108108
109109 $prop = array_flip($params['prop']);
@@ -134,7 +134,7 @@
135135 $this->addTables('text');
136136 $this->addWhere('rev_text_id=old_id');
137137 $this->addFields('old_id');
138 - $this->addFields( Revision::selectTextFields() );
 138+ $this->addFields(Revision::selectTextFields());
139139
140140 $this->fld_content = true;
141141
@@ -190,10 +190,14 @@
191191
192192 if(!is_null($params['user'])) {
193193 $this->addWhereFld('rev_user_text', $params['user']);
194 - } elseif (!is_null( $params['excludeuser'])) {
 194+ } elseif (!is_null($params['excludeuser'])) {
195195 $this->addWhere('rev_user_text != ' .
196196 $this->getDB()->addQuotes($params['excludeuser']));
197197 }
 198+ if(!is_null($params['user']) || !is_null($params['excludeuser'])) {
 199+ // Paranoia: avoid brute force searches (bug 17342)
 200+ $this->addWhere('rev_deleted & ' . Revision::DELETED_USER . ' = 0');
 201+ }
198202 }
199203 elseif ($revCount > 0) {
200204 $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
@@ -280,9 +284,13 @@
281285 $vals['minor'] = '';
282286
283287 if ($this->fld_user) {
284 - $vals['user'] = $revision->getUserText();
285 - if (!$revision->getUser())
286 - $vals['anon'] = '';
 288+ if ($revision->isDeleted(Revision::DELETED_USER)) {
 289+ $vals['userhidden'] = '';
 290+ } else {
 291+ $vals['user'] = $revision->getUserText();
 292+ if (!$revision->getUser())
 293+ $vals['anon'] = '';
 294+ }
287295 }
288296
289297 if ($this->fld_timestamp) {
@@ -294,9 +302,13 @@
295303 }
296304
297305 if ($this->fld_comment) {
298 - $comment = $revision->getComment();
299 - if (strval($comment) !== '')
300 - $vals['comment'] = $comment;
 306+ if ($revision->isDeleted(Revision::DELETED_COMMENT)) {
 307+ $vals['commenthidden'] = '';
 308+ } else {
 309+ $comment = $revision->getComment();
 310+ if (strval($comment) !== '')
 311+ $vals['comment'] = $comment;
 312+ }
301313 }
302314
303315 if(!is_null($this->token) || ($this->fld_content && $this->expandTemplates))
@@ -314,8 +326,8 @@
315327 $vals[$t . 'token'] = $val;
316328 }
317329 }
318 -
319 - if ($this->fld_content) {
 330+
 331+ if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
320332 global $wgParser;
321333 $text = $revision->getText();
322334 # Expand templates after getting section content because
@@ -341,6 +353,8 @@
342354 $text = $wgParser->preprocess( $text, $title, new ParserOptions() );
343355 }
344356 ApiResult :: setContent($vals, $text);
 357+ } else if ($this->fld_content) {
 358+ $vals['texthidden'] = '';
345359 }
346360 return $vals;
347361 }
Index: trunk/phase3/RELEASE-NOTES
@@ -163,6 +163,8 @@
164164 * (bug 17007) Added action=import
165165 * BREAKING CHANGE: Removed rctitles parameter from list=recentchanges because of
166166 performance concerns
 167+* Listing (semi-)deleted revisions and log entries as well in prop=revisions and
 168+ list=logevents
167169
168170 === Languages updated in 1.15 ===
169171

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r46807(bug 17342) Prevent deleted log item leaking (via slow brute-force)aaron18:54, 4 February 2009

Comments

#Comment by Aaron Schulz (talk | contribs)   14:43, 6 February 2009

Tweaks in r46917

Status & tagging log