r70460 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70459‎ | r70460 | r70461 >
Date:13:35, 4 August 2010
Author:soxred93
Status:ok (Comments)
Tags:
Comment:
* PARAM_REQUIRED parameter flag added. If this flag is set, and the end user does not set
the parameter, the API will automatically throw an error.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiBase.php
@@ -50,6 +50,7 @@
5151 const PARAM_MIN = 5; // Lowest value allowed for a parameter. Only applies if TYPE='integer'
5252 const PARAM_ALLOW_DUPLICATES = 6; // Boolean, do we allow the same value to be set more than once when ISMULTI=true
5353 const PARAM_DEPRECATED = 7; // Boolean, is the parameter deprecated (will show a warning)
 54+ const PARAM_REQUIRED = 8; // Boolean, is the parameter required?
5455
5556 const LIMIT_BIG1 = 500; // Fast query, std user limit
5657 const LIMIT_BIG2 = 5000; // Fast query, bot/sysop limit
@@ -306,6 +307,12 @@
307308 if ( $deprecated ) {
308309 $desc = "DEPRECATED! $desc";
309310 }
 311+
 312+ $required = isset( $paramSettings[self::PARAM_REQUIRED] ) ?
 313+ $paramSettings[self::PARAM_REQUIRED] : false;
 314+ if ( $required ) {
 315+ $desc .= $paramPrefix . "This parameter is required";
 316+ }
310317
311318 $type = isset( $paramSettings[self::PARAM_TYPE] ) ? $paramSettings[self::PARAM_TYPE] : null;
312319 if ( isset( $type ) ) {
@@ -493,6 +500,14 @@
494501 }
495502 $this->mParamCache[$parseLimit] = $results;
496503 }
 504+
 505+ $allparams = $this->getAllowedParams();
 506+ foreach( $this->mParamCache[$parseLimit] as $param => $val ) {
 507+ if( !isset( $allparams[$param][ApiBase::PARAM_REQUIRED] ) ) {
 508+ $this->dieUsageMsg( array( 'missingparam', $param ) );
 509+ }
 510+ }
 511+
497512 return $this->mParamCache[$parseLimit];
498513 }
499514
Index: trunk/phase3/RELEASE-NOTES
@@ -316,6 +316,8 @@
317317 * (bug 24564) Fix fatal errors when using list=deletedrevs, prop=revisions or
318318 one of the backlinks generators with limit=max.
319319 * (bug 24656) API's parse module needs option to disable PP report
 320+* PARAM_REQUIRED parameter flag added. If this flag is set, and the end user does not set
 321+ the parameter, the API will automatically throw an error.
320322
321323 === Languages updated in 1.17 ===
322324

Follow-up revisions

RevisionCommit summaryAuthorDate
r70461Followup to r70460: Committed wrong version of ApiBase.php, convert all core ...soxred9314:15, 4 August 2010
r70462Followup to r70460 and r70461: Use true instead of 1soxred9314:29, 4 August 2010
r70477Followup r70460/r70461...reedy20:27, 4 August 2010
r70479Further followup to r70460/r70461 and r70477...reedy21:19, 4 August 2010
r70554Followup r70460 per Umherirrender comment...reedy11:18, 6 August 2010
r734691.16wmf4: Merging PARAM_REQUIRED support from trunk for upcoming ArticleAsses...catrope18:53, 21 September 2010

Comments

#Comment by Reedy (talk | contribs)   14:01, 4 August 2010

I suppose... We should look at updating the usages of these.

And possibly look at using a similar method to do the getPossibleErrors for missing params in the base...

#Comment by X! (talk | contribs)   14:17, 4 August 2010

All usages updated that did not have dependencies in r70461

#Comment by Umherirrender (talk | contribs)   18:25, 5 August 2010

It can be very helpful to have that information with action=paraminfo or action=help. Thanks.

#Comment by Reedy (talk | contribs)   18:44, 5 August 2010
+				$required = isset( $paramSettings[self::PARAM_REQUIRED] ) ?
+					$paramSettings[self::PARAM_REQUIRED] : false;
+				if ( $required ) {
+					$desc .= $paramPrefix . "This parameter is required";
+				}

That's what the code above does that was added

#Comment by Umherirrender (talk | contribs)   10:47, 6 August 2010

Thanks, you are right for action=help.

But in action=paraminfo I am missing a required attribut.

#Comment by Reedy (talk | contribs)   10:48, 6 August 2010

Alright, will have a look later for you :)

#Comment by Umherirrender (talk | contribs)   15:24, 6 August 2010

Thanks, r70554 looks good.

Status & tagging log