Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -50,6 +50,7 @@ |
51 | 51 | const PARAM_MIN = 5; // Lowest value allowed for a parameter. Only applies if TYPE='integer' |
52 | 52 | const PARAM_ALLOW_DUPLICATES = 6; // Boolean, do we allow the same value to be set more than once when ISMULTI=true |
53 | 53 | const PARAM_DEPRECATED = 7; // Boolean, is the parameter deprecated (will show a warning) |
| 54 | + const PARAM_REQUIRED = 8; // Boolean, is the parameter required? |
54 | 55 | |
55 | 56 | const LIMIT_BIG1 = 500; // Fast query, std user limit |
56 | 57 | const LIMIT_BIG2 = 5000; // Fast query, bot/sysop limit |
— | — | @@ -306,6 +307,12 @@ |
307 | 308 | if ( $deprecated ) { |
308 | 309 | $desc = "DEPRECATED! $desc"; |
309 | 310 | } |
| 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 | + } |
310 | 317 | |
311 | 318 | $type = isset( $paramSettings[self::PARAM_TYPE] ) ? $paramSettings[self::PARAM_TYPE] : null; |
312 | 319 | if ( isset( $type ) ) { |
— | — | @@ -493,6 +500,14 @@ |
494 | 501 | } |
495 | 502 | $this->mParamCache[$parseLimit] = $results; |
496 | 503 | } |
| 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 | + |
497 | 512 | return $this->mParamCache[$parseLimit]; |
498 | 513 | } |
499 | 514 | |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -316,6 +316,8 @@ |
317 | 317 | * (bug 24564) Fix fatal errors when using list=deletedrevs, prop=revisions or |
318 | 318 | one of the backlinks generators with limit=max. |
319 | 319 | * (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. |
320 | 322 | |
321 | 323 | === Languages updated in 1.17 === |
322 | 324 | |