Merge "API: Internationalize all remaining core API modules"
[lhc/web/wiklou.git] / includes / api / ApiQueryDeletedrevs.php
index 58db035..9d34724 100644 (file)
@@ -31,7 +31,7 @@
  */
 class ApiQueryDeletedrevs extends ApiQueryBase {
 
-       public function __construct( $query, $moduleName ) {
+       public function __construct( ApiQuery $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'dr' );
        }
 
@@ -61,6 +61,13 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                $fld_token = isset( $prop['token'] );
                $fld_tags = isset( $prop['tags'] );
 
+               if ( isset( $prop['token'] ) ) {
+                       $p = $this->getModulePrefix();
+                       $this->setWarning(
+                               "{$p}prop=token has been deprecated. Please use action=query&meta=tokens instead."
+                       );
+               }
+
                // If we're in JSON callback mode, no tokens can be obtained
                if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
                        $fld_token = false;
@@ -106,7 +113,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                }
 
                $this->addTables( 'archive' );
-               $this->addFields( array( 'ar_title', 'ar_namespace', 'ar_timestamp', 'ar_deleted' ) );
+               $this->addFields( array( 'ar_title', 'ar_namespace', 'ar_timestamp', 'ar_deleted', 'ar_id' ) );
 
                $this->addFieldsIf( 'ar_parent_id', $fld_parentid );
                $this->addFieldsIf( 'ar_rev_id', $fld_revid );
@@ -134,11 +141,17 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                }
 
                if ( $fld_content ) {
+                       // Modern MediaWiki has the content for deleted revs in the 'text'
+                       // table using fields old_text and old_flags. But revisions deleted
+                       // pre-1.5 store the content in the 'archive' table directly using
+                       // fields ar_text and ar_flags, and no corresponding 'text' row. So
+                       // we have to LEFT JOIN and fetch all four fields, plus ar_text_id
+                       // to be able to tell the difference.
                        $this->addTables( 'text' );
                        $this->addJoinConds(
-                               array( 'text' => array( 'INNER JOIN', array( 'ar_text_id=old_id' ) ) )
+                               array( 'text' => array( 'LEFT JOIN', array( 'ar_text_id=old_id' ) ) )
                        );
-                       $this->addFields( array( 'ar_text', 'ar_text_id', 'old_text', 'old_flags' ) );
+                       $this->addFields( array( 'ar_text', 'ar_flags', 'ar_text_id', 'old_text', 'old_flags' ) );
 
                        // This also means stricter restrictions
                        if ( !$user->isAllowedAny( 'undelete', 'deletedtext' ) ) {
@@ -204,7 +217,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                        // check it again just in case)
                        if ( !$user->isAllowed( 'deletedhistory' ) ) {
                                $bitmask = Revision::DELETED_USER;
-                       } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
+                       } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
                                $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
                        } else {
                                $bitmask = 0;
@@ -214,19 +227,33 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                        }
                }
 
