* API: Listing (semi-)deleted revisions and log entries (with rev_/log_deleted !...
authorRoan Kattouw <catrope@users.mediawiki.org>
Thu, 5 Feb 2009 11:44:10 +0000 (11:44 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Thu, 5 Feb 2009 11:44:10 +0000 (11:44 +0000)
* Still honors the paranoia checks added in r46807
* Use $index consistently in ApiQueryLogEvents
* Some whitespace consistency

RELEASE-NOTES
includes/api/ApiPageSet.php
includes/api/ApiQueryLogEvents.php
includes/api/ApiQueryRevisions.php

index 1715468..8de4829 100644 (file)
@@ -163,6 +163,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 17007) Added action=import
 * BREAKING CHANGE: Removed rctitles parameter from list=recentchanges because of
   performance concerns
+* Listing (semi-)deleted revisions and log entries as well in prop=revisions and
+  list=logevents
 
 === Languages updated in 1.15 ===
 
index b6b43cb..a9724d3 100644 (file)
@@ -457,9 +457,9 @@ class ApiPageSet extends ApiQueryBase {
                $pageids = array();
                $remaining = array_flip($revids);
 
-               $tables = array('revision','page');
-               $fields = array('rev_id','rev_page');
-               $where = array('rev_deleted' => 0, 'rev_id' => $revids,'rev_page = page_id');
+               $tables = array('revision', 'page');
+               $fields = array('rev_id', 'rev_page');
+               $where = array('rev_id' => $revids, 'rev_page = page_id');
 
                // Get pageIDs data from the `page` table
                $this->profileDBIn();
index beb2963..f745894 100644 (file)
@@ -65,12 +65,13 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                array(  'log_namespace=page_namespace',
                                        'log_title=page_title'))));
                $this->addWhere('user_id=log_user');
-               $this->addOption('USE INDEX', array('logging' => 'times')); // default, may change
+               $index = 'times'; // default, may change
 
                $this->addFields(array (
                        'log_type',
                        'log_action',
                        'log_timestamp',
+                       'log_deleted',
                ));
 
                $this->addFieldsIf('log_id', $this->fld_ids);
