From 8b466d3d0dfca51b86081b68a5b8c86ae18b4c56 Mon Sep 17 00:00:00 2001 From: X! Date: Wed, 4 Aug 2010 14:15:33 +0000 Subject: [PATCH] Followup to r70460: Committed wrong version of ApiBase.php, convert all core API modules to PARAM_REQUIRED syntax --- includes/api/ApiBase.php | 2 +- includes/api/ApiBlock.php | 8 ++++---- includes/api/ApiEditPage.php | 9 ++++----- includes/api/ApiEmailUser.php | 17 ++++++++--------- includes/api/ApiMove.php | 8 ++++---- includes/api/ApiPatrol.php | 7 ++----- includes/api/ApiProtect.php | 14 ++++++-------- includes/api/ApiPurge.php | 6 ++---- includes/api/ApiQueryBacklinks.php | 7 ++++--- includes/api/ApiRollback.php | 17 ++++++++--------- includes/api/ApiUndelete.php | 8 ++++---- includes/api/ApiUpload.php | 9 ++++----- includes/api/ApiUserrights.php | 8 ++++---- 13 files changed, 55 insertions(+), 65 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 099d6f5bad..a1bb693562 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -503,7 +503,7 @@ abstract class ApiBase { $allparams = $this->getAllowedParams(); foreach( $this->mParamCache[$parseLimit] as $param => $val ) { - if( !isset( $allparams[$param][ApiBase::PARAM_REQUIRED] ) ) { + if( isset( $allparams[$param][ApiBase::PARAM_REQUIRED] ) && !isset( $val ) ) { $this->dieUsageMsg( array( 'missingparam', $param ) ); } } diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index dfd52e5b3f..f597204fd2 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -58,9 +58,6 @@ class ApiBlock extends ApiBase { return; } - if ( is_null( $params['user'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'user' ) ); - } if ( !$wgUser->isAllowed( 'block' ) ) { $this->dieUsageMsg( array( 'cantblock' ) ); } @@ -135,7 +132,10 @@ class ApiBlock extends ApiBase { public function getAllowedParams() { return array( - 'user' => null, + 'user' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'token' => null, 'gettoken' => false, 'expiry' => 'never', diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index fabbd77fa6..90f11f7416 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -45,10 +45,6 @@ class ApiEditPage extends ApiBase { global $wgUser; $params = $this->extractRequestParams(); - if ( is_null( $params['title'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'title' ) ); - } - if ( is_null( $params['text'] ) && is_null( $params['appendtext'] ) && is_null( $params['prependtext'] ) && $params['undo'] == 0 ) @@ -388,7 +384,10 @@ class ApiEditPage extends ApiBase { protected function getAllowedParams() { return array( - 'title' => null, + 'title' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'section' => null, 'text' => null, 'token' => null, diff --git a/includes/api/ApiEmailUser.php b/includes/api/ApiEmailUser.php index bc3c7a2c75..ad35c99d61 100644 --- a/includes/api/ApiEmailUser.php +++ b/includes/api/ApiEmailUser.php @@ -41,13 +41,6 @@ class ApiEmailUser extends ApiBase { global $wgUser; $params = $this->extractRequestParams(); - // Check required parameters - if ( !isset( $params['target'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'target' ) ); - } - if ( !isset( $params['text'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'text' ) ); - } // Validate target $targetUser = SpecialEmailUser::getTarget( $params['target'] ); @@ -90,9 +83,15 @@ class ApiEmailUser extends ApiBase { public function getAllowedParams() { return array( - 'target' => null, + 'target' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'subject' => null, - 'text' => null, + 'text' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'token' => null, 'ccme' => false, ); diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 9b6017105e..4c52d3dc05 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -45,9 +45,6 @@ class ApiMove extends ApiBase { } $this->requireOnlyOneParameter( $params, 'from', 'fromid' ); - if ( !isset( $params['to'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'to' ) ); - } if ( isset( $params['from'] ) ) { $fromTitle = Title::newFromText( $params['from'] ); @@ -172,7 +169,10 @@ class ApiMove extends ApiBase { 'fromid' => array( ApiBase::PARAM_TYPE => 'integer' ), - 'to' => null, + 'to' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'token' => null, 'reason' => null, 'movetalk' => false, diff --git a/includes/api/ApiPatrol.php b/includes/api/ApiPatrol.php index 2f248aff10..33fbe636d1 100644 --- a/includes/api/ApiPatrol.php +++ b/includes/api/ApiPatrol.php @@ -43,10 +43,6 @@ class ApiPatrol extends ApiBase { public function execute() { $params = $this->extractRequestParams(); - if ( !isset( $params['rcid'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'rcid' ) ); - } - $rc = RecentChange::newFromID( $params['rcid'] ); if ( !$rc instanceof RecentChange ) { $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) ); @@ -70,7 +66,8 @@ class ApiPatrol extends ApiBase { return array( 'token' => null, 'rcid' => array( - ApiBase::PARAM_TYPE => 'integer' + ApiBase::PARAM_TYPE => 'integer', + ApiBase::PARAM_REQUIRED => 1 ), ); } diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index 9bd7824c80..77c9f6d16c 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -41,12 +41,6 @@ class ApiProtect extends ApiBase { $params = $this->extractRequestParams(); $titleObj = null; - if ( !isset( $params['title'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'title' ) ); - } - if ( empty( $params['protections'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'protections' ) ); - } $titleObj = Title::newFromText( $params['title'] ); if ( !$titleObj ) { @@ -149,10 +143,14 @@ class ApiProtect extends ApiBase { public function getAllowedParams() { return array( - 'title' => null, + 'title' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'token' => null, 'protections' => array( - ApiBase::PARAM_ISMULTI => true + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_REQUIRED => 1, ), 'expiry' => array( ApiBase::PARAM_ISMULTI => true, diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index fbcd9c2525..7d3b8a7df4 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -46,9 +46,6 @@ class ApiPurge extends ApiBase { if ( !$wgUser->isAllowed( 'purge' ) ) { $this->dieUsageMsg( array( 'cantpurge' ) ); } - if ( !isset( $params['titles'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'titles' ) ); - } $result = array(); foreach ( $params['titles'] as $t ) { $r = array(); @@ -86,7 +83,8 @@ class ApiPurge extends ApiBase { public function getAllowedParams() { return array( 'titles' => array( - ApiBase::PARAM_ISMULTI => true + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_REQUIRED => 1 ) ); } diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php index 4a15e45ea8..6d22160446 100644 --- a/includes/api/ApiQueryBacklinks.php +++ b/includes/api/ApiQueryBacklinks.php @@ -345,8 +345,6 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } else { $this->rootTitle = $title; } - } else { - $this->dieUsageMsg( array( 'missingparam', 'title' ) ); } } @@ -404,7 +402,10 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { public function getAllowedParams() { $retval = array( - 'title' => null, + 'title' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'continue' => null, 'namespace' => array( ApiBase::PARAM_ISMULTI => true, diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index 5f6f5c6314..40a88dcae2 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -77,8 +77,14 @@ class ApiRollback extends ApiBase { public function getAllowedParams() { return array( - 'title' => null, - 'user' => null, + 'title' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), + 'user' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'token' => null, 'summary' => null, 'markbot' => false, @@ -133,10 +139,6 @@ class ApiRollback extends ApiBase { $params = $this->extractRequestParams(); - if ( !isset( $params['user'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'user' ) ); - } - // We need to be able to revert IPs, but getCanonicalName rejects them $this->mUser = User::isIP( $params['user'] ) ? $params['user'] @@ -154,9 +156,6 @@ class ApiRollback extends ApiBase { } $params = $this->extractRequestParams(); - if ( !isset( $params['title'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'title' ) ); - } $this->mTitleObj = Title::newFromText( $params['title'] ); diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php index 89f4a71c75..6082ef00fb 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -41,9 +41,6 @@ class ApiUndelete extends ApiBase { $params = $this->extractRequestParams(); $titleObj = null; - if ( !isset( $params['title'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'title' ) ); - } if ( !$wgUser->isAllowed( 'undelete' ) ) { $this->dieUsageMsg( array( 'permdenied-undelete' ) ); @@ -101,7 +98,10 @@ class ApiUndelete extends ApiBase { public function getAllowedParams() { return array( - 'title' => null, + 'title' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'token' => null, 'reason' => '', 'timestamps' => array( diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index c5ea2f790e..8636fea85b 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -101,10 +101,6 @@ class ApiUpload extends ApiBase { // One and only one of the following parameters is needed $this->requireOnlyOneParameter( $this->mParams, 'sessionkey', 'file', 'url' ); - // And this one is needed - if ( !isset( $this->mParams['filename'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'filename' ) ); - } if ( $this->mParams['sessionkey'] ) { // Upload stashed in a previous request @@ -318,7 +314,10 @@ class ApiUpload extends ApiBase { public function getAllowedParams() { $params = array( - 'filename' => null, + 'filename' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'comment' => array( ApiBase::PARAM_DFLT => '' ), diff --git a/includes/api/ApiUserrights.php b/includes/api/ApiUserrights.php index 8f6f659fb9..28699764f9 100644 --- a/includes/api/ApiUserrights.php +++ b/includes/api/ApiUserrights.php @@ -61,9 +61,6 @@ class ApiUserrights extends ApiBase { } $params = $this->extractRequestParams(); - if ( is_null( $params['user'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'user' ) ); - } $form = new UserrightsPage; $status = $form->fetchUser( $params['user'] ); @@ -88,7 +85,10 @@ class ApiUserrights extends ApiBase { public function getAllowedParams() { return array ( - 'user' => null, + 'user' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 1 + ), 'add' => array( ApiBase::PARAM_TYPE => User::getAllGroups(), ApiBase::PARAM_ISMULTI => true -- 2.20.1