-               if ( !is_null( $params['continue'] ) && ( $mode == 'all' || $mode == 'revs' ) ) {
+               if ( !is_null( $params['continue'] ) ) {
                        $cont = explode( '|', $params['continue'] );
-                       $this->dieContinueUsageIf( count( $cont ) != 3 );
-                       $ns = intval( $cont[0] );
-                       $this->dieContinueUsageIf( strval( $ns ) !== $cont[0] );
-                       $title = $db->addQuotes( $cont[1] );
-                       $ts = $db->addQuotes( $db->timestamp( $cont[2] ) );
                        $op = ( $dir == 'newer' ? '>' : '<' );
-                       $this->addWhere( "ar_namespace $op $ns OR " .
-                               "(ar_namespace = $ns AND " .
-                               "(ar_title $op $title OR " .
-                               "(ar_title = $title AND " .
-                               "ar_timestamp $op= $ts)))" );
+                       if ( $mode == 'all' || $mode == 'revs' ) {
+                               $this->dieContinueUsageIf( count( $cont ) != 4 );
+                               $ns = intval( $cont[0] );
+                               $this->dieContinueUsageIf( strval( $ns ) !== $cont[0] );
+                               $title = $db->addQuotes( $cont[1] );
+                               $ts = $db->addQuotes( $db->timestamp( $cont[2] ) );
+                               $ar_id = (int)$cont[3];
+                               $this->dieContinueUsageIf( strval( $ar_id ) !== $cont[3] );
+                               $this->addWhere( "ar_namespace $op $ns OR " .
+                                       "(ar_namespace = $ns AND " .
+                                       "(ar_title $op $title OR " .
+                                       "(ar_title = $title AND " .
+                                       "(ar_timestamp $op $ts OR " .
+                                       "(ar_timestamp = $ts AND " .
+                                       "ar_id $op= $ar_id)))))" );
+                       } else {
+                               $this->dieContinueUsageIf( count( $cont ) != 2 );
+                               $ts = $db->addQuotes( $db->timestamp( $cont[0] ) );
+                               $ar_id = (int)$cont[1];
+                               $this->dieContinueUsageIf( strval( $ar_id ) !== $cont[1] );
+                               $this->addWhere( "ar_timestamp $op $ts OR " .
+                                       "(ar_timestamp = $ts AND " .
+                                       "ar_id $op= $ar_id)" );
+                       }
                }
 
                $this->addOption( 'LIMIT', $limit + 1 );
@@ -236,12 +263,14 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                );
                if ( $mode == 'all' ) {
                        if ( $params['unique'] ) {
+                               // @todo Does this work on non-MySQL?
                                $this->addOption( 'GROUP BY', 'ar_title' );
                        } else {
                                $sort = ( $dir == 'newer' ? '' : ' DESC' );
                                $this->addOption( 'ORDER BY', array(
                                        'ar_title' . $sort,
-                                       'ar_timestamp' . $sort
+                                       'ar_timestamp' . $sort,
+                                       'ar_id' . $sort,
                                ) );
                        }
                } else {
@@ -251,6 +280,8 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                                $this->addWhereRange( 'ar_title', $dir, null, null );
                        }
                        $this->addTimestampWhereRange( 'ar_timestamp', $dir, $params['start'], $params['end'] );
+                       // Include in ORDER BY for uniqueness
+                       $this->addWhereRange( 'ar_id', $dir, null, null );
                }
                $res = $this->select( __METHOD__ );
                $pageMap = array(); // Maps ns&title to (fake) pageid
@@ -260,10 +291,11 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                        if ( ++$count > $limit ) {
                                // We've had enough
                                if ( $mode == 'all' || $mode == 'revs' ) {
-                                       $this->setContinueEnumParameter( 'continue', intval( $row->ar_namespace ) . '|' .
-                                               $row->ar_title . '|' . $row->ar_timestamp );
+                                       $this->setContinueEnumParameter( 'continue',
+                                               "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
+                                       );
                                } else {
-                                       $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->ar_timestamp ) );
+                                       $this->setContinueEnumParameter( 'continue', "$row->ar_timestamp|$row->ar_id" );
                                }
                                break;
                        }
@@ -334,7 +366,12 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                                        $anyHidden = true;
                                }
                                if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_TEXT, $user ) ) {
-                                       ApiResult::setContent( $rev, Revision::getRevisionText( $row ) );
+                                       if ( isset( $row->ar_text ) && !$row->ar_text_id ) {
+                                               // Pre-1.5 ar_text row (if condition from Revision::newFromArchiveRow)
+                                               ApiResult::setContent( $rev, Revision::getRevisionText( $row, 'ar_' ) );
+                                       } else {
+                                               ApiResult::setContent( $rev, Revision::getRevisionText( $row ) );
+                                       }
                                }
                        }
 
