r78133 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78132‎ | r78133 | r78134 >
Date:19:20, 9 December 2010
Author:yaron
Status:deferred
Tags:
Comment:
Removed all inline Javascript, most global variables intended for use by Javascript, and some HTML elements, a part of the overall simplification of the Javascript handling
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -148,8 +148,7 @@
149149 global $wgRequest, $wgUser, $wgParser;
150150 global $sfgTabIndex; // used to represent the current tab index in the form
151151 global $sfgFieldNum; // used for setting various HTML IDs
152 - global $sfgJSValidationCalls; // array of Javascript calls to determine if page can be saved
153 - global $sfgAdderButtons, $sfgRemoverButtons;
 152+ global $sfgAdderButtons;
154153
155154 // initialize some variables
156155 $sfgTabIndex = 1;
@@ -231,8 +230,6 @@
232231 $wgOut->readOnlyPage( null, false, $permissionErrors, 'edit' );
233232 $wgOut->addHTML( "\n<hr />\n" );
234233 }
235 - $javascript_text = "";
236 - $fields_javascript_text = "";
237234
238235 // Remove <noinclude> sections and <includeonly> tags from form definition
239236 $form_def = StringUtils::delimiterReplace( '<noinclude>', '</noinclude>', '', $form_def );
@@ -705,7 +702,7 @@
706703 } else {
707704 $default_value = $cur_value;
708705 }
709 - list( $new_text, $new_javascript_text ) = SFTextAreaInput::getText( $default_value, 'free_text', false, ( $form_is_disabled || $is_restricted ), $field_args );
 706+ $new_text = SFTextAreaInput::getText( $default_value, 'free_text', false, ( $form_is_disabled || $is_restricted ), $field_args );
710707 if ( in_array( 'edittools', $free_text_components ) ) {
711708 // borrowed from EditPage::showEditTools()
712709 $options[] = 'parse';
@@ -718,7 +715,6 @@
719716
720717 END;
721718 }
722 - $fields_javascript_text .= $new_javascript_text;
723719 }
724720 $free_text_was_included = true;
725721 // add a similar placeholder to the data text
@@ -939,10 +935,8 @@
940936 $cur_value = $cur_value_in_template;
941937 }
942938 }
943 - list( $new_text, $new_javascript_text ) = $this->formFieldHTML( $form_field, $cur_value );
 939+ $new_text = $this->formFieldHTML( $form_field, $cur_value );
944940
945 - $fields_javascript_text .= $new_javascript_text;
946 -
947941 // if this field is disabled, add a hidden field holding
948942 // the value of this field, because disabled inputs for some
949943 // reason don't submit their value
@@ -964,40 +958,6 @@
965959 $template_text .= "\n|$field_name=$cur_value_in_template";
966960 }
967961 $section = substr_replace( $section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
968 - // also add to Javascript validation code
969 - $input_id = "input_" . $sfgFieldNum;
970 - $info_id = "info_" . $sfgFieldNum;
971 - if ( $is_mandatory ) {
972 - if ( $input_type == 'date' || $input_type == 'datetime' || $input_type == 'datetime with timezone' ||
973 - ( $input_type == '' && $form_field->template_field->propertyIsOfType( '_dat' ) ) ) {
974 - $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_month', '$info_id')";
975 - $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_day', '$info_id')";
976 - $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_year', '$info_id')";
977 - if ( $input_type == 'datetime' || $input_type == 'datetime with timezone' ) {
978 - // TODO - validate the time fields
979 - if ( $input_type == 'datetime with timezone' ) {
980 - // TODO - validate the timezone
981 - }
982 - }
983 - } else {
984 - if ( $allow_multiple ) {
985 - if ( $all_instances_printed ) {
986 - $sfgJSValidationCalls[] = "validate_multiple_mandatory_fields($sfgFieldNum)";
987 - } else {
988 - $sfgJSValidationCalls[] = "validate_mandatory_field(\"input_$sfgFieldNum\", \"info_$sfgFieldNum\")";
989 - }
990 - } elseif ( $input_type == 'radiobutton' || $input_type == 'category' ) {
991 - // only add this if there's a "None" option
992 - if ( empty( $default_value ) ) {
993 - $sfgJSValidationCalls[] = "validate_mandatory_radiobutton('$input_id', '$info_id')";
994 - }
995 - } elseif ( ( $form_field->template_field->is_list && $form_field->template_field->field_type == 'enumeration' && $input_type != 'listbox' ) || ( $input_type == 'checkboxes' ) ) {
996 - $sfgJSValidationCalls[] = "validate_mandatory_checkboxes('$input_id', '$info_id')";
997 - } else {
998 - $sfgJSValidationCalls[] = "validate_mandatory_field('$input_id', '$info_id')";
999 - }
1000 - }
1001 - }
1002962 } else {
1003963 $start_position = $brackets_end_loc;
1004964 }
@@ -1143,24 +1103,21 @@
11441104 // in the form, to differentiate the inputs the form starts out
11451105 // with from any inputs added by the Javascript
11461106 $section = str_replace( '[num]', "[{$instance_num}a]", $section );
1147 - $wrapperID = "wrapper_$sfgFieldNum";
1148 - $removerID = "remover_$sfgFieldNum";
11491107 $remove_text = wfMsg( 'sf_formedit_remove' );
11501108 $form_text .= <<<END
1151 - <div id="$wrapperID" class="multipleTemplate">
 1109+ <div class="multipleTemplate">
