r80171 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80170‎ | r80171 | r80172 >
Date:16:55, 13 January 2011
Author:yaron
Status:deferred
Tags:
Comment:
Simplified and improved the HTML for multiple-instance templates: div IDs replaced by classes, global JS variable removed. Also improved some comments.
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -158,7 +158,6 @@
159159 global $wgRequest, $wgUser, $wgParser;
160160 global $sfgTabIndex; // used to represent the current tab index in the form
161161 global $sfgFieldNum; // used for setting various HTML IDs
162 - global $sfgAdderButtons;
163162
164163 // initialize some variables
165164 $sfgTabIndex = 1;
@@ -355,23 +354,29 @@
356355 }
357356 }
358357 // If this is the first instance, add the label into the form, if
359 - // there is one.
360 - if ( ( $old_template_name != $template_name ) && isset( $template_label ) ) {
361 - $form_text .= "<fieldset>\n";
362 - $form_text .= "<legend>$template_label</legend>\n";
 358+ // there is one, and add the appropriate wrapper div, if this is
 359+ // a multiple-instance template.
 360+ if ( $old_template_name != $template_name ) {
 361+ if ( isset( $template_label ) ) {
 362+ $form_text .= "<fieldset>\n";
 363+ $form_text .= "<legend>$template_label</legend>\n";
 364+ }
 365+ if ($allow_multiple) {
 366+ $form_text .= "\t" . '<div class="multipleTemplateWrapper">' . "\n";
 367+ }
363368 }
364369 $template_text .= "{{" . $tif->template_name;
365370 $all_fields = $tif->getAllFields();
366371 // remove template tag
367372 $section = substr_replace( $section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
368373 $template_instance_query_values = $wgRequest->getArray( $query_template_name );
369 - // if we are editing a page, and this template can be found more than
 374+ // If we are editing a page, and this template can be found more than
370375 // once in that page, and multiple values are allowed, repeat this
371 - // section
 376+ // section.
372377 $existing_template_text = null;
373378 if ( $source_is_page || $form_is_partial ) {
374 - // replace underlines with spaces in template name, to allow for
375 - // searching on either
 379+ // Replace underlines with spaces in template name, to allow for
 380+ // searching on either.
376381 $search_template_str = str_replace( '_', ' ', $tif->template_name );
377382 $preg_match_template_str = str_replace(
378383 array( '/', '(', ')' ),
@@ -1126,32 +1131,30 @@
11271132 // with from any inputs added by the Javascript
11281133 $section = str_replace( '[num]', "[{$instance_num}a]", $section );
11291134 $remove_text = wfMsg( 'sf_formedit_remove' );
 1135+ // The "multipleTemplate" class is there for backwards-compatibility
 1136+ // with any custom CSS on people's wikis.
11301137 $form_text .= <<<END
1131 - <div class="multipleTemplate">
1132 - $section
1133 - <input type="button" value="$remove_text" tabindex="$sfgTabIndex" class="remover" />
1134 - </div>
 1138+ <div class="multipleTemplateInstance multipleTemplate">
 1139+ $section
 1140+ <input type="button" value="$remove_text" tabindex="$sfgTabIndex" class="remover" />
 1141+ </div>
11351142
11361143 END;
11371144 // this will cause the section to be re-parsed on the next go
11381145 $section_num--;
11391146 } else {
1140 - // this is the last instance of this template - stick an 'add'
1141 - // button in the form
 1147+ // This is the last instance of this template - print all the
 1148+ // sections necessary for adding additional instances.
11421149 $form_text .= <<<END
1143 - <div id="starter_$query_template_name" class="multipleTemplateStarter" style="display: none;">
1144 - $section
 1150+ <div class="multipleTemplateStarter" style="display: none;">
 1151+ $section
 1152+ </div>
 1153+ <div class="multipleTemplatePlaceholder"></div>
 1154+ <p style="margin-left:10px;" />
 1155+ <p><input type="button" value="$add_button_text" tabindex="$sfgTabIndex" class="multipleTemplateAdder" /></p>
11451156 </div>
1146 - <div id="main_$query_template_name"></div>
11471157
11481158 END;
1149 - $adderID = "adder_$sfgFieldNum";
1150 - $form_text .= <<<END
1151 - <p style="margin-left:10px;">
1152 - <p><input type="button" id="$adderID" value="$add_button_text" tabindex="$sfgTabIndex" class="addAnother" /></p>
1153 -
1154 -END;
1155 - $sfgAdderButtons[] = "$adderID,$query_template_name,$sfgFieldNum";
11561159 }
11571160 } else {
11581161 $form_text .= $section;

Status & tagging log