diff options
author | Brad Jorsch <bjorsch@wikimedia.org> | 2019-08-21 15:53:53 -0400 |
---|---|---|
committer | Brad Jorsch <bjorsch@wikimedia.org> | 2020-02-04 13:36:14 -0500 |
commit | c2b15259081bdaa7cec892ba6b59c72b595254cc (patch) | |
tree | 118e61ce5eb79ba23f8603bbaa79d1ba14c8ef22 /includes/api/ApiQueryDeletedrevs.php | |
parent | 054dd94e97d679385c0a9c17297d089b5e1ff192 (diff) | |
download | mediawikicore-c2b15259081bdaa7cec892ba6b59c72b595254cc.tar.gz mediawikicore-c2b15259081bdaa7cec892ba6b59c72b595254cc.zip |
API: Use ParamValidator library
This brings significant modularization to the Action API's parameter
validation, and allows the Action API and MW REST API to share
validation code.
Note there are several changes in this patch that may affect other code;
see the entries in RELEASE-NOTES-1.35 for details.
Bug: T142080
Bug: T232672
Bug: T21195
Bug: T34675
Bug: T154774
Change-Id: I1462edc1701278760fa695308007006868b249fc
Depends-On: I10011be060fe6d27c7527312ad41218786b3f40d
Diffstat (limited to 'includes/api/ApiQueryDeletedrevs.php')
-rw-r--r-- | includes/api/ApiQueryDeletedrevs.php | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index 6b3cdf372c4e..01d48bc9bd13 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -21,9 +21,12 @@ */ use MediaWiki\MediaWikiServices; +use MediaWiki\ParamValidator\TypeDef\UserDef; use MediaWiki\Revision\RevisionRecord; use MediaWiki\Revision\SlotRecord; use MediaWiki\Storage\NameTableAccessException; +use Wikimedia\ParamValidator\ParamValidator; +use Wikimedia\ParamValidator\TypeDef\IntegerDef; /** * Query module to enumerate all deleted revisions. @@ -146,7 +149,15 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $this->getResult()->addParsedLimit( $this->getModuleName(), $limit ); } - $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax ); + $limit = $this->getMain()->getParamValidator()->validateValue( + $this, 'limit', $limit, [ + ParamValidator::PARAM_TYPE => 'limit', + IntegerDef::PARAM_MIN => 1, + IntegerDef::PARAM_MAX => $userMax, + IntegerDef::PARAM_MAX2 => $botMax, + IntegerDef::PARAM_IGNORE_RANGE => true, + ] + ); if ( $fld_token ) { // Undelete tokens are identical for all pages, so we cache one here @@ -181,14 +192,14 @@ class ApiQueryDeletedrevs extends ApiQueryBase { if ( $params['user'] !== null ) { // Don't query by user ID here, it might be able to use the ar_usertext_timestamp index. $actorQuery = ActorMigration::newMigration() - ->getWhere( $db, 'ar_user', User::newFromName( $params['user'], false ), false ); + ->getWhere( $db, 'ar_user', $params['user'], false ); $this->addTables( $actorQuery['tables'] ); $this->addJoinConds( $actorQuery['joins'] ); $this->addWhere( $actorQuery['conds'] ); } elseif ( $params['excludeuser'] !== null ) { // Here there's no chance of using ar_usertext_timestamp. $actorQuery = ActorMigration::newMigration() - ->getWhere( $db, 'ar_user', User::newFromName( $params['excludeuser'], false ) ); + ->getWhere( $db, 'ar_user', $params['excludeuser'] ); $this->addTables( $actorQuery['tables'] ); $this->addJoinConds( $actorQuery['joins'] ); $this->addWhere( 'NOT(' . $actorQuery['conds'] . ')' ); @@ -442,10 +453,14 @@ class ApiQueryDeletedrevs extends ApiQueryBase { ], 'tag' => null, 'user' => [ - ApiBase::PARAM_TYPE => 'user' + ApiBase::PARAM_TYPE => 'user', + UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip', 'id', 'interwiki' ], + UserDef::PARAM_RETURN_OBJECT => true, ], 'excludeuser' => [ - ApiBase::PARAM_TYPE => 'user' + ApiBase::PARAM_TYPE => 'user', + UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip', 'id', 'interwiki' ], + UserDef::PARAM_RETURN_OBJECT => true, ], 'prop' => [ ApiBase::PARAM_DFLT => 'user|comment', |