From 20d042a99e34e00a98672bb27de91487a62f17e6 Mon Sep 17 00:00:00 2001 From: X! Date: Wed, 4 Aug 2010 13:35:08 +0000 Subject: [PATCH] * 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. --- RELEASE-NOTES | 2 ++ includes/api/ApiBase.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 23c39bced5..1103595b9b 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -316,6 +316,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 24564) Fix fatal errors when using list=deletedrevs, prop=revisions or one of the backlinks generators with limit=max. * (bug 24656) API's parse module needs option to disable PP report +* 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. === Languages updated in 1.17 === diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index b28224b93f..099d6f5bad 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -50,6 +50,7 @@ abstract class ApiBase { const PARAM_MIN = 5; // Lowest value allowed for a parameter. Only applies if TYPE='integer' const PARAM_ALLOW_DUPLICATES = 6; // Boolean, do we allow the same value to be set more than once when ISMULTI=true const PARAM_DEPRECATED = 7; // Boolean, is the parameter deprecated (will show a warning) + const PARAM_REQUIRED = 8; // Boolean, is the parameter required? const LIMIT_BIG1 = 500; // Fast query, std user limit const LIMIT_BIG2 = 5000; // Fast query, bot/sysop limit @@ -306,6 +307,12 @@ abstract class ApiBase { if ( $deprecated ) { $desc = "DEPRECATED! $desc"; } + + $required = isset( $paramSettings[self::PARAM_REQUIRED] ) ? + $paramSettings[self::PARAM_REQUIRED] : false; + if ( $required ) { + $desc .= $paramPrefix . "This parameter is required"; + } $type = isset( $paramSettings[self::PARAM_TYPE] ) ? $paramSettings[self::PARAM_TYPE] : null; if ( isset( $type ) ) { @@ -493,6 +500,14 @@ abstract class ApiBase { } $this->mParamCache[$parseLimit] = $results; } + + $allparams = $this->getAllowedParams(); + foreach( $this->mParamCache[$parseLimit] as $param => $val ) { + if( !isset( $allparams[$param][ApiBase::PARAM_REQUIRED] ) ) { + $this->dieUsageMsg( array( 'missingparam', $param ) ); + } + } + return $this->mParamCache[$parseLimit]; } -- 2.20.1