r82381 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82380‎ | r82381 | r82382 >
Date:07:02, 18 February 2011
Author:yaron
Status:deferred
Tags:
Comment:
Fixed some bugs, plus a changeover to the slightly modified form-definition syntax
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormInputs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php
@@ -188,11 +188,6 @@
189189 return SFTextWithAutocompleteInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
190190 }
191191
192 - // If there are possible values specified, call the dropdown
193 - // function.
194 - if ( array_key_exists( 'possible_values', $other_args ) && $other_args['possible_values'] != null )
195 - return SFDropdownInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
196 -
197192 global $sfgTabIndex, $sfgFieldNum;
198193
199194 $className = "createboxInput";
@@ -610,20 +605,50 @@
611606
612607 static function setAutocompleteValues( $field_args ) {
613608 global $sfgAutocompleteValues;
614 -
615 - $autocompletion_source = null;
616 - if ( array_key_exists( 'autocomplete field type', $field_args ) ) {
617 - $autocomplete_field_type = $field_args['autocomplete field type'];
618 - $autocompletion_source = $field_args['autocompletion source'];
619 - if ( $autocomplete_field_type != 'external_url' ) {
620 - global $wgContLang;
621 - $autocompletion_source = $wgContLang->ucfirst( $autocompletion_source );
 609+
 610+ if ( array_key_exists( 'values from property', $field_args ) ) {
 611+ $autocompletionSource = $field_args['values from property'];
 612+ $propValue = SMWPropertyValue::makeUserProperty( $autocompletionSource );
 613+ if ( $propValue->getPropertyTypeID() == '_wpg' ) {
 614+ $autocompleteFieldType = 'relation';
 615+ } else {
 616+ $autocompleteFieldType = 'attribute';
622617 }
 618+
 619+ } elseif ( array_key_exists( 'values from category', $field_args ) ) {
 620+ $autocompleteFieldType = 'category';
 621+ $autocompletionSource = $field_args['values from category'];
 622+ } elseif ( array_key_exists( 'values from concept', $field_args ) ) {
 623+ $autocompleteFieldType = 'concept';
 624+ $autocompletionSource = $field_args['values from concept'];
 625+ } elseif ( array_key_exists( 'values from namespace', $field_args ) ) {
 626+ $autocompleteFieldType = 'namespace';
 627+ $autocompletionSource = $field_args['values from namespace'];
 628+ } elseif ( array_key_exists( 'values from url', $field_args ) ) {
 629+ $autocompleteFieldType = 'external_url';
 630+ $autocompletionSource = $field_args['values from namespace'];
 631+ // Autocompletion from URL is always done remotely.
 632+ $field_args['remote autocompletion'] == true;
 633+ } elseif ( array_key_exists( 'values', $field_args ) ) {
 634+ global $sfgFieldNum;
 635+ $autocompleteFieldType = 'values';
 636+ $autocompletionSource = "values-$sfgFieldNum";
 637+ } elseif ( array_key_exists( 'autocomplete field type', $field_args ) ) {
 638+ $autocompleteFieldType = $field_args['autocomplete field type'];
 639+ $autocompletionSource = $field_args['autocompletion source'];
 640+ } else {
 641+ $autocompleteFieldType = null;
 642+ $autocompletionSource = null;
623643 }
624644
 645+ if ( $autocompleteFieldType != 'external_url' ) {
 646+ global $wgContLang;
 647+ $autocompletionSource = $wgContLang->ucfirst( $autocompletionSource );
 648+ }
 649+
625650 // Get all autocomplete-related values, plus delimiter value
626651 // (it's needed also for the 'uploadable' link, if there is one).
627 - $autocompleteSettings = $autocompletion_source;
 652+ $autocompleteSettings = $autocompletionSource;
628653 $is_list = ( array_key_exists( 'is_list', $field_args ) && $field_args['is_list'] == true );
629654 if ( $is_list ) {
630655 $autocompleteSettings .= ",list";
@@ -640,25 +665,26 @@
641666 $remoteDataType = null;
642667 if ( array_key_exists( 'remote autocompletion', $field_args ) &&
643668 $field_args['remote autocompletion'] == true ) {
644 - $remoteDataType = $autocomplete_field_type;
645 - } elseif ( $autocompletion_source != '' ) {
646 - $autocomplete_values = SFUtils::getAutocompleteValues( $autocompletion_source, $autocomplete_field_type );
647 - $sfgAutocompleteValues[$autocompleteSettings] = $autocomplete_values;
 669+ $remoteDataType = $autocompleteFieldType;
 670+ } elseif ( $autocompletionSource != '' ) {
 671+ if ( $autocompleteFieldType == 'values' ) {
 672+ $autocompleteValues = explode( ',', $field_args['values'] );
 673+ } else {
 674+ $autocompleteValues = SFUtils::getAutocompleteValues( $autocompletionSource, $autocompleteFieldType );
 675+ }
 676+ $sfgAutocompleteValues[$autocompleteSettings] = $autocompleteValues;
648677 }
649678 return array( $autocompleteSettings, $remoteDataType, $delimiter );
650679 }
651680
652681 static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
653 - // If 'no autocomplete' was specified, print a regular text
654 - // entry instead.
 682+ // Backwards compatibility, for pre-SF-2.1 forms:
 683+ // if 'no autocomplete' was specified, switch to SFTextInput.
655684 if ( array_key_exists( 'no autocomplete', $other_args ) &&
656685 $other_args['no autocomplete'] == true ) {
657686 unset( $other_args['autocompletion source'] );
658687 return SFTextInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
659688 }
660 - // if a set of values was specified, print a dropdown instead
661 - if ( array_key_exists( 'possible_values', $other_args ) && $other_args['possible_values'] != null )
662 - return SFDropdownInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
663689
664690 global $sfgTabIndex, $sfgFieldNum;
665691
@@ -669,11 +695,13 @@
670696 $className .= " " . $other_args['class'];
671697 $input_id = "input_" . $sfgFieldNum;
672698
673 -
674 - if ( array_key_exists( 'size', $other_args ) )
 699+ if ( array_key_exists( 'size', $other_args ) ) {
675700 $size = $other_args['size'];
676 - else
 701+ } elseif ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] ) {
 702+ $size = "100";
 703+ } else {
677704 $size = "35";
 705+ }
678706
679707 $inputAttrs = array(
680708 'type' => 'text',
@@ -718,6 +746,7 @@
719747 $params[] = array( 'name' => 'values from category', 'type' => 'string' );
720748 $params[] = array( 'name' => 'values from namespace', 'type' => 'string' );
721749 $params[] = array( 'name' => 'values from concept', 'type' => 'string' );
 750+ $params[] = array( 'name' => 'values from url', 'type' => 'string' );
722751 $params[] = array( 'name' => 'values', 'type' => 'string' );
723752 $params[] = array( 'name' => 'list', 'type' => 'boolean' );
724753 $params[] = array( 'name' => 'remote autocompletion', 'type' => 'boolean' );
@@ -824,6 +853,7 @@
825854 $params[] = array( 'name' => 'values from category', 'type' => 'string' );
826855 $params[] = array( 'name' => 'values from namespace', 'type' => 'string' );
827856 $params[] = array( 'name' => 'values from concept', 'type' => 'string' );
 857+ $params[] = array( 'name' => 'values from url', 'type' => 'string' );
828858 $params[] = array( 'name' => 'values', 'type' => 'string' );
829859 $params[] = array( 'name' => 'list', 'type' => 'boolean' );
830860 $params[] = array( 'name' => 'remote autocompletion', 'type' => 'boolean' );