r83126 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83125‎ | r83126 | r83127 >
Date:01:22, 3 March 2011
Author:yaron
Status:deferred
Tags:
Comment:
Removed getAlternateInputTypes() method; added new SFYearInput class; removed 'datetime with timezone' input type; switched order of SFTextAreaInput and SFTextAreaWithAutocompletInput classes
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormInputs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php
@@ -14,15 +14,6 @@
1515 */
1616 class SFFormInput {
1717 /**
18 - * Returns the set of input types, other than the main one, defined
19 - * by this class; with the set of additional field arguments to
20 - * be passed to each one.
21 - */
22 - public static function getAlternateInputTypes() {
23 - return array();
24 - }
25 -
26 - /**
2718 * Returns the set of SMW property types for which this input is
2819 * meant to be the default one - ideally, no more than one input
2920 * should declare itself the default for any specific type.
@@ -141,12 +132,6 @@
142133 return 'text';
143134 }
144135
145 - public static function getAlternateInputTypes() {
146 - return array(
147 - array( 'year', array( 'size' => 4 ) )
148 - );
149 - }
150 -
151136 public static function getDefaultPropTypes() {
152137 return array(
153138 '_str' => array( 'field_type' => 'string' ),
@@ -792,13 +777,13 @@
793778 }
794779 }
795780
796 -class SFTextAreaWithAutocompleteInput extends SFTextAreaInput {
 781+class SFTextAreaInput extends SFFormInput {
797782 public static function getName() {
798 - return 'textarea with autocomplete';
 783+ return 'textarea';
799784 }
800785
801786 public static function getDefaultPropTypes() {
802 - return array();
 787+ return array( '_txt' => array(), '_cod' => array() );
803788 }
804789
805790 public static function getOtherPropTypesHandled() {
@@ -810,22 +795,14 @@
811796 }
812797
813798 static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
814 - // If 'no autocomplete' was specified, print a regular
815 - // textarea instead.
816 - if ( array_key_exists( 'no autocomplete', $other_args ) &&
817 - $other_args['no autocomplete'] == true ) {
818 - unset( $other_args['autocompletion source'] );
819 - return SFTextAreaInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
820 - }
821 -
822799 global $sfgTabIndex, $sfgFieldNum;
823800
824 - list( $autocompleteSettings, $remoteDataType, $delimiter ) = SFTextWithAutocompleteInput::setAutocompleteValues( $other_args );
825 -
826 - $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput";
827 - if ( array_key_exists( 'class', $other_args ) )
 801+ $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
 802+ if ( array_key_exists( 'class', $other_args ) ) {
828803 $className .= " " . $other_args['class'];
829 - $input_id = "input_" . $sfgFieldNum;
 804+ }
 805+ // Use a special ID for the free text field, for FCK's needs.
 806+ $input_id = $input_name == "free_text" ? "free_text" : "input_$sfgFieldNum";
830807
831808 if ( array_key_exists( 'rows', $other_args ) ) {
832809 $rows = $other_args['rows'];
@@ -837,7 +814,7 @@
838815 } else {
839816 $cols = 80;
840817 }
841 - $text = "";
 818+
842819 if ( array_key_exists( 'autogrow', $other_args ) ) {
843820 $className .= ' autoGrow';
844821 }
@@ -849,60 +826,48 @@
850827 'rows' => $rows,
851828 'cols' => $cols,
852829 'class' => $className,
853 - 'autocompletesettings' => $autocompleteSettings,
854830 );
855 - if ( !is_null( $remoteDataType ) ) {
856 - $textarea_attrs['autocompletedatatype'] = $remoteDataType;
857 - }
858831 if ( $is_disabled ) {
859832 $textarea_attrs['disabled'] = 'disabled';
860833 }
861834 if ( array_key_exists( 'maxlength', $other_args ) ) {
862835 $maxlength = $other_args['maxlength'];
863836 // For every actual character pressed (i.e., excluding
864 - // things like the Shift key), reduce the string to
865 - // its allowed length if it's exceeded that.
 837+ // things like the Shift key), reduce the string to its
 838+ // allowed length if it's exceeded that.
866839 // This JS code is complicated so that it'll work
867840 // correctly in IE - IE moves the cursor to the end
868 - // whenever this.value is reset, so we'll make sure
869 - // to do that only when we need to.
 841+ // whenever this.value is reset, so we'll make sure to
 842+ // do that only when we need to.
870843 $maxLengthJSCheck = "if (window.event && window.event.keyCode < 48 && window.event.keyCode != 13) return; if (this.value.length > $maxlength) { this.value = this.value.substring(0, $maxlength); }";
871844 $textarea_attrs['onKeyDown'] = $maxLengthJSCheck;
872845 $textarea_attrs['onKeyUp'] = $maxLengthJSCheck;
873846 }
874 - $textarea_input = Xml::element('textarea', $textarea_attrs, $cur_value, false);
875 - $text .= $textarea_input;
876 -
877 - if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) {
878 - if ( array_key_exists( 'default filename', $other_args ) ) {
879 - $default_filename = $other_args['default filename'];
880 - } else {
881 - $default_filename = "";
882 - }
883 - $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename );
884 - }
885 -
 847+ $text = Xml::element( 'textarea', $textarea_attrs, $cur_value, false );
886848 $spanClass = "inputSpan";
887849 if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
888 - $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text );
889 -
 850+ $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
890851 return $text;
891852 }
892853
893854 public static function getParameters() {
894855 $params = parent::getParameters();
895 - $params = array_merge( $params, SFTextWithAutocompleteInput::getAutocompletionParameters() );
 856+ $params[] = array( 'name' => 'preload', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_preload' ) );
 857+ $params[] = array( 'name' => 'rows', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_rows' ) );
 858+ $params[] = array( 'name' => 'cols', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_cols' ) );
 859+ $params[] = array( 'name' => 'maxlength', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_maxlength' ) );
 860+ $params[] = array( 'name' => 'autogrow', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_autogrow' ) );
896861 return $params;
897862 }
898863 }
899864
900 -class SFTextAreaInput extends SFFormInput {
 865+class SFTextAreaWithAutocompleteInput extends SFTextAreaInput {
901866 public static function getName() {
902 - return 'textarea';
 867+ return 'textarea with autocomplete';
903868 }
904869
905870 public static function getDefaultPropTypes() {
906 - return array( '_txt' => array(), '_cod' => array() );
 871+ return array();
907872 }
908873
909874 public static function getOtherPropTypesHandled() {
@@ -914,14 +879,22 @@
915880 }
916881
917882 static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 883+ // If 'no autocomplete' was specified, print a regular
 884+ // textarea instead.
 885+ if ( array_key_exists( 'no autocomplete', $other_args ) &&
 886+ $other_args['no autocomplete'] == true ) {
 887+ unset( $other_args['autocompletion source'] );
 888+ return SFTextAreaInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
 889+ }
 890+
918891 global $sfgTabIndex, $sfgFieldNum;
919892
920 - $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
921 - if ( array_key_exists( 'class', $other_args ) ) {
 893+ list( $autocompleteSettings, $remoteDataType, $delimiter ) = SFTextWithAutocompleteInput::setAutocompleteValues( $other_args );
 894+
 895+ $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput";
 896+ if ( array_key_exists( 'class', $other_args ) )
922897 $className .= " " . $other_args['class'];
923 - }
924 - // Use a special ID for the free text field, for FCK's needs.
925 - $input_id = $input_name == "free_text" ? "free_text" : "input_$sfgFieldNum";
 898+ $input_id = "input_" . $sfgFieldNum;
926899
927900 if ( array_key_exists( 'rows', $other_args ) ) {
928901 $rows = $other_args['rows'];
@@ -933,7 +906,7 @@
934907 } else {
935908 $cols = 80;
936909 }
937 -
 910+ $text = "";
938911 if ( array_key_exists( 'autogrow', $other_args ) ) {
939912 $className .= ' autoGrow';
940913 }
@@ -945,37 +918,49 @@
946919 'rows' => $rows,
947920 'cols' => $cols,
948921 'class' => $className,
 922+ 'autocompletesettings' => $autocompleteSettings,
949923 );
 924+ if ( !is_null( $remoteDataType ) ) {
 925+ $textarea_attrs['autocompletedatatype'] = $remoteDataType;
 926+ }
950927 if ( $is_disabled ) {
951928 $textarea_attrs['disabled'] = 'disabled';
952929 }
953930 if ( array_key_exists( 'maxlength', $other_args ) ) {
954931 $maxlength = $other_args['maxlength'];
955932 // For every actual character pressed (i.e., excluding
956 - // things like the Shift key), reduce the string to its
957 - // allowed length if it's exceeded that.
 933+ // things like the Shift key), reduce the string to
 934+ // its allowed length if it's exceeded that.
958935 // This JS code is complicated so that it'll work
959936 // correctly in IE - IE moves the cursor to the end
960 - // whenever this.value is reset, so we'll make sure to
961 - // do that only when we need to.
 937+ // whenever this.value is reset, so we'll make sure
 938+ // to do that only when we need to.
962939 $maxLengthJSCheck = "if (window.event && window.event.keyCode < 48 && window.event.keyCode != 13) return; if (this.value.length > $maxlength) { this.value = this.value.substring(0, $maxlength); }";
963940 $textarea_attrs['onKeyDown'] = $maxLengthJSCheck;
964941 $textarea_attrs['onKeyUp'] = $maxLengthJSCheck;
965942 }
966 - $text = Xml::element( 'textarea', $textarea_attrs, $cur_value, false );
 943+ $textarea_input = Xml::element('textarea', $textarea_attrs, $cur_value, false);
 944+ $text .= $textarea_input;
 945+
 946+ if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) {
 947+ if ( array_key_exists( 'default filename', $other_args ) ) {
 948+ $default_filename = $other_args['default filename'];
 949+ } else {
 950+ $default_filename = "";
 951+ }
 952+ $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename );
 953+ }
 954+
967955 $spanClass = "inputSpan";
968956 if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
969 - $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 957+ $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 958+
970959 return $text;
971960 }
972961
973962 public static function getParameters() {
974963 $params = parent::getParameters();
975 - $params[] = array( 'name' => 'preload', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_preload' ) );
976 - $params[] = array( 'name' => 'rows', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_rows' ) );
977 - $params[] = array( 'name' => 'cols', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_cols' ) );
978 - $params[] = array( 'name' => 'maxlength', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_maxlength' ) );
979 - $params[] = array( 'name' => 'autogrow', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_autogrow' ) );
 964+ $params = array_merge( $params, SFTextWithAutocompleteInput::getAutocompletionParameters() );
980965 return $params;
981966 }
982967 }
@@ -1083,12 +1068,6 @@
10841069 return 'datetime';
10851070 }
10861071
1087 - public static function getAlternateInputTypes() {
1088 - return array(
1089 - array( 'datetime with timezone', array( 'include_timezone' => true ) )
1090 - );
1091 - }
1092 -
10931072 public static function getDefaultPropTypes() {
10941073 return array();
10951074 }
@@ -1100,7 +1079,7 @@
11011080 static function getHTML( $datetime, $input_name, $is_mandatory, $is_disabled, $other_args ) {
11021081 global $sfgTabIndex, $sfg24HourTime;
11031082
1104 - $include_timezone = $other_args['include_timezone'];
 1083+ $include_timezone = array_key_exists( 'include timezone', $other_args );
11051084
11061085 if ( $datetime ) {
11071086 // Can show up here either as an array or a string,
@@ -1192,6 +1171,35 @@
11931172 }
11941173 }
11951174
 1175+class SFYearInput extends SFTextInput {
 1176+ public static function getName() {
 1177+ return 'year';
 1178+ }
 1179+
 1180+ public static function getDefaultPropTypes() {
 1181+ return array();
 1182+ }
 1183+
 1184+ public static function getOtherPropTypesHandled() {
 1185+ return array( '_dat' );
 1186+ }
 1187+
 1188+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 1189+ $other_args['size'] = 4;
 1190+ return parent::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
 1191+ }
 1192+
 1193+ public static function getParameters() {
 1194+ $params = array();
 1195+ $params[] = array( 'name' => 'mandatory', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_mandatory' ) );
 1196+ $params[] = array( 'name' => 'restricted', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_restricted' ) );
 1197+ $params[] = array( 'name' => 'class', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_class' ) );
 1198+ $params[] = array( 'name' => 'default', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_default' ) );
 1199+ $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) );
 1200+ return $params;
 1201+ }
 1202+}
 1203+
11961204 class SFRadioButtonInput extends SFEnumInput {
11971205 public static function getName() {
11981206 return 'radiobutton';