r85657 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85656‎ | r85657 | r85658 >
Date:03:18, 8 April 2011
Author:yaron
Status:deferred
Tags:
Comment:
Two fixes: fixed handling of fields contained in template calls but not in the form, so that they don't also show up in multiple-instance templates; and fixed "default=" value so that it only applies when the form is first displayed. Also some minor formatting fixes.
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -619,11 +619,13 @@
620620 // =====================================================
621621 } elseif ( $tag_title == 'end template' ) {
622622 if ( $source_is_page ) {
623 - // add any unhandled template fields in the page as hidden variables
624 - if ( isset( $template_contents ) )
 623+ // Add any unhandled template fields in the page as hidden variables.
 624+ if ( isset( $template_contents ) ) {
625625 $form_text .= SFFormUtils::unhandledFieldsHTML( $template_contents );
 626+ $template_contents = null;
 627+ }
626628 }
627 - // remove this tag, reset some variables, and close off form HTML tag
 629+ // Remove this tag, reset some variables, and close off form HTML tag.
628630 $section = substr_replace( $section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
629631 $template_name = null;
630632 if ( isset( $template_label ) ) {
@@ -791,7 +793,7 @@
792794 $cur_value = '';
793795 }
794796
795 - if ( empty( $cur_value ) ) {
 797+ if ( empty( $cur_value ) && !$form_submitted ) {
796798 if ( $default_value ) {
797799 // Set to the default value specified in the form, if it's there.
798800 $cur_value = $default_value;
@@ -1109,13 +1111,14 @@
11101112 }
11111113
11121114 if ( $new_text ) {
1113 - // include the field name only for non-numeric field names
 1115+ // Include the field name only for non-numeric field names.
11141116 if ( is_numeric( $field_name ) ) {
11151117 $template_text .= "|$cur_value_in_template";
11161118 } else {
1117 - // if the value is null, don't include it at all
1118 - if ( $cur_value_in_template != '' )
 1119+ // If the value is null, don't include it at all.
 1120+ if ( $cur_value_in_template != '' ) {
11191121 $template_text .= "\n|$field_name=$cur_value_in_template";
 1122+ }
11201123 }
11211124 $section = substr_replace( $section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
11221125 } else {
@@ -1231,21 +1234,24 @@
12321235
12331236 if ( ! $all_instances_printed ) {
12341237 if ( $template_text != '' ) {
1235 - // for mostly aesthetic purposes, if the template call ends with
 1238+ // For mostly aesthetic purposes, if the template call ends with
12361239 // a bunch of pipes (i.e., it's an indexed template with unused
1237 - // parameters at the end), remove the pipes
 1240+ // parameters at the end), remove the pipes.
12381241 $template_text = preg_replace( '/\|*$/', '', $template_text );
12391242 // add another newline before the final bracket, if this template
12401243 // call is already more than one line
1241 - if ( strpos( $template_text, "\n" ) )
 1244+ if ( strpos( $template_text, "\n" ) ) {
12421245 $template_text .= "\n";
1243 - // if we're editing an existing page, and there were fields in
1244 - // the template call not handled by this form, preserve those
1245 - $template_text .= SFFormUtils::addUnhandledFields();
 1246+ }
 1247+ // If we're editing an existing page, and there were fields in
 1248+ // the template call not handled by this form, preserve those.
 1249+ if ( !$allow_multiple ) {
 1250+ $template_text .= SFFormUtils::addUnhandledFields();
 1251+ }
12461252 $template_text .= "}}";
12471253 $data_text .= $template_text . "\n";
1248 - // if there is a placeholder in the text, we know that we are
1249 - // doing a replace
 1254+ // If there is a placeholder in the text, we know that we are
 1255+ // doing a replace.
12501256 if ( $existing_page_content && strpos( $existing_page_content, '{{{insertionpoint}}}', 0 ) !== false ) {
12511257 $existing_page_content = preg_replace( '/\{\{\{insertionpoint\}\}\}(\r?\n?)/',
12521258 preg_replace( '/\}\}/m', '}�',