From af3a1052ff8c65fb23f3415c371ecbdc6132205c Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sun, 10 Apr 2011 13:01:47 +0000 Subject: [PATCH] * (bug 28254) action=paraminfo: Extract type from PARAM_DFLT if PARAM_TYPE is not set Patch by Umherirrender --- RELEASE-NOTES | 2 ++ includes/api/ApiParamInfo.php | 46 +++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index b4aca3eeec..fb8ad955ff 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -329,6 +329,8 @@ PHP if you have not done so prior to upgrading MediaWiki. action=import&xml= * (bug 28391) action=feedwatchlist&allrev should be a bool * (bug 28364) add registration date to meta=userinfo +* (bug 28254) action=paraminfo: Extract type from PARAM_DFLT if + PARAM_TYPE is not set === Languages updated in 1.18 === diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php index 7f1f945f70..ac91ea3d92 100644 --- a/includes/api/ApiParamInfo.php +++ b/includes/api/ApiParamInfo.php @@ -121,6 +121,26 @@ class ApiParamInfo extends ApiBase { if ( isset( $paramDesc[$n] ) ) { $a['description'] = implode( "\n", (array)$paramDesc[$n] ); } + + //handle shorthand + if( !is_array( $p ) ) { + $p = array( + ApiBase::PARAM_DFLT => $p, + ); + } + + //handle missing type + if ( !isset( $p[ApiBase::PARAM_TYPE] ) ) { + $dflt = $p[ApiBase::PARAM_DFLT]; + if ( is_bool( $dflt ) ) { + $p[ApiBase::PARAM_TYPE] = 'bool'; + } elseif ( is_string( $dflt ) || is_null( $dflt ) ) { + $p[ApiBase::PARAM_TYPE] = 'string'; + } elseif ( is_int( $dflt ) ) { + $p[ApiBase::PARAM_TYPE] = 'integer'; + } + } + if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] ) { $a['deprecated'] = ''; } @@ -128,23 +148,17 @@ class ApiParamInfo extends ApiBase { $a['required'] = ''; } - if ( !is_array( $p ) ) { - if ( is_bool( $p ) ) { - $a['type'] = 'bool'; - $a['default'] = ( $p ? 'true' : 'false' ); - } elseif ( is_string( $p ) || is_null( $p ) ) { - $a['type'] = 'string'; - $a['default'] = strval( $p ); - } elseif ( is_int( $p ) ) { - $a['type'] = 'integer'; - $a['default'] = intval( $p ); - } - $retval['parameters'][] = $a; - continue; - } - if ( isset( $p[ApiBase::PARAM_DFLT] ) ) { - $a['default'] = $p[ApiBase::PARAM_DFLT]; + $type = $p[ApiBase::PARAM_TYPE]; + if( $type === 'bool' ) { + $a['default'] = ( $p[ApiBase::PARAM_DFLT] ? 'true' : 'false' ); + } elseif( $type === 'string' ) { + $a['default'] = strval( $p[ApiBase::PARAM_DFLT] ); + } elseif( $type === 'integer' ) { + $a['default'] = intval( $p[ApiBase::PARAM_DFLT] ); + } else { + $a['default'] = $p[ApiBase::PARAM_DFLT]; + } } if ( isset( $p[ApiBase::PARAM_ISMULTI] ) && $p[ApiBase::PARAM_ISMULTI] ) { $a['multi'] = ''; -- 2.20.1