r83176 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83175‎ | r83176 | r83177 >
Date:23:14, 3 March 2011
Author:yaron
Status:deferred
Tags:
Comment:
Fixed retrieval of autocompletion values for 'combobox' input by, among other things, creating a new helper function; added explicit 'public' declaration for all public methods
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormInputs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php
@@ -158,7 +158,7 @@
159159 return array( '_wpg' );
160160 }
161161
162 - static function uploadLinkHTML( $input_id, $delimiter = null, $default_filename = null ) {
 162+ public static function uploadLinkHTML( $input_id, $delimiter = null, $default_filename = null ) {
163163 $upload_window_page = SpecialPage::getPage( 'UploadWindow' );
164164 $query_string = "sfInputID=$input_id";
165165 if ( $delimiter != null )
@@ -183,7 +183,7 @@
184184 return $text;
185185 }
186186
187 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 187+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
188188 global $sfgTabIndex, $sfgFieldNum;
189189
190190 $className = "createboxInput";
@@ -282,7 +282,7 @@
283283 return array();
284284 }
285285
286 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 286+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
287287 global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
288288
289289 $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
@@ -345,7 +345,7 @@
346346 return 'listbox';
347347 }
348348
349 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 349+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
350350 global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
351351
352352 $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
@@ -432,7 +432,7 @@
433433 return array();
434434 }
435435
436 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 436+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
437437 global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
438438
439439 $checkbox_class = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
@@ -518,7 +518,7 @@
519519 return array( '_wpg', '_str' );
520520 }
521521
522 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 522+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
523523 // For backward compatibility with pre-SF-2.1 forms
524524 if ( array_key_exists( 'no autocomplete', $other_args ) &&
525525 $other_args['no autocomplete'] == true ) {
@@ -528,9 +528,6 @@
529529
530530 global $sfgTabIndex, $sfgFieldNum;
531531
532 - $autocomplete_field_type = "";
533 - $autocompletion_source = "";
534 -
535532 $className = "sfComboBox";
536533 if ( $is_mandatory ) {
537534 $className .= " mandatoryField";
@@ -539,14 +536,7 @@
540537 $className .= " " . $other_args['class'];
541538 }
542539 $disabled_text = ( $is_disabled ) ? "disabled" : "";
543 - if ( array_key_exists( 'autocomplete field type', $other_args ) ) {
544 - $autocomplete_field_type = $other_args['autocomplete field type'];
545 - $autocompletion_source = $other_args['autocompletion source'];
546 - if ( $autocomplete_field_type != 'external_url' ) {
547 - global $wgContLang;
548 - $autocompletion_source = $wgContLang->ucfirst( $autocompletion_source );
549 - }
550 - }
 540+
551541 if ( array_key_exists( 'size', $other_args ) ) {
552542 $size = $other_args['size'];
553543 } else {
@@ -558,8 +548,10 @@
559549 // browsers.
560550 $pixel_width = $size * 6 . "px";
561551
562 - $values = SFUtils::getAutocompleteValues($autocompletion_source, $autocomplete_field_type );
563 - $autocompletion_source = str_replace( "'", "\'", $autocompletion_source );
 552+ list( $autocompleteFieldType, $autocompletionSource ) =
 553+ SFTextWithAutocompleteInput::getAutocompletionTypeAndSource( $other_args );
 554+ $values = SFUtils::getAutocompleteValues($autocompletionSource, $autocompleteFieldType );
 555+ $autocompletionSource = str_replace( "'", "\'", $autocompletionSource );
564556
565557 $optionsText = Xml::element( 'option', array( 'value' => $cur_value ), null, false ) . "\n";
566558 foreach ( $values as $value ) {
@@ -571,7 +563,7 @@
572564 'name' => $input_name,
573565 'class' => $className,
574566 'tabindex' => $sfgTabIndex,
575 - 'autocompletesettings' => $autocompletion_source,
 567+ 'autocompletesettings' => $autocompletionSource,
576568 'comboboxwidth' => $pixel_width,
577569 );
578570 if ( array_key_exists( 'existing values only', $other_args ) ) {
@@ -619,9 +611,7 @@
620612 return array( '_str' );
621613 }
622614
623 - static function setAutocompleteValues( $field_args ) {
624 - global $sfgAutocompleteValues;
625 -
 615+ public static function getAutocompletionTypeAndSource( $field_args ) {
626616 if ( array_key_exists( 'values from property', $field_args ) ||
627617 array_key_exists( 'semantic_property', $field_args ) ) {
628618 if ( array_key_exists( 'values from property', $field_args ) ) {
@@ -667,8 +657,16 @@
668658 $autocompletionSource = $wgContLang->ucfirst( $autocompletionSource );
669659 }
670660
 661+ return array( $autocompleteFieldType, $autocompletionSource );
 662+ }
 663+
 664+ public static function setAutocompleteValues( $field_args ) {
 665+ global $sfgAutocompleteValues;
 666+
671667 // Get all autocomplete-related values, plus delimiter value
672668 // (it's needed also for the 'uploadable' link, if there is one).
 669+ list( $autocompleteFieldType, $autocompletionSource ) =
 670+ self::getAutocompletionTypeAndSource( $field_args );
673671 $autocompleteSettings = $autocompletionSource;
674672 $is_list = ( array_key_exists( 'is_list', $field_args ) && $field_args['is_list'] == true );
675673 if ( $is_list ) {
@@ -698,7 +696,7 @@
699697 return array( $autocompleteSettings, $remoteDataType, $delimiter );
700698 }
701699
702 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 700+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
703701 // Backwards compatibility, for pre-SF-2.1 forms:
704702 // if 'no autocomplete' was specified, switch to SFTextInput.
705703 if ( array_key_exists( 'no autocomplete', $other_args ) &&
@@ -794,7 +792,7 @@
795793 return array( '_wpg', '_str' );
796794 }
797795
798 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 796+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
799797 global $sfgTabIndex, $sfgFieldNum;
800798
801799 $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
@@ -878,7 +876,7 @@
879877 return array( '_wpg', '_str' );
880878 }
881879
882 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 880+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
883881 // If 'no autocomplete' was specified, print a regular
884882 // textarea instead.
885883 if ( array_key_exists( 'no autocomplete', $other_args ) &&
@@ -974,7 +972,7 @@
975973 return array( '_dat' => array() );
976974 }
977975
978 - static function monthDropdownHTML( $cur_month, $input_name, $is_disabled ) {
 976+ public static function monthDropdownHTML( $cur_month, $input_name, $is_disabled ) {
979977 global $sfgTabIndex, $wgAmericanDates;
980978
981979 $optionsText = "";
@@ -1000,7 +998,7 @@
1001999 return $text;
10021000 }
10031001
1004 - static function getMainHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 1002+ public static function getMainHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args ) {
10051003 global $sfgTabIndex, $sfgFieldNum, $wgAmericanDates;
10061004
10071005 $input_id = "input_$sfgFieldNum";
@@ -1054,7 +1052,7 @@
10551053 return $text;
10561054 }
10571055
1058 - static function getHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 1056+ public static function getHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args ) {
10591057 $text = self::getMainHTML( $date, $input_name, $is_mandatory, $is_disabled, $other_args );
10601058 $spanClass = "dateInput";
10611059 if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
@@ -1076,7 +1074,7 @@
10771075 return array( '_dat' );
10781076 }
10791077
1080 - static function getHTML( $datetime, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 1078+ public static function getHTML( $datetime, $input_name, $is_mandatory, $is_disabled, $other_args ) {
10811079 global $sfgTabIndex, $sfg24HourTime;
10821080
10831081 $include_timezone = array_key_exists( 'include timezone', $other_args );
@@ -1205,7 +1203,7 @@
12061204 return 'radiobutton';
12071205 }
12081206
1209 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 1207+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
12101208 global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
12111209
12121210 if ( ( $possible_values = $other_args['possible_values'] ) == null )
@@ -1298,7 +1296,7 @@
12991297 return array( '_boo' => array() );
13001298 }
13011299
1302 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 1300+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
13031301 global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
13041302
13051303 $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
@@ -1362,7 +1360,7 @@
13631361 return array( '_wpg' );
13641362 }
13651363
1366 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 1364+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
13671365 // escape if CategoryTree extension isn't included
13681366 if ( ! function_exists( 'efCategoryTreeParserHook' ) )
13691367 return null;
@@ -1450,7 +1448,7 @@
14511449 return array( '_wpg' );
14521450 }
14531451
1454 - static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 1452+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
14551453 // escape if CategoryTree extension isn't included
14561454 if ( ! function_exists( 'efCategoryTreeParserHook' ) )
14571455 return null;