@@ -371,10 +408,11 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                        }
                        if ( !$fit ) {
                                if ( $mode == 'all' || $mode == 'revs' ) {
-                                       $this->setContinueEnumParameter( 'continue', intval( $row->ar_namespace ) . '|' .
-                                               $row->ar_title . '|' . $row->ar_timestamp );
+                                       $this->setContinueEnumParameter( 'continue',
+                                               "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
+                                       );
                                } else {
-                                       $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->ar_timestamp ) );
+                                       $this->setContinueEnumParameter( 'continue', "$row->ar_timestamp|$row->ar_id" );
                                }
                                break;
                        }
@@ -385,40 +423,46 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
        public function getAllowedParams() {
                return array(
                        'start' => array(
-                               ApiBase::PARAM_TYPE => 'timestamp'
+                               ApiBase::PARAM_TYPE => 'timestamp',
+                               ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 1, 2 ) ),
                        ),
                        'end' => array(
                                ApiBase::PARAM_TYPE => 'timestamp',
+                               ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 1, 2 ) ),
                        ),
                        'dir' => array(
                                ApiBase::PARAM_TYPE => array(
                                        'newer',
                                        'older'
                                ),
-                               ApiBase::PARAM_DFLT => 'older'
+                               ApiBase::PARAM_DFLT => 'older',
+                               ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
+                               ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 1, 3 ) ),
                        ),
-                       'from' => null,
-                       'to' => null,
-                       'prefix' => null,
-                       'continue' => null,
-                       'unique' => false,
-                       'tag' => null,
-                       'user' => array(
-                               ApiBase::PARAM_TYPE => 'user'
+                       'from' => array(
+                               ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 3 ) ),
                        ),
-                       'excludeuser' => array(
-                               ApiBase::PARAM_TYPE => 'user'
+                       'to' => array(
+                               ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 3 ) ),
+                       ),
+                       'prefix' => array(
+                               ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 3 ) ),
+                       ),
+                       'unique' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 3 ) ),
                        ),
                        'namespace' => array(
                                ApiBase::PARAM_TYPE => 'namespace',
                                ApiBase::PARAM_DFLT => NS_MAIN,
+                               ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 3 ) ),
                        ),
-                       'limit' => array(
-                               ApiBase::PARAM_DFLT => 10,
-                               ApiBase::PARAM_TYPE => 'limit',
-                               ApiBase::PARAM_MIN => 1,
-                               ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
-                               ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
+                       'tag' => null,
+                       'user' => array(
+                               ApiBase::PARAM_TYPE => 'user'
+                       ),
+                       'excludeuser' => array(
+                               ApiBase::PARAM_TYPE => 'user'
                        ),
                        'prop' => array(
                                ApiBase::PARAM_DFLT => 'user|comment',
@@ -438,103 +482,30 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                                ),
                                ApiBase::PARAM_ISMULTI => true
                        ),
