r85758 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85757‎ | r85758 | r85759 >
Date:13:01, 10 April 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
* (bug 28254) action=paraminfo: Extract type from PARAM_DFLT if PARAM_TYPE is not set

Patch by Umherirrender
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiParamInfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiParamInfo.php
@@ -121,6 +121,26 @@
122122 if ( isset( $paramDesc[$n] ) ) {
123123 $a['description'] = implode( "\n", (array)$paramDesc[$n] );
124124 }
 125+
 126+ //handle shorthand
 127+ if( !is_array( $p ) ) {
 128+ $p = array(
 129+ ApiBase::PARAM_DFLT => $p,
 130+ );
 131+ }
 132+
 133+ //handle missing type
 134+ if ( !isset( $p[ApiBase::PARAM_TYPE] ) ) {
 135+ $dflt = $p[ApiBase::PARAM_DFLT];
 136+ if ( is_bool( $dflt ) ) {
 137+ $p[ApiBase::PARAM_TYPE] = 'bool';
 138+ } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
 139+ $p[ApiBase::PARAM_TYPE] = 'string';
 140+ } elseif ( is_int( $dflt ) ) {
 141+ $p[ApiBase::PARAM_TYPE] = 'integer';
 142+ }
 143+ }
 144+
125145 if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] ) {
126146 $a['deprecated'] = '';
127147 }
@@ -128,24 +148,18 @@
129149 $a['required'] = '';
130150 }
131151
132 - if ( !is_array( $p ) ) {
133 - if ( is_bool( $p ) ) {
134 - $a['type'] = 'bool';
135 - $a['default'] = ( $p ? 'true' : 'false' );
136 - } elseif ( is_string( $p ) || is_null( $p ) ) {
137 - $a['type'] = 'string';
138 - $a['default'] = strval( $p );
139 - } elseif ( is_int( $p ) ) {
140 - $a['type'] = 'integer';
141 - $a['default'] = intval( $p );
 152+ if ( isset( $p[ApiBase::PARAM_DFLT] ) ) {
 153+ $type = $p[ApiBase::PARAM_TYPE];
 154+ if( $type === 'bool' ) {
 155+ $a['default'] = ( $p[ApiBase::PARAM_DFLT] ? 'true' : 'false' );
 156+ } elseif( $type === 'string' ) {
 157+ $a['default'] = strval( $p[ApiBase::PARAM_DFLT] );
 158+ } elseif( $type === 'integer' ) {
 159+ $a['default'] = intval( $p[ApiBase::PARAM_DFLT] );
 160+ } else {
 161+ $a['default'] = $p[ApiBase::PARAM_DFLT];
142162 }
143 - $retval['parameters'][] = $a;
144 - continue;
145163 }
146 -
147 - if ( isset( $p[ApiBase::PARAM_DFLT] ) ) {
148 - $a['default'] = $p[ApiBase::PARAM_DFLT];
149 - }
150164 if ( isset( $p[ApiBase::PARAM_ISMULTI] ) && $p[ApiBase::PARAM_ISMULTI] ) {
151165 $a['multi'] = '';
152166 $a['limit'] = $this->getMain()->canApiHighLimits() ?
Index: trunk/phase3/RELEASE-NOTES
@@ -329,6 +329,8 @@
330330 action=import&xml=
331331 * (bug 28391) action=feedwatchlist&allrev should be a bool
332332 * (bug 28364) add registration date to meta=userinfo
 333+* (bug 28254) action=paraminfo: Extract type from PARAM_DFLT if
 334+ PARAM_TYPE is not set
333335
334336 === Languages updated in 1.18 ===
335337

Follow-up revisions

RevisionCommit summaryAuthorDate
r86917* (bug 28702) Undefined offset in ApiParamInfo.php...reedy22:56, 25 April 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   18:59, 25 April 2011

This appears to trigger bug 28702; on api.php?action=paraminfo&modules=purge we get a notice error:

 PHP Notice:  Undefined offset: 0 in /var/www/trunk/includes/api/ApiParamInfo.php on line 134

for an entry that doesn't list a default or a type.

Status & tagging log