r70461 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70460‎ | r70461 | r70462 >
Date:14:15, 4 August 2010
Author:soxred93
Status:ok (Comments)
Tags:
Comment:
Followup to r70460: Committed wrong version of ApiBase.php, convert all core API modules to PARAM_REQUIRED syntax
Modified paths:
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiBlock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEmailUser.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMove.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPatrol.php (modified) (history)
  • /trunk/phase3/includes/api/ApiProtect.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPurge.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBacklinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiRollback.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUndelete.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUserrights.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiMove.php
@@ -45,9 +45,6 @@
4646 }
4747
4848 $this->requireOnlyOneParameter( $params, 'from', 'fromid' );
49 - if ( !isset( $params['to'] ) ) {
50 - $this->dieUsageMsg( array( 'missingparam', 'to' ) );
51 - }
5249
5350 if ( isset( $params['from'] ) ) {
5451 $fromTitle = Title::newFromText( $params['from'] );
@@ -172,7 +169,10 @@
173170 'fromid' => array(
174171 ApiBase::PARAM_TYPE => 'integer'
175172 ),
176 - 'to' => null,
 173+ 'to' => array(
 174+ ApiBase::PARAM_TYPE => 'string',
 175+ ApiBase::PARAM_REQUIRED => 1
 176+ ),
177177 'token' => null,
178178 'reason' => null,
179179 'movetalk' => false,
Index: trunk/phase3/includes/api/ApiProtect.php
@@ -41,12 +41,6 @@
4242 $params = $this->extractRequestParams();
4343
4444 $titleObj = null;
45 - if ( !isset( $params['title'] ) ) {
46 - $this->dieUsageMsg( array( 'missingparam', 'title' ) );
47 - }
48 - if ( empty( $params['protections'] ) ) {
49 - $this->dieUsageMsg( array( 'missingparam', 'protections' ) );
50 - }
5145
5246 $titleObj = Title::newFromText( $params['title'] );
5347 if ( !$titleObj ) {
@@ -149,10 +143,14 @@
150144
151145 public function getAllowedParams() {
152146 return array(
153 - 'title' => null,
 147+ 'title' => array(
 148+ ApiBase::PARAM_TYPE => 'string',
 149+ ApiBase::PARAM_REQUIRED => 1
 150+ ),
154151 'token' => null,
155152 'protections' => array(
156 - ApiBase::PARAM_ISMULTI => true
 153+ ApiBase::PARAM_ISMULTI => true,
 154+ ApiBase::PARAM_REQUIRED => 1,
157155 ),
158156 'expiry' => array(
159157 ApiBase::PARAM_ISMULTI => true,
Index: trunk/phase3/includes/api/ApiPurge.php
@@ -46,9 +46,6 @@
4747 if ( !$wgUser->isAllowed( 'purge' ) ) {
4848 $this->dieUsageMsg( array( 'cantpurge' ) );
4949 }
50 - if ( !isset( $params['titles'] ) ) {
51 - $this->dieUsageMsg( array( 'missingparam', 'titles' ) );
52 - }
5350 $result = array();
5451 foreach ( $params['titles'] as $t ) {
5552 $r = array();
@@ -86,7 +83,8 @@
8784 public function getAllowedParams() {
8885 return array(
8986 'titles' => array(
90 - ApiBase::PARAM_ISMULTI => true
 87+ ApiBase::PARAM_ISMULTI => true,
 88+ ApiBase::PARAM_REQUIRED => 1
9189 )
9290 );
9391 }
Index: trunk/phase3/includes/api/ApiQueryBacklinks.php
@@ -345,8 +345,6 @@
346346 } else {
347347 $this->rootTitle = $title;
348348 }
349 - } else {
350 - $this->dieUsageMsg( array( 'missingparam', 'title' ) );
351349 }
352350 }
353351
@@ -404,7 +402,10 @@
405403
406404 public function getAllowedParams() {
407405 $retval = array(
408 - 'title' => null,
 406+ 'title' => array(
 407+ ApiBase::PARAM_TYPE => 'string',
 408+ ApiBase::PARAM_REQUIRED => 1
 409+ ),
409410 'continue' => null,
410411 'namespace' => array(
411412 ApiBase::PARAM_ISMULTI => true,
Index: trunk/phase3/includes/api/ApiRollback.php
@@ -77,8 +77,14 @@
7878
7979 public function getAllowedParams() {
8080 return array(
81 - 'title' => null,
82 - 'user' => null,
 81+ 'title' => array(
 82+ ApiBase::PARAM_TYPE => 'string',
 83+ ApiBase::PARAM_REQUIRED => 1
 84+ ),
 85+ 'user' => array(
 86+ ApiBase::PARAM_TYPE => 'string',
 87+ ApiBase::PARAM_REQUIRED => 1
 88+ ),
8389 'token' => null,
8490 'summary' => null,
8591 'markbot' => false,
@@ -133,10 +139,6 @@
134140
135141 $params = $this->extractRequestParams();
136142
137 - if ( !isset( $params['user'] ) ) {
138 - $this->dieUsageMsg( array( 'missingparam', 'user' ) );
139 - }
140 -
141143 // We need to be able to revert IPs, but getCanonicalName rejects them
142144 $this->mUser = User::isIP( $params['user'] )
143145 ? $params['user']
@@ -154,9 +156,6 @@
155157 }
156158
157159 $params = $this->extractRequestParams();
158 - if ( !isset( $params['title'] ) ) {
159 - $this->dieUsageMsg( array( 'missingparam', 'title' ) );
160 - }
161160
162161 $this->mTitleObj = Title::newFromText( $params['title'] );
163162
Index: trunk/phase3/includes/api/ApiUserrights.php
@@ -61,9 +61,6 @@
6262 }
6363
6464 $params = $this->extractRequestParams();
65 - if ( is_null( $params['user'] ) ) {
66 - $this->dieUsageMsg( array( 'missingparam', 'user' ) );
67 - }
6865
6966 $form = new UserrightsPage;
7067 $status = $form->fetchUser( $params['user'] );
@@ -88,7 +85,10 @@
8986
9087 public function getAllowedParams() {
9188 return array (
92 - 'user' => null,
 89+ 'user' => array(
 90+ ApiBase::PARAM_TYPE => 'string',
 91+ ApiBase::PARAM_REQUIRED => 1
 92+ ),
9393 'add' => array(
9494 ApiBase::PARAM_TYPE => User::getAllGroups(),
9595 ApiBase::PARAM_ISMULTI => true
Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -45,10 +45,6 @@
4646 global $wgUser;
4747 $params = $this->extractRequestParams();
4848
49 - if ( is_null( $params['title'] ) ) {
50 - $this->dieUsageMsg( array( 'missingparam', 'title' ) );
51 - }
52 -
5349 if ( is_null( $params['text'] ) && is_null( $params['appendtext'] ) &&
5450 is_null( $params['prependtext'] ) &&
5551 $params['undo'] == 0 )
@@ -388,7 +384,10 @@
389385
390386 protected function getAllowedParams() {
391387 return array(
392 - 'title' => null,
 388+ 'title' => array(
 389+ ApiBase::PARAM_TYPE => 'string',
 390+ ApiBase::PARAM_REQUIRED => 1
 391+ ),
393392 'section' => null,
394393 'text' => null,
395394 'token' => null,
Index: trunk/phase3/includes/api/ApiEmailUser.php
@@ -41,13 +41,6 @@
4242 global $wgUser;
4343
4444 $params = $this->extractRequestParams();
45 - // Check required parameters
46 - if ( !isset( $params['target'] ) ) {
47 - $this->dieUsageMsg( array( 'missingparam', 'target' ) );
48 - }
49 - if ( !isset( $params['text'] ) ) {
50 - $this->dieUsageMsg( array( 'missingparam', 'text' ) );
51 - }
5245
5346 // Validate target
5447 $targetUser = SpecialEmailUser::getTarget( $params['target'] );
@@ -90,9 +83,15 @@
9184
9285 public function getAllowedParams() {
9386 return array(
94 - 'target' => null,
 87+ 'target' => array(
 88+ ApiBase::PARAM_TYPE => 'string',
 89+ ApiBase::PARAM_REQUIRED => 1
 90+ ),
9591 'subject' => null,
96 - 'text' => null,
 92+ 'text' => array(
 93+ ApiBase::PARAM_TYPE => 'string',
 94+ ApiBase::PARAM_REQUIRED => 1
 95+ ),
9796 'token' => null,
9897 'ccme' => false,
9998 );
Index: trunk/phase3/includes/api/ApiBlock.php
@@ -58,9 +58,6 @@
5959 return;
6060 }
6161
62 - if ( is_null( $params['user'] ) ) {
63 - $this->dieUsageMsg( array( 'missingparam', 'user' ) );
64 - }
6562 if ( !$wgUser->isAllowed( 'block' ) ) {
6663 $this->dieUsageMsg( array( 'cantblock' ) );
6764 }
@@ -135,7 +132,10 @@
136133
137134 public function getAllowedParams() {
138135 return array(
139 - 'user' => null,
 136+ 'user' => array(
 137+ ApiBase::PARAM_TYPE => 'string',
 138+ ApiBase::PARAM_REQUIRED => 1
 139+ ),
140140 'token' => null,
141141 'gettoken' => false,
142142 'expiry' => 'never',
Index: trunk/phase3/includes/api/ApiPatrol.php
@@ -43,10 +43,6 @@
4444 public function execute() {
4545 $params = $this->extractRequestParams();
4646
47 - if ( !isset( $params['rcid'] ) ) {
48 - $this->dieUsageMsg( array( 'missingparam', 'rcid' ) );
49 - }
50 -
5147 $rc = RecentChange::newFromID( $params['rcid'] );
5248 if ( !$rc instanceof RecentChange ) {
5349 $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
@@ -70,7 +66,8 @@
7167 return array(
7268 'token' => null,
7369 'rcid' => array(
74 - ApiBase::PARAM_TYPE => 'integer'
 70+ ApiBase::PARAM_TYPE => 'integer',
 71+ ApiBase::PARAM_REQUIRED => 1
7572 ),
7673 );
7774 }
Index: trunk/phase3/includes/api/ApiUndelete.php
@@ -41,9 +41,6 @@
4242 $params = $this->extractRequestParams();
4343
4444 $titleObj = null;
45 - if ( !isset( $params['title'] ) ) {
46 - $this->dieUsageMsg( array( 'missingparam', 'title' ) );
47 - }
4845
4946 if ( !$wgUser->isAllowed( 'undelete' ) ) {
5047 $this->dieUsageMsg( array( 'permdenied-undelete' ) );
@@ -101,7 +98,10 @@
10299
103100 public function getAllowedParams() {
104101 return array(
105 - 'title' => null,
 102+ 'title' => array(
 103+ ApiBase::PARAM_TYPE => 'string',
 104+ ApiBase::PARAM_REQUIRED => 1
 105+ ),
106106 'token' => null,
107107 'reason' => '',
108108 'timestamps' => array(
Index: trunk/phase3/includes/api/ApiBase.php
@@ -503,7 +503,7 @@
504504
505505 $allparams = $this->getAllowedParams();
506506 foreach( $this->mParamCache[$parseLimit] as $param => $val ) {
507 - if( !isset( $allparams[$param][ApiBase::PARAM_REQUIRED] ) ) {
 507+ if( isset( $allparams[$param][ApiBase::PARAM_REQUIRED] ) && !isset( $val ) ) {
508508 $this->dieUsageMsg( array( 'missingparam', $param ) );
509509 }
510510 }
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -101,10 +101,6 @@
102102 // One and only one of the following parameters is needed
103103 $this->requireOnlyOneParameter( $this->mParams,
104104 'sessionkey', 'file', 'url' );
105 - // And this one is needed
106 - if ( !isset( $this->mParams['filename'] ) ) {
107 - $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
108 - }
109105
110106 if ( $this->mParams['sessionkey'] ) {
111107 // Upload stashed in a previous request
@@ -318,7 +314,10 @@
319315
320316 public function getAllowedParams() {
321317 $params = array(
322 - 'filename' => null,
 318+ 'filename' => array(
 319+ ApiBase::PARAM_TYPE => 'string',
 320+ ApiBase::PARAM_REQUIRED => 1
 321+ ),
323322 'comment' => array(
324323 ApiBase::PARAM_DFLT => ''
325324 ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r70462Followup to r70460 and r70461: Use true instead of 1soxred9314:29, 4 August 2010
r70474Followup r70461 if PARAM_REQUIRED is set, use for missing param in getPossibl...reedy19:20, 4 August 2010
r70476Followup r70474 and r70461, drop missingparam from getPossibleErrorsreedy19:32, 4 August 2010
r70477Followup r70460/r70461...reedy20:27, 4 August 2010
r70478Make search enforced by API in search by setting PARAM_REQUIRED...reedy20:47, 4 August 2010
r70479Further followup to r70460/r70461 and r70477...reedy21:19, 4 August 2010
r734691.16wmf4: Merging PARAM_REQUIRED support from trunk for upcoming ArticleAsses...catrope18:53, 21 September 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r70460* PARAM_REQUIRED parameter flag added. If this flag is set, and the end user ...soxred9313:35, 4 August 2010

Comments

#Comment by Reedy (talk | contribs)   20:25, 4 August 2010

You've actually unknowingly fixed a bug here.

Title should've been a required paramter in Backlinks via any method, but it wasn't

Status & tagging log