11521110 $section
1153 - <input type="button" id="$removerID" value="$remove_text" tabindex="$sfgTabIndex" class="remove" />
 1111+ <input type="button" value="$remove_text" tabindex="$sfgTabIndex" class="remover" />
11541112 </div>
11551113
11561114 END;
1157 - $sfgRemoverButtons[] = "$removerID,$wrapperID";
11581115 // this will cause the section to be re-parsed on the next go
11591116 $section_num--;
11601117 } else {
11611118 // this is the last instance of this template - stick an 'add'
11621119 // button in the form
11631120 $form_text .= <<<END
1164 - <div id="starter_$query_template_name" class="multipleTemplate" style="display: none;">
 1121+ <div id="starter_$query_template_name" class="multipleTemplateStarter" style="display: none;">
11651122 $section
11661123 </div>
11671124 <div id="main_$query_template_name"></div>
@@ -1266,6 +1223,7 @@
12671224 END;
12681225
12691226 // add Javascript code for form-wide use
 1227+ $javascript_text = "";
12701228 if ( $free_text_was_included && $showFCKEditor > 0 ) {
12711229 $javascript_text .= SFFormUtils::mainFCKJavascript( $showFCKEditor );
12721230 if ( $showFCKEditor & ( RTE_TOGGLE_LINK | RTE_POPUP ) ) {
@@ -1281,7 +1239,7 @@
12821240 // if doing a replace, the data text is actually the modified original page
12831241 if ( $wgRequest->getCheck( 'partial' ) )
12841242 $data_text = $existing_page_content;
1285 - $javascript_text .= $fields_javascript_text;
 1243+
12861244 global $wgParser;
12871245 $new_text = "";
12881246 if ( !$embedded )
@@ -1309,7 +1267,6 @@
13101268
13111269 if ( $form_field->is_hidden ) {
13121270 $text = SFFormUtils::hiddenFieldHTML( $form_field->input_name, $cur_value );
1313 - $javascript_text = "";
13141271 } elseif ( $form_field->input_type != '' &&
13151272 array_key_exists( $form_field->input_type, $this->mInputTypeHooks ) &&
13161273 $this->mInputTypeHooks[$form_field->input_type] != null ) {
@@ -1324,7 +1281,7 @@
13251282 $hook_values = $this->mInputTypeHooks[$form_field->input_type];
13261283 $other_args = $form_field->getArgumentsForInputCall( $hook_values[1] );
13271284 $funcArgs[] = $other_args;
1328 - list( $text, $javascript_text ) = call_user_func_array( $hook_values[0], $funcArgs );
 1285+ $text = call_user_func_array( $hook_values[0], $funcArgs );
13291286 } else { // input type not defined in form
13301287 $field_type = $template_field->field_type;
13311288 $is_list = ( $form_field->is_list || $template_field->is_list );
@@ -1339,7 +1296,7 @@
13401297 $hook_values = $this->mSemanticTypeHooks[$field_type][$is_list];
13411298 $other_args = $form_field->getArgumentsForInputCall( $hook_values[1] );
13421299 $funcArgs[] = $other_args;
1343 - list( $text, $javascript_text ) = call_user_func_array( $hook_values[0], $funcArgs );
 1300+ $text = call_user_func_array( $hook_values[0], $funcArgs );
13441301 } else { // anything else
13451302 $other_args = $form_field->getArgumentsForInputCall();
13461303 // special call to ensure that a list input is the right default size
@@ -1347,10 +1304,10 @@
13481305 if ( ! array_key_exists( 'size', $other_args ) )
13491306 $other_args['size'] = 100;
13501307 }
1351 - list( $text, $javascript_text ) = SFTextInput::getText( $cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $other_args );
 1308+ $text = SFTextInput::getText( $cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $other_args );
13521309 }
13531310 }
1354 - return array( $text, $javascript_text );
 1311+ return $text;
13551312 }
13561313
13571314 }

Status & tagging log