r83650 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83649‎ | r83650 | r83651 >
Date:15:15, 10 March 2011
Author:yaron
Status:deferred
Tags:
Comment:
Fixed handling of param names with spaces when creating a form
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormField.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateForm.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_CreateForm.php
@@ -32,6 +32,9 @@
3333 foreach ( $wgRequest->getArray('params') as $key => $value ) {
3434 if ( ( $pos = strpos( $key, '_' . $fieldFormText ) ) != false ) {
3535 $paramName = substr( $key, 0, $pos );
 36+ // Spaces got replaced by underlines in
 37+ // the query.
 38+ $paramName = str_replace( '_', ' ', $paramName );
3639 $paramValues[$paramName] = $value;
3740 }
3841 }
@@ -149,13 +152,16 @@
150153 foreach ( $wgRequest->getValues() as $key => $value ) {
151154 if ( ( $pos = strpos( $key, '_' . $old_i . '_' . $j ) ) != false ) {
152155 $paramName = substr( $key, 0, $pos );
 156+ // Spaces got replaced by underlines
 157+ // in the query.
 158+ $paramName = str_replace( '_', ' ', $paramName );
153159 } else {
154160 continue;
155161 }
156162
157163 if ( $paramName == 'label' ) {
158164 $field->template_field->label = $value;
159 - } elseif ( $paramName == 'input_type' ) {
 165+ } elseif ( $paramName == 'input type' ) {
160166 $input_type = $wgRequest->getVal( "input_type_" . $old_i . "_" . $j );
161167 if ( $input_type == 'hidden' ) {
162168 $field->template_field->input_type = $input_type;
@@ -273,23 +279,23 @@
274280 * Code borrowed heavily from Semantic MediaWiki's
275281 * SMWAskPage::addOptionInput().
276282 */
277 - public static function inputTypeParamInput( $type, $param_name, $cur_value, array $param, array $paramValues, $fieldFormText ) {
 283+ public static function inputTypeParamInput( $type, $paramName, $cur_value, array $param, array $paramValues, $fieldFormText ) {
278284 if ( $type == 'int' ) {
279285 return Xml::element( 'input', array(
280286 'type' => 'text',
281 - 'name' => $param_name . '_' . $fieldFormText,
 287+ 'name' => $paramName . '_' . $fieldFormText,
282288 'value' => $cur_value,
283289 'size' => 6
284290 ) );
285291 } elseif ( $type == 'string' ) {
286292 return Xml::element( 'input', array(
287293 'type' => 'text',
288 - 'name' => $param_name . '_' . $fieldFormText,
 294+ 'name' => $paramName . '_' . $fieldFormText,
289295 'value' => $cur_value,
290296 'size' => 32
291297 ) );
292298 } elseif ( $type == 'enumeration' ) {
293 - $text = '<select name="p[' . htmlspecialchars( $param_name ) . ']">';
 299+ $text = '<select name="p[' . htmlspecialchars( $paramName ) . ']">';
294300 $text .= "\n <option value=''></option>\n";
295301
296302 $parts = array();
@@ -305,14 +311,14 @@
306312 $cur_values = explode( ',', $cur_value );
307313 foreach ( $param['values'] as $val ) {
308314 $text .= '<span style="white-space: nowrap; padding-right: 5px;"><input type="checkbox" name="p[' .
309 - htmlspecialchars( $param_name ) . '][' . htmlspecialchars( $val ). ']" value="true"' .
 315+ htmlspecialchars( $paramName ) . '][' . htmlspecialchars( $val ). ']" value="true"' .
310316 ( in_array( $val, $cur_values ) ? ' checked' : '' ) . '/> <tt>' . htmlspecialchars( $val ) . "</tt></span>\n";
311317 }
312318 return $text;
313319 } elseif ( $type == 'boolean' ) {
314320 $checkboxAttrs = array(
315321 'type' => 'checkbox',
316 - 'name' => $param_name . '_' . $fieldFormText
 322+ 'name' => $paramName . '_' . $fieldFormText
317323 );
318324 if ( $cur_value) { $checkboxAttrs['checked'] = 'checked'; }
319325 return Xml::element( 'input', $checkboxAttrs );
@@ -344,11 +350,11 @@
345351 $params = method_exists( $inputTypeClass, 'getParameters' ) ? call_user_func( array( $inputTypeClass, 'getParameters' ) ) : array();
346352
347353 foreach ( $params as $i => $param ) {
348 - $param_name = $param['name'];
 354+ $paramName = $param['name'];
349355 $type = $param['type'];
350356 $desc = $param['description'];
351357
352 - $cur_value = ( array_key_exists( $param_name, $paramValues ) ) ? $paramValues[$param_name] : '';
 358+ $cur_value = ( array_key_exists( $paramName, $paramValues ) ) ? $paramValues[$paramName] : '';
353359
354360 // 3 values per row, with alternating colors for rows
355361 if ( $i % 3 == 0 ) {
@@ -356,9 +362,9 @@
357363 $text .= "<div style=\"background: $bgcolor;\">";
358364 }
359365
360 - $text .= "<div style=\"width: 30%; padding: 5px; float: left;\">$param_name:\n";
 366+ $text .= "<div style=\"width: 30%; padding: 5px; float: left;\">$paramName:\n";
361367
362 - $text .= self::inputTypeParamInput( $type, $param_name, $cur_value, $param, array(), $fieldFormText );
 368+ $text .= self::inputTypeParamInput( $type, $paramName, $cur_value, $param, array(), $fieldFormText );
363369 $text .= "\n<br />" . Xml::element( 'em', null, $desc ) . "\n</div>\n";
364370
365371 if ( $i % 3 == 2 || $i == count( $params ) - 1 ) {
Index: trunk/extensions/SemanticForms/includes/SF_FormField.php
@@ -159,6 +159,9 @@
160160 foreach ( $wgRequest->getValues() as $key => $value ) {
161161 if ( ( $pos = strpos( $key, '_' . $field_form_text ) ) != false ) {
162162 $paramName = substr( $key, 0, $pos );
 163+ // Spaces got replaced by underlines in the
 164+ // query.
 165+ $paramName = str_replace( '_', ' ', $paramName );
163166 $paramValues[$paramName] = $value;
164167 }
165168 }