@@ -81,12 +82,10 @@ class ApiQueryLogEvents extends ApiQueryBase {
                $this->addFieldsIf('log_title', $this->fld_title);
                $this->addFieldsIf('log_comment', $this->fld_comment);
                $this->addFieldsIf('log_params', $this->fld_details);
-
-               $this->addWhereFld('log_deleted', 0);
                
                if( !is_null($params['type']) ) {
                        $this->addWhereFld('log_type', $params['type']);
-                       $this->addOption('USE INDEX', array('logging' => array('type_time')));
+                       $index = 'type_time';
                }
                
                $this->addWhereRange('log_timestamp', $params['dir'], $params['start'], $params['end']);
@@ -118,7 +117,13 @@ class ApiQueryLogEvents extends ApiQueryBase {
                if ( $index ) {
                        $this->addOption( 'USE INDEX', array( 'logging' => $index ) );
                }
-
+               // Paranoia: avoid brute force searches (bug 17342)
+               if (!is_null($title) || !is_null($params['type'])) {
+                       $this->addWhere('log_deleted & ' . LogPage::DELETED_ACTION . ' = 0');
+               }
+               if (!is_null($user)) {
+                       $this->addWhere('log_deleted & ' . LogPage::DELETED_USER . ' = 0');
+               }
 
                $data = array ();
                $count = 0;
@@ -196,26 +201,42 @@ class ApiQueryLogEvents extends ApiQueryBase {
                }
 
                if ($this->fld_type) {
-                       $vals['type'] = $row->log_type;
-                       $vals['action'] = $row->log_action;
+                       if (LogEventsList::isDeleted($row, LogPage::DELETED_ACTION)) {
+                               $vals['actionhidden'] = '';
+                       } else {
+                               $vals['type'] = $row->log_type;
+                               $vals['action'] = $row->log_action;
+                       }
                }
 
                if ($this->fld_details && $row->log_params !== '') {
-                       self::addLogParams($this->getResult(), $vals,
-                               $row->log_params, $row->log_type,
-                               $row->log_timestamp);
+                       if (LogEventsList::isDeleted($row, LogPage::DELETED_ACTION)) {
+                               $vals['actionhidden'] = '';
+                       } else {
+                               self::addLogParams($this->getResult(), $vals,
+                                       $row->log_params, $row->log_type,
+                                       $row->log_timestamp);
+                       }
                }
 
                if ($this->fld_user) {
-                       $vals['user'] = $row->user_name;
-                       if(!$row->log_user)
-                               $vals['anon'] = '';
+                       if (LogEventsList::isDeleted($row, LogPage::DELETED_USER)) {
+                               $vals['userhidden'] = '';
+                       } else {
+                               $vals['user'] = $row->user_name;
+                               if(!$row->log_user)
+                                       $vals['anon'] = '';
+                       }
                }
                if ($this->fld_timestamp) {
                        $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->log_timestamp);
                }
                if ($this->fld_comment && isset($row->log_comment)) {
-                       $vals['comment'] = $row->log_comment;
+                       if (LogEventsList::isDeleted($row, LogPage::DELETED_COMMENT)) {
+                               $vals['commenthidden'] = '';
+                       } else {
+                               $vals['comment'] = $row->log_comment;
+                       }
                }
 
                return $vals;
index af2afdc..258f460 100644 (file)
@@ -101,8 +101,8 @@ class ApiQueryRevisions extends ApiQueryBase {
                        $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');
 
                $this->addTables('revision');
-               $this->addFields( Revision::selectFields() );
-               $this->addTables( 'page' );
+               $this->addFields(Revision::selectFields());
+               $this->addTables('page');
                $this->addWhere('page_id = rev_page');
 
                $prop = array_flip($params['prop']);
@@ -134,7 +134,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                        $this->addTables('text');
                        $this->addWhere('rev_text_id=old_id');
                        $this->addFields('old_id');
-                       $this->addFields( Revision::selectTextFields() );
+                       $this->addFields(Revision::selectTextFields());
 
                        $this->fld_content = true;
 
@@ -190,10 +190,14 @@ class ApiQueryRevisions extends ApiQueryBase {
 
                        if(!is_null($params['user'])) {
                                $this->addWhereFld('rev_user_text', $params['user']);
-                       } elseif (!is_null( $params['excludeuser'])) {
+                       } elseif (!is_null($params['excludeuser'])) {
                                $this->addWhere('rev_user_text != ' .
                                        $this->getDB()->addQuotes($params['excludeuser']));
                        }
+                       if(!is_null($params['user']) || !is_null($params['excludeuser'])) {
+                               // Paranoia: avoid brute force searches (bug 17342)
+                               $this->addWhere('rev_deleted & ' . Revision::DELETED_USER . ' = 0');
+                       }
                }
                elseif ($revCount > 0) {
                        $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
@@ -280,9 +284,13 @@ class ApiQueryRevisions extends ApiQueryBase {
                        $vals['minor'] = '';
 
                if ($this->fld_user) {
-                       $vals['user'] = $revision->getUserText();
-                       if (!$revision->getUser())
-                               $vals['anon'] = '';
+                       if ($revision->isDeleted(Revision::DELETED_USER)) {
+                               $vals['userhidden'] = '';
+                       } else {
+                               $vals['user'] = $revision->getUserText();
+                               if (!$revision->getUser())
+                                       $vals['anon'] = '';
+                       }
                }
 
                if ($this->fld_timestamp) {
@@ -294,9 +302,13 @@ class ApiQueryRevisions extends ApiQueryBase {
                }
 
                if ($this->fld_comment) {
-                       $comment = $revision->getComment();
-                       if (strval($comment) !== '')
-                               $vals['comment'] = $comment;
+                       if ($revision->isDeleted(Revision::DELETED_COMMENT)) {
+                               $vals['commenthidden'] = '';
+                       } else {
+                               $comment = $revision->getComment();
+                               if (strval($comment) !== '')
+                                       $vals['comment'] = $comment;
+                       }
                }
 
                if(!is_null($this->token) || ($this->fld_content && $this->expandTemplates))
@@ -314,8 +326,8 @@ class ApiQueryRevisions extends ApiQueryBase {
                                        $vals[$t . 'token'] = $val;
                        }
                }
-
-               if ($this->fld_content) {
+               
+               if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
                        global $wgParser;
                        $text = $revision->getText();
                        # Expand templates after getting section content because
@@ -341,6 +353,8 @@ class ApiQueryRevisions extends ApiQueryBase {
                                $text = $wgParser->preprocess( $text, $title, new ParserOptions() );
                        }
                        ApiResult :: setContent($vals, $text);
+               } else if ($this->fld_content) {
+                       $vals['texthidden'] = '';
                }
                return $vals;
        }