-               );
-       }
-
-       public function getParamDescription() {
-               return array(
-                       'start' => 'The timestamp to start enumerating from (1, 2)',
-                       'end' => 'The timestamp to stop enumerating at (1, 2)',
-                       'dir' => $this->getDirectionDescription( $this->getModulePrefix(), ' (1, 3)' ),
-                       'from' => 'Start listing at this title (3)',
-                       'to' => 'Stop listing at this title (3)',
-                       'prefix' => 'Search for all page titles that begin with this value (3)',
-                       'limit' => 'The maximum amount of revisions to list',
-                       'prop' => array(
-                               'Which properties to get',
-                               ' revid          - Adds the revision ID of the deleted revision',
-                               ' parentid       - Adds the revision ID of the previous revision to the page',
-                               ' user           - Adds the user who made the revision',
-                               ' userid         - Adds the user ID whom made the revision',
-                               ' comment        - Adds the comment of the revision',
-                               ' parsedcomment  - Adds the parsed comment of the revision',
-                               ' minor          - Tags if the revision is minor',
-                               ' len            - Adds the length (bytes) of the revision',
-                               ' sha1           - Adds the SHA-1 (base 16) of the revision',
-                               ' content        - Adds the content of the revision',
-                               ' token          - Gives the edit token',
-                               ' tags           - Tags for the revision',
+                       'limit' => array(
+                               ApiBase::PARAM_DFLT => 10,
+                               ApiBase::PARAM_TYPE => 'limit',
+                               ApiBase::PARAM_MIN => 1,
+                               ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+                               ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
                        ),
-                       'namespace' => 'Only list pages in this namespace (3)',
-                       'user' => 'Only list revisions by this user',
-                       'excludeuser' => 'Don\'t list revisions by this user',
-                       'continue' => 'When more results are available, use this to continue (1, 3)',
-                       'unique' => 'List only one revision for each page (3)',
-                       'tag' => 'Only list revisions tagged with this tag',
-               );
-       }
-
-       public function getResultProperties() {
-               return array(
-                       '' => array(
-                               'ns' => 'namespace',
-                               'title' => 'string'
+                       'continue' => array(
+                               ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
                        ),
-                       'token' => array(
-                               'token' => 'string'
-                       )
-               );
-       }
-
-       public function getDescription() {
-               $p = $this->getModulePrefix();
-
-               return array(
-                       'List deleted revisions.',
-                       'Operates in three modes:',
-                       ' 1) List deleted revisions for the given title(s), sorted by timestamp.',
-                       ' 2) List deleted contributions for the given user, sorted by timestamp (no titles specified).',
-                       ' 3) List all deleted revisions in the given namespace, sorted by title and timestamp',
-                       "    (no titles specified, {$p}user not set).",
-                       'Certain parameters only apply to some modes and are ignored in others.',
-                       'For instance, a parameter marked (1) only applies to mode 1 and is ignored in modes 2 and 3.',
                );
        }
 
-       public function getPossibleErrors() {
-               return array_merge( parent::getPossibleErrors(), array(
-                       array(
-                               'code' => 'permissiondenied',
-                               'info' => 'You don\'t have permission to view deleted revision information'
-                       ),
-                       array( 'code' => 'badparams', 'info' => 'user and excludeuser cannot be used together'
-                       ),
-                       array(
-                               'code' => 'permissiondenied',
-                               'info' => 'You don\'t have permission to view deleted revision content'
-                       ),
-                       array( 'code' => 'badparams', 'info' => "The 'from' parameter cannot be used in modes 1 or 2" ),
-                       array( 'code' => 'badparams', 'info' => "The 'to' parameter cannot be used in modes 1 or 2" ),
-                       array(
-                               'code' => 'badparams',
-                               'info' => "The 'prefix' parameter cannot be used in modes 1 or 2"
-                       ),
-                       array( 'code' => 'badparams', 'info' => "The 'start' parameter cannot be used in mode 3" ),
-                       array( 'code' => 'badparams', 'info' => "The 'end' parameter cannot be used in mode 3" ),
-               ) );
-       }
-
-       public function getExamples() {
+       public function getExamplesMessages() {
                return array(
-                       'api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&' .
+                       'action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&' .
                                'drprop=user|comment|content'
-                               => 'List the last deleted revisions of Main Page and Talk:Main Page, with content (mode 1)',
-                       'api.php?action=query&list=deletedrevs&druser=Bob&drlimit=50'
-                               => 'List the last 50 deleted contributions by Bob (mode 2)',
-                       'api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50'
-                               => 'List the first 50 deleted revisions in the main namespace (mode 3)',
-                       'api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique='
-                               => 'List the first 50 deleted pages in the Talk namespace (mode 3):',
+                               => 'apihelp-query+deletedrevs-example-mode1',
+                       'action=query&list=deletedrevs&druser=Bob&drlimit=50'
+                               => 'apihelp-query+deletedrevs-example-mode2',
+                       'action=query&list=deletedrevs&drdir=newer&drlimit=50'
+                               => 'apihelp-query+deletedrevs-example-mode3-main',
+                       'action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique='
+                               => 'apihelp-query+deletedrevs-example-mode3-talk',
                );
        }