From b70c52dd8e3c11c5417d06cf35e956d391d12ab3 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Wed, 4 Aug 2010 21:19:53 +0000 Subject: [PATCH] Further followup to r70460/r70461 and r70477 Move code into getParameterFromSettings, most of the flesh is there anyway (it checks isset( $value ) ), so we can use the else to check if it's required A followup could be to whinge if '' is returned for a string --- includes/api/ApiBase.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index be1be86768..44acddadbf 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -496,10 +496,6 @@ abstract class ApiBase { foreach ( $params as $paramName => $paramSettings ) { $results[$paramName] = $this->getParameterFromSettings( $paramName, $paramSettings, $parseLimit ); - - if( isset( $paramSettings[self::PARAM_REQUIRED] ) && !isset( $results[$paramName] ) ) { - $this->dieUsageMsg( array( 'missingparam', $paramName ) ); - } } } $this->mParamCache[$parseLimit] = $results; @@ -627,6 +623,7 @@ abstract class ApiBase { $type = isset( $paramSettings[self::PARAM_TYPE] ) ? $paramSettings[self::PARAM_TYPE] : null; $dupes = isset( $paramSettings[self::PARAM_ALLOW_DUPLICATES] ) ? $paramSettings[self::PARAM_ALLOW_DUPLICATES] : false; $deprecated = isset( $paramSettings[self::PARAM_DEPRECATED] ) ? $paramSettings[self::PARAM_DEPRECATED] : false; + $required = isset( $paramSettings[self::PARAM_REQUIRED] ) ? $paramSettings[self::PARAM_REQUIRED] : false; // When type is not given, and no choices, the type is the same as $default if ( !isset( $type ) ) { @@ -745,6 +742,8 @@ abstract class ApiBase { if ( $deprecated && $value !== false ) { $this->setWarning( "The $encParamName parameter has been deprecated." ); } + } else if ( $required ) { + $this->dieUsageMsg( array( 'missingparam', $paramName ) ); } return $value; -- 2.20.1