r90237 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90236‎ | r90237 | r90238 >
Date:22:13, 16 June 2011
Author:yaron
Status:deferred
Tags:
Comment:
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 (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormUtils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -615,7 +615,7 @@
616616 if ( $source_is_page ) {
617617 // Add any unhandled template fields in the page as hidden variables.
618618 if ( isset( $template_contents ) ) {
619 - $form_text .= SFFormUtils::unhandledFieldsHTML( $template_contents );
 619+ $form_text .= SFFormUtils::unhandledFieldsHTML( $template_name, $template_contents );
620620 $template_contents = null;
621621 }
622622 }
@@ -1203,7 +1203,7 @@
12041204 // If we're editing an existing page, and there were fields in
12051205 // the template call not handled by this form, preserve those.
12061206 if ( !$allow_multiple ) {
1207 - $template_text .= SFFormUtils::addUnhandledFields();
 1207+ $template_text .= SFFormUtils::addUnhandledFields( $template_name );
12081208 }
12091209 $template_text .= "}}";
12101210 $data_text .= $template_text . "\n";
Index: trunk/extensions/SemanticForms/includes/SF_FormUtils.php
@@ -46,12 +46,12 @@
4747 * Add a hidden input for each field in the template call that's
4848 * not handled by the form itself
4949 */
50 - static function unhandledFieldsHTML( $template_contents ) {
 50+ static function unhandledFieldsHTML( $templateName, $templateContents ) {
5151 $text = "";
52 - foreach ( $template_contents as $key => $value ) {
 52+ foreach ( $templateContents as $key => $value ) {
5353 if ( !is_null( $key ) && !is_numeric( $key ) ) {
5454 $key = urlencode( $key );
55 - $text .= self::hiddenFieldHTML( "_unhandled_$key", $value );
 55+ $text .= self::hiddenFieldHTML( '_unhandled_' . $templateName . '_' . $key, $value );
5656 }
5757 }
5858 return $text;
@@ -61,12 +61,15 @@
6262 * Add unhandled fields back into the template call that the form
6363 * generates, so that editing with a form will have no effect on them
6464 */
65 - static function addUnhandledFields() {
 65+ static function addUnhandledFields( $templateName ) {
6666 global $wgRequest;
 67+
 68+ $prefix = '_unhandled_' . $templateName . '_';
 69+ $prefixSize = strlen( $prefix );
6770 $additional_template_text = "";
6871 foreach ( $wgRequest->getValues() as $key => $value ) {
69 - if ( substr( $key, 0, 11 ) == '_unhandled_' ) {
70 - $field_name = urldecode( substr( $key, 11 ) );
 72+ if ( strpos( $key, $prefix ) === 0 ) {
 73+ $field_name = urldecode( substr( $key, $prefixSize ) );
7174 $additional_template_text .= "|$field_name=$value\n";
7275 }
7376 }