http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90237
Revision: 90237 Author: yaron Date: 2011-06-16 22:13:23 +0000 (Thu, 16 Jun 2011) Log Message: ----------- Fixed handling of 'unhandled' fields (fields that only on the page, not in the form) - there was a bug in which they were also added to unrelated templates Modified Paths: -------------- trunk/extensions/SemanticForms/includes/SF_FormPrinter.php trunk/extensions/SemanticForms/includes/SF_FormUtils.php Modified: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php =================================================================== --- trunk/extensions/SemanticForms/includes/SF_FormPrinter.php 2011-06-16 21:43:58 UTC (rev 90236) +++ trunk/extensions/SemanticForms/includes/SF_FormPrinter.php 2011-06-16 22:13:23 UTC (rev 90237) @@ -615,7 +615,7 @@ if ( $source_is_page ) { // Add any unhandled template fields in the page as hidden variables. if ( isset( $template_contents ) ) { - $form_text .= SFFormUtils::unhandledFieldsHTML( $template_contents ); + $form_text .= SFFormUtils::unhandledFieldsHTML( $template_name, $template_contents ); $template_contents = null; } } @@ -1203,7 +1203,7 @@ // If we're editing an existing page, and there were fields in // the template call not handled by this form, preserve those. if ( !$allow_multiple ) { - $template_text .= SFFormUtils::addUnhandledFields(); + $template_text .= SFFormUtils::addUnhandledFields( $template_name ); } $template_text .= "}}"; $data_text .= $template_text . "\n"; Modified: trunk/extensions/SemanticForms/includes/SF_FormUtils.php =================================================================== --- trunk/extensions/SemanticForms/includes/SF_FormUtils.php 2011-06-16 21:43:58 UTC (rev 90236) +++ trunk/extensions/SemanticForms/includes/SF_FormUtils.php 2011-06-16 22:13:23 UTC (rev 90237) @@ -46,12 +46,12 @@ * Add a hidden input for each field in the template call that's * not handled by the form itself */ - static function unhandledFieldsHTML( $template_contents ) { + static function unhandledFieldsHTML( $templateName, $templateContents ) { $text = ""; - foreach ( $template_contents as $key => $value ) { + foreach ( $templateContents as $key => $value ) { if ( !is_null( $key ) && !is_numeric( $key ) ) { $key = urlencode( $key ); - $text .= self::hiddenFieldHTML( "_unhandled_$key", $value ); + $text .= self::hiddenFieldHTML( '_unhandled_' . $templateName . '_' . $key, $value ); } } return $text; @@ -61,12 +61,15 @@ * Add unhandled fields back into the template call that the form * generates, so that editing with a form will have no effect on them */ - static function addUnhandledFields() { + static function addUnhandledFields( $templateName ) { global $wgRequest; + + $prefix = '_unhandled_' . $templateName . '_'; + $prefixSize = strlen( $prefix ); $additional_template_text = ""; foreach ( $wgRequest->getValues() as $key => $value ) { - if ( substr( $key, 0, 11 ) == '_unhandled_' ) { - $field_name = urldecode( substr( $key, 11 ) ); + if ( strpos( $key, $prefix ) === 0 ) { + $field_name = urldecode( substr( $key, $prefixSize ) ); $additional_template_text .= "|$field_name=$value\n"; } } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs