r71484 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71483‎ | r71484 | r71485 >
Date:14:02, 23 August 2010
Author:yaron
Status:deferred
Tags:
Comment:
Added 'combobox' input and validation; changed strReplaceOnce() to strReplaceFirst(); other small changes
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -64,6 +64,7 @@
6565 $this->setInputTypeHook( 'radiobutton', array( 'SFFormInputs', 'radioButtonHTML' ), array() );
6666 $this->setInputTypeHook( 'checkboxes', array( 'SFFormInputs', 'checkboxesHTML' ), array() );
6767 $this->setInputTypeHook( 'listbox', array( 'SFFormInputs', 'listboxHTML' ), array() );
 68+ $this->setInputTypeHook( 'combobox', array( 'SFFormInputs', 'comboboxHTML' ), array() );
6869 $this->setInputTypeHook( 'category', array( 'SFFormInputs', 'categoryHTML' ), array() );
6970 $this->setInputTypeHook( 'categories', array( 'SFFormInputs', 'categoriesHTML' ), array() );
7071
@@ -132,7 +133,7 @@
133134 * - this might make sense in some SF utils class, if it's useful in
134135 * other places.
135136 */
136 - function strReplaceOnce( $search, $replace, $subject) {
 137+ function strReplaceFirst( $search, $replace, $subject) {
137138 $firstChar = strpos( $subject, $search );
138139 if ( $firstChar !== false ) {
139140 $beforeStr = substr( $subject, 0, $firstChar );
@@ -254,8 +255,9 @@
255256 }
256257 }
257258 // otherwise, parse it
258 - if ( ! $got_form_def_from_cache )
 259+ if ( ! $got_form_def_from_cache ) {
259260 $form_def = $wgParser->parse( $form_def, $this->mPageTitle, $wgParser->mOptions )->getText();
 261+ }
260262 $wgParser->mStripState = $old_strip_state;
261263
262264 // turn form definition file into an array of sections, one for each
@@ -440,7 +442,7 @@
441443 $existing_page_content = str_replace( $existing_template_text, '{{{insertionpoint}}}', $existing_page_content );
442444 }
443445 } else {
444 - $existing_page_content = self::strReplaceOnce( $existing_template_text, '', $existing_page_content );
 446+ $existing_page_content = self::strReplaceFirst( $existing_template_text, '', $existing_page_content );
445447 }
446448 // if this is not a multiple-instance template, and we've found
447449 // a match in the source page, there's a good chance that this
@@ -822,7 +824,7 @@
823825 // form values, see if the current input is part of that formula,
824826 // and if so, substitute in the actual value
825827 if ( $form_submitted && $generated_page_name != '' ) {
826 - // this line appears unnecessary
 828+ // this line appears to be unnecessary
827829 // $generated_page_name = str_replace('.', '_', $generated_page_name);
828830 $generated_page_name = str_replace( ' ', '_', $generated_page_name );
829831 $escaped_input_name = str_replace( ' ', '_', $input_name );
@@ -973,6 +975,8 @@
974976 if ( empty( $default_value ) ) {
975977 $sfgJSValidationCalls[] = "validate_mandatory_radiobutton('$input_id', '$info_id')";
976978 }
 979+ } elseif ( $input_type == 'combobox' ) {
 980+ $sfgJSValidationCalls[] = "validate_mandatory_combobox('$input_id', '$info_id')";
977981 } elseif ( ( $form_field->template_field->is_list && $form_field->template_field->field_type == 'enumeration' && $input_type != 'listbox' ) || ( $input_type == 'checkboxes' ) ) {
978982 $sfgJSValidationCalls[] = "validate_mandatory_checkboxes('$input_id', '$info_id')";
979983 } else {
@@ -1267,6 +1271,12 @@
12681272 $new_text = "";
12691273 if ( !$embedded )
12701274 $new_text = $wgParser->preprocess( str_replace( "{{!}}", "|", $form_page_title ), $this->mPageTitle, new ParserOptions() );
 1275+
 1276+ // keep it simple - if the form has already been submitted, i.e. this is
 1277+ // just the redirect page, get rid of all the Javascript, to avoid JS errors
 1278+ if ( $form_submitted ) {
 1279+ $javascript_text = '';
 1280+ }
12711281
12721282 return array( $form_text, "/*<![CDATA[*/ $javascript_text /*]]>*/",
12731283 $data_text, $new_text, $generated_page_name );

Status & tagging log