r83180 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83179‎ | r83180 | r83181 >
Date:23:36, 3 March 2011
Author:yaron
Status:deferred
Tags:
Comment:
Rearranged classes into a more logical order - simplest to most involved
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormInputs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php
@@ -267,6 +267,154 @@
268268 }
269269 }
270270
 271+class SFTextAreaInput extends SFFormInput {
 272+ public static function getName() {
 273+ return 'textarea';
 274+ }
 275+
 276+ public static function getDefaultPropTypes() {
 277+ return array( '_txt' => array(), '_cod' => array() );
 278+ }
 279+
 280+ public static function getOtherPropTypesHandled() {
 281+ return array( '_wpg', '_str' );
 282+ }
 283+
 284+ public static function getOtherPropTypeListsHandled() {
 285+ return array( '_wpg', '_str' );
 286+ }
 287+
 288+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 289+ global $sfgTabIndex, $sfgFieldNum;
 290+
 291+ $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
 292+ if ( array_key_exists( 'class', $other_args ) ) {
 293+ $className .= " " . $other_args['class'];
 294+ }
 295+ // Use a special ID for the free text field, for FCK's needs.
 296+ $input_id = $input_name == "free_text" ? "free_text" : "input_$sfgFieldNum";
 297+
 298+ if ( array_key_exists( 'rows', $other_args ) ) {
 299+ $rows = $other_args['rows'];
 300+ } else {
 301+ $rows = 5;
 302+ }
 303+ if ( array_key_exists( 'cols', $other_args ) ) {
 304+ $cols = $other_args['cols'];
 305+ } else {
 306+ $cols = 80;
 307+ }
 308+
 309+ if ( array_key_exists( 'autogrow', $other_args ) ) {
 310+ $className .= ' autoGrow';
 311+ }
 312+
 313+ $textarea_attrs = array(
 314+ 'tabindex' => $sfgTabIndex,
 315+ 'id' => $input_id,
 316+ 'name' => $input_name,
 317+ 'rows' => $rows,
 318+ 'cols' => $cols,
 319+ 'class' => $className,
 320+ );
 321+ if ( $is_disabled ) {
 322+ $textarea_attrs['disabled'] = 'disabled';
 323+ }
 324+ if ( array_key_exists( 'maxlength', $other_args ) ) {
 325+ $maxlength = $other_args['maxlength'];
 326+ // For every actual character pressed (i.e., excluding
 327+ // things like the Shift key), reduce the string to its
 328+ // allowed length if it's exceeded that.
 329+ // This JS code is complicated so that it'll work
 330+ // correctly in IE - IE moves the cursor to the end
 331+ // whenever this.value is reset, so we'll make sure to
 332+ // do that only when we need to.
 333+ $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); }";
 334+ $textarea_attrs['onKeyDown'] = $maxLengthJSCheck;
 335+ $textarea_attrs['onKeyUp'] = $maxLengthJSCheck;
 336+ }
 337+ $text = Xml::element( 'textarea', $textarea_attrs, $cur_value, false );
 338+ $spanClass = "inputSpan";
 339+ if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
 340+ $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 341+ return $text;
 342+ }
 343+
 344+ public static function getParameters() {
 345+ $params = parent::getParameters();
 346+ $params[] = array( 'name' => 'preload', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_preload' ) );
 347+ $params[] = array( 'name' => 'rows', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_rows' ) );
 348+ $params[] = array( 'name' => 'cols', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_cols' ) );
 349+ $params[] = array( 'name' => 'maxlength', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_maxlength' ) );
 350+ $params[] = array( 'name' => 'autogrow', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_autogrow' ) );
 351+ return $params;
 352+ }
 353+}
 354+
 355+class SFCheckboxInput extends SFFormInput {
 356+ public static function getName() {
 357+ return 'checkbox';
 358+ }
 359+
 360+ public static function getDefaultPropTypes() {
 361+ return array( '_boo' => array() );
 362+ }
 363+
 364+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 365+ global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
 366+
 367+ $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
 368+ if ( array_key_exists( 'class', $other_args ) )
 369+ $className .= " " . $other_args['class'];
 370+ $input_id = "input_$sfgFieldNum";
 371+ $disabled_text = ( $is_disabled ) ? "disabled" : "";
 372+ if ( array_key_exists( 'show on select', $other_args ) ) {
 373+ $className .= " sfShowIfCheckedCheckbox";
 374+ $div_id = key( $other_args['show on select'] );
 375+ $sfgShowOnSelect[$input_id] = $div_id;
 376+ }
 377+
 378+ // Can show up here either as an array or a string, depending on
 379+ // whether it came from user input or a wiki page
 380+ if ( is_array( $cur_value ) ) {
 381+ $checked_str = ( array_key_exists( 'value', $cur_value ) && $cur_value['value'] == 'on' ) ? ' checked="checked"' : "";
 382+ } else {
 383+ // Default to false - no need to check if it matches
 384+ // a 'false' word.
 385+ $vlc = strtolower( trim( $cur_value ) );
 386+ // Manually load SMW's message values, if they weren't
 387+ // loaded before.
 388+ global $wgVersion;
 389+ if ( version_compare( $wgVersion, '1.16', '<' ) ) {
 390+ wfLoadExtensionMessages( 'SemanticMediaWiki' );
 391+ }
 392+ if ( in_array( $vlc, explode( ',', wfMsgForContent( 'smw_true_words' ) ), TRUE ) ) {
 393+ $checked_str = ' checked="checked"';
 394+ } else {
 395+ $checked_str = "";
 396+ }
 397+ }
 398+ $text = <<<END
 399+ <input name="{$input_name}[is_checkbox]" type="hidden" value="true" />
 400+ <input id="$input_id" name="{$input_name}[value]" type="checkbox" class="$className" tabindex="$sfgTabIndex" $checked_str $disabled_text/>
 401+
 402+END;
 403+ return $text;
 404+ }
 405+
 406+ public static function getParameters() {
 407+ // Remove the 'mandatory' option - it doesn't make sense for
 408+ // checkboxes.
 409+ $params = array();
 410+ foreach( parent::getParameters() as $param ) {
 411+ if ( $param['name'] != 'mandatory' ) {
 412+ $params[] = $param;
 413+ }
 414+ }
 415+ return $params;
 416+ }
 417+}
 418+
271419 class SFDropdownInput extends SFEnumInput {
272420 public static function getName() {
273421 return 'dropdown';
@@ -340,6 +488,95 @@
341489 }
342490 }
343491
 492+class SFRadioButtonInput extends SFEnumInput {
 493+ public static function getName() {
 494+ return 'radiobutton';
 495+ }
 496+
 497+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 498+ global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
 499+
 500+ if ( ( $possible_values = $other_args['possible_values'] ) == null )
 501+ $possible_values = array();
 502+
 503+ // Add a "None" value at the beginning, unless this is a
 504+ // mandatory field and there's a current value in place (either
 505+ // through a default value or because we're editing an existing
 506+ // page).
 507+ if ( ! $is_mandatory || $cur_value == '' ) {
 508+ array_unshift( $possible_values, '' );
 509+ }
 510+
 511+ // Set $cur_value to be one of the allowed options, if it isn't
 512+ // already - that makes it easier to automatically have one of
 513+ // the radiobuttons be checked at the beginning.
 514+ if ( ! in_array( $cur_value, $possible_values ) ) {
 515+ if ( in_array( '', $possible_values ) )
 516+ $cur_value = '';
 517+ else
 518+ $cur_value = $possible_values[0];
 519+ }
 520+
 521+ $text = '';
 522+ foreach ( $possible_values as $i => $possible_value ) {
 523+ $sfgTabIndex++;
 524+ $sfgFieldNum++;
 525+ $input_id = "input_$sfgFieldNum";
 526+
 527+ $radiobutton_attrs = array(
 528+ 'type' => 'radio',
 529+ 'id' => $input_id,
 530+ 'tabindex' => $sfgTabIndex,
 531+ 'name' => $input_name,
 532+ 'value' => $possible_value,
 533+ );
 534+ if ( $cur_value == $possible_value ) {
 535+ $radiobutton_attrs['checked'] = 'checked';
 536+ }
 537+ if ( $is_disabled ) {
 538+ $radiobutton_attrs['disabled'] = 'disabled';
 539+ }
 540+ if ( $possible_value == '' ) // blank/"None" value
 541+ $label = wfMsg( 'sf_formedit_none' );
 542+ elseif ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) )
 543+ $label = htmlspecialchars( $other_args['value_labels'][$possible_value] );
 544+ else
 545+ $label = $possible_value;
 546+
 547+ $text .= "\t" . Xml::element ( 'input', $radiobutton_attrs ) . " $label\n";
 548+ }
 549+
 550+ $spanClass = "radioButtonSpan";
 551+ if ( array_key_exists( 'class', $other_args ) ) {
 552+ $spanClass .= " " . $other_args['class'];
 553+ }
 554+ if ( $is_mandatory ) {
 555+ $spanClass .= " mandatoryFieldSpan";
 556+ }
 557+
 558+ $spanID = "span_$sfgFieldNum";
 559+
 560+ // Do the 'show on select' handling.
 561+ if ( array_key_exists( 'show on select', $other_args ) ) {
 562+ $spanClass .= " sfShowIfChecked";
 563+ foreach ( $other_args['show on select'] as $div_id => $options ) {
 564+ if ( array_key_exists( $spanID, $sfgShowOnSelect ) ) {
 565+ $sfgShowOnSelect[$spanID][] = array( $options, $div_id );
 566+ } else {
 567+ $sfgShowOnSelect[$spanID] = array( array( $options, $div_id ) );
 568+ }
 569+ }
 570+ }
 571+ $spanAttrs = array(
 572+ 'id' => $spanID,
 573+ 'class' => $spanClass
 574+ );
 575+ $text = Xml::tags( 'span', $spanAttrs, $text );
 576+
 577+ return $text;
 578+ }
 579+}
 580+
344581 class SFListBoxInput extends SFMultiEnumInput {
345582 public static function getName() {
346583 return 'listbox';
@@ -509,83 +746,6 @@
510747 }
511748 }
512749
513 -class SFComboBoxInput extends SFFormInput {
514 - public static function getName() {
515 - return 'combobox';
516 - }
517 -
518 - public static function getOtherPropTypesHandled() {
519 - return array( '_wpg', '_str' );
520 - }
521 -
522 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
523 - // For backward compatibility with pre-SF-2.1 forms
524 - if ( array_key_exists( 'no autocomplete', $other_args ) &&
525 - $other_args['no autocomplete'] == true ) {
526 - unset( $other_args['autocompletion source'] );
527 - return SFTextInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
528 - }
529 -
530 - global $sfgTabIndex, $sfgFieldNum;
531 -
532 - $className = "sfComboBox";
533 - if ( $is_mandatory ) {
534 - $className .= " mandatoryField";
535 - }
536 - if ( array_key_exists( 'class', $other_args ) ) {
537 - $className .= " " . $other_args['class'];
538 - }
539 - $disabled_text = ( $is_disabled ) ? "disabled" : "";
540 -
541 - if ( array_key_exists( 'size', $other_args ) ) {
542 - $size = $other_args['size'];
543 - } else {
544 - $size = "35";
545 - }
546 - // There's no direct correspondence between the 'size='
547 - // attribute for text inputs and the number of pixels, but
548 - // multiplying by 6 seems to be about right for the major
549 - // browsers.
550 - $pixel_width = $size * 6 . "px";
551 -
552 - list( $autocompleteFieldType, $autocompletionSource ) =
553 - SFTextWithAutocompleteInput::getAutocompletionTypeAndSource( $other_args );
554 - $values = SFUtils::getAutocompleteValues($autocompletionSource, $autocompleteFieldType );
555 - $autocompletionSource = str_replace( "'", "\'", $autocompletionSource );
556 -
557 - $optionsText = Xml::element( 'option', array( 'value' => $cur_value ), null, false ) . "\n";
558 - foreach ( $values as $value ) {
559 - $optionsText .= Xml::element( 'option', array( 'value' => $value ), $value ) . "\n";
560 - }
561 -
562 - $selectAttrs = array(
563 - 'id' => "input_$sfgFieldNum",
564 - 'name' => $input_name,
565 - 'class' => $className,
566 - 'tabindex' => $sfgTabIndex,
567 - 'autocompletesettings' => $autocompletionSource,
568 - 'comboboxwidth' => $pixel_width,
569 - );
570 - if ( array_key_exists( 'existing values only', $other_args ) ) {
571 - $selectAttrs['existingvaluesonly'] = 'true';
572 - }
573 - $selectText = Xml::tags( 'select', $selectAttrs, $optionsText );
574 -
575 - $divClass = "ui-widget";
576 - if ($is_mandatory) { $divClass .= " mandatory"; }
577 - $text = Xml::tags( 'div', array( 'class' => $divClass ), $selectText );
578 - return $text;
579 - }
580 -
581 - public static function getParameters() {
582 - $params = parent::getParameters();
583 - $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) );
584 - $params = array_merge( $params, SFEnumInput::getValuesParameters() );
585 - $params[] = array( 'name' => 'existing values only', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_existingvaluesonly' ) );
586 - return $params;
587 - }
588 -}
589 -
590750 class SFTextWithAutocompleteInput extends SFTextInput {
591751 public static function getName() {
592752 return 'text with autocomplete';
@@ -775,90 +935,6 @@
776936 }
777937 }
778938
779 -class SFTextAreaInput extends SFFormInput {
780 - public static function getName() {
781 - return 'textarea';
782 - }
783 -
784 - public static function getDefaultPropTypes() {
785 - return array( '_txt' => array(), '_cod' => array() );
786 - }
787 -
788 - public static function getOtherPropTypesHandled() {
789 - return array( '_wpg', '_str' );
790 - }
791 -
792 - public static function getOtherPropTypeListsHandled() {
793 - return array( '_wpg', '_str' );
794 - }
795 -
796 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
797 - global $sfgTabIndex, $sfgFieldNum;
798 -
799 - $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
800 - if ( array_key_exists( 'class', $other_args ) ) {
801 - $className .= " " . $other_args['class'];
802 - }
803 - // Use a special ID for the free text field, for FCK's needs.
804 - $input_id = $input_name == "free_text" ? "free_text" : "input_$sfgFieldNum";
805 -
806 - if ( array_key_exists( 'rows', $other_args ) ) {
807 - $rows = $other_args['rows'];
808 - } else {
809 - $rows = 5;
810 - }
811 - if ( array_key_exists( 'cols', $other_args ) ) {
812 - $cols = $other_args['cols'];
813 - } else {
814 - $cols = 80;
815 - }
816 -
817 - if ( array_key_exists( 'autogrow', $other_args ) ) {
818 - $className .= ' autoGrow';
819 - }
820 -
821 - $textarea_attrs = array(
822 - 'tabindex' => $sfgTabIndex,
823 - 'id' => $input_id,
824 - 'name' => $input_name,
825 - 'rows' => $rows,
826 - 'cols' => $cols,
827 - 'class' => $className,
828 - );
829 - if ( $is_disabled ) {
830 - $textarea_attrs['disabled'] = 'disabled';
831 - }
832 - if ( array_key_exists( 'maxlength', $other_args ) ) {
833 - $maxlength = $other_args['maxlength'];
834 - // For every actual character pressed (i.e., excluding
835 - // things like the Shift key), reduce the string to its
836 - // allowed length if it's exceeded that.
837 - // This JS code is complicated so that it'll work
838 - // correctly in IE - IE moves the cursor to the end
839 - // whenever this.value is reset, so we'll make sure to
840 - // do that only when we need to.
841 - $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); }";
842 - $textarea_attrs['onKeyDown'] = $maxLengthJSCheck;
843 - $textarea_attrs['onKeyUp'] = $maxLengthJSCheck;
844 - }
845 - $text = Xml::element( 'textarea', $textarea_attrs, $cur_value, false );
846 - $spanClass = "inputSpan";
847 - if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; }
848 - $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
849 - return $text;
850 - }
851 -
852 - public static function getParameters() {
853 - $params = parent::getParameters();
854 - $params[] = array( 'name' => 'preload', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_preload' ) );
855 - $params[] = array( 'name' => 'rows', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_rows' ) );
856 - $params[] = array( 'name' => 'cols', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_cols' ) );
857 - $params[] = array( 'name' => 'maxlength', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_maxlength' ) );
858 - $params[] = array( 'name' => 'autogrow', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_autogrow' ) );
859 - return $params;
860 - }
861 -}
862 -
863939 class SFTextAreaWithAutocompleteInput extends SFTextAreaInput {
864940 public static function getName() {
865941 return 'textarea with autocomplete';
@@ -963,6 +1039,83 @@
9641040 }
9651041 }
9661042
 1043+class SFComboBoxInput extends SFFormInput {
 1044+ public static function getName() {
 1045+ return 'combobox';
 1046+ }
 1047+
 1048+ public static function getOtherPropTypesHandled() {
 1049+ return array( '_wpg', '_str' );
 1050+ }
 1051+
 1052+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 1053+ // For backward compatibility with pre-SF-2.1 forms
 1054+ if ( array_key_exists( 'no autocomplete', $other_args ) &&
 1055+ $other_args['no autocomplete'] == true ) {
 1056+ unset( $other_args['autocompletion source'] );
 1057+ return SFTextInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args );
 1058+ }
 1059+
 1060+ global $sfgTabIndex, $sfgFieldNum;
 1061+
 1062+ $className = "sfComboBox";
 1063+ if ( $is_mandatory ) {
 1064+ $className .= " mandatoryField";
 1065+ }
 1066+ if ( array_key_exists( 'class', $other_args ) ) {
 1067+ $className .= " " . $other_args['class'];
 1068+ }
 1069+ $disabled_text = ( $is_disabled ) ? "disabled" : "";
 1070+
 1071+ if ( array_key_exists( 'size', $other_args ) ) {
 1072+ $size = $other_args['size'];
 1073+ } else {
 1074+ $size = "35";
 1075+ }
 1076+ // There's no direct correspondence between the 'size='
 1077+ // attribute for text inputs and the number of pixels, but
 1078+ // multiplying by 6 seems to be about right for the major
 1079+ // browsers.
 1080+ $pixel_width = $size * 6 . "px";
 1081+
 1082+ list( $autocompleteFieldType, $autocompletionSource ) =
 1083+ SFTextWithAutocompleteInput::getAutocompletionTypeAndSource( $other_args );
 1084+ $values = SFUtils::getAutocompleteValues($autocompletionSource, $autocompleteFieldType );
 1085+ $autocompletionSource = str_replace( "'", "\'", $autocompletionSource );
 1086+
 1087+ $optionsText = Xml::element( 'option', array( 'value' => $cur_value ), null, false ) . "\n";
 1088+ foreach ( $values as $value ) {
 1089+ $optionsText .= Xml::element( 'option', array( 'value' => $value ), $value ) . "\n";
 1090+ }
 1091+
 1092+ $selectAttrs = array(
 1093+ 'id' => "input_$sfgFieldNum",
 1094+ 'name' => $input_name,
 1095+ 'class' => $className,
 1096+ 'tabindex' => $sfgTabIndex,
 1097+ 'autocompletesettings' => $autocompletionSource,
 1098+ 'comboboxwidth' => $pixel_width,
 1099+ );
 1100+ if ( array_key_exists( 'existing values only', $other_args ) ) {
 1101+ $selectAttrs['existingvaluesonly'] = 'true';
 1102+ }
 1103+ $selectText = Xml::tags( 'select', $selectAttrs, $optionsText );
 1104+
 1105+ $divClass = "ui-widget";
 1106+ if ($is_mandatory) { $divClass .= " mandatory"; }
 1107+ $text = Xml::tags( 'div', array( 'class' => $divClass ), $selectText );
 1108+ return $text;
 1109+ }
 1110+
 1111+ public static function getParameters() {
 1112+ $params = parent::getParameters();
 1113+ $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) );
 1114+ $params = array_merge( $params, SFEnumInput::getValuesParameters() );
 1115+ $params[] = array( 'name' => 'existing values only', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_existingvaluesonly' ) );
 1116+ return $params;
 1117+ }
 1118+}
 1119+
9671120 class SFDateInput extends SFFormInput {
9681121 public static function getName() {
9691122 return 'date';
@@ -1198,159 +1351,6 @@
11991352 }
12001353 }
12011354
1202 -class SFRadioButtonInput extends SFEnumInput {
1203 - public static function getName() {
1204 - return 'radiobutton';
1205 - }
1206 -
1207 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
1208 - global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
1209 -
1210 - if ( ( $possible_values = $other_args['possible_values'] ) == null )
1211 - $possible_values = array();
1212 -
1213 - // Add a "None" value at the beginning, unless this is a
1214 - // mandatory field and there's a current value in place (either
1215 - // through a default value or because we're editing an existing
1216 - // page).
1217 - if ( ! $is_mandatory || $cur_value == '' ) {
1218 - array_unshift( $possible_values, '' );
1219 - }
1220 -
1221 - // Set $cur_value to be one of the allowed options, if it isn't
1222 - // already - that makes it easier to automatically have one of
1223 - // the radiobuttons be checked at the beginning.
1224 - if ( ! in_array( $cur_value, $possible_values ) ) {
1225 - if ( in_array( '', $possible_values ) )
1226 - $cur_value = '';
1227 - else
1228 - $cur_value = $possible_values[0];
1229 - }
1230 -
1231 - $text = '';
1232 - foreach ( $possible_values as $i => $possible_value ) {
1233 - $sfgTabIndex++;
1234 - $sfgFieldNum++;
1235 - $input_id = "input_$sfgFieldNum";
1236 -
1237 - $radiobutton_attrs = array(
1238 - 'type' => 'radio',
1239 - 'id' => $input_id,
1240 - 'tabindex' => $sfgTabIndex,
1241 - 'name' => $input_name,
1242 - 'value' => $possible_value,
1243 - );
1244 - if ( $cur_value == $possible_value ) {
1245 - $radiobutton_attrs['checked'] = 'checked';
1246 - }
1247 - if ( $is_disabled ) {
1248 - $radiobutton_attrs['disabled'] = 'disabled';
1249 - }
1250 - if ( $possible_value == '' ) // blank/"None" value
1251 - $label = wfMsg( 'sf_formedit_none' );
1252 - elseif ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) )
1253 - $label = htmlspecialchars( $other_args['value_labels'][$possible_value] );
1254 - else
1255 - $label = $possible_value;
1256 -
1257 - $text .= "\t" . Xml::element ( 'input', $radiobutton_attrs ) . " $label\n";
1258 - }
1259 -
1260 - $spanClass = "radioButtonSpan";
1261 - if ( array_key_exists( 'class', $other_args ) ) {
1262 - $spanClass .= " " . $other_args['class'];
1263 - }
1264 - if ( $is_mandatory ) {
1265 - $spanClass .= " mandatoryFieldSpan";
1266 - }
1267 -
1268 - $spanID = "span_$sfgFieldNum";
1269 -
1270 - // Do the 'show on select' handling.
1271 - if ( array_key_exists( 'show on select', $other_args ) ) {
1272 - $spanClass .= " sfShowIfChecked";
1273 - foreach ( $other_args['show on select'] as $div_id => $options ) {
1274 - if ( array_key_exists( $spanID, $sfgShowOnSelect ) ) {
1275 - $sfgShowOnSelect[$spanID][] = array( $options, $div_id );
1276 - } else {
1277 - $sfgShowOnSelect[$spanID] = array( array( $options, $div_id ) );
1278 - }
1279 - }
1280 - }
1281 - $spanAttrs = array(
1282 - 'id' => $spanID,
1283 - 'class' => $spanClass
1284 - );
1285 - $text = Xml::tags( 'span', $spanAttrs, $text );
1286 -
1287 - return $text;
1288 - }
1289 -}
1290 -
1291 -class SFCheckboxInput extends SFFormInput {
1292 - public static function getName() {
1293 - return 'checkbox';
1294 - }
1295 -
1296 - public static function getDefaultPropTypes() {
1297 - return array( '_boo' => array() );
1298 - }
1299 -
1300 - public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
1301 - global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect;
1302 -
1303 - $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput";
1304 - if ( array_key_exists( 'class', $other_args ) )
1305 - $className .= " " . $other_args['class'];
1306 - $input_id = "input_$sfgFieldNum";
1307 - $disabled_text = ( $is_disabled ) ? "disabled" : "";
1308 - if ( array_key_exists( 'show on select', $other_args ) ) {
1309 - $className .= " sfShowIfCheckedCheckbox";
1310 - $div_id = key( $other_args['show on select'] );
1311 - $sfgShowOnSelect[$input_id] = $div_id;
1312 - }
1313 -
1314 - // Can show up here either as an array or a string, depending on
1315 - // whether it came from user input or a wiki page
1316 - if ( is_array( $cur_value ) ) {
1317 - $checked_str = ( array_key_exists( 'value', $cur_value ) && $cur_value['value'] == 'on' ) ? ' checked="checked"' : "";
1318 - } else {
1319 - // Default to false - no need to check if it matches
1320 - // a 'false' word.
1321 - $vlc = strtolower( trim( $cur_value ) );
1322 - // Manually load SMW's message values, if they weren't
1323 - // loaded before.
1324 - global $wgVersion;
1325 - if ( version_compare( $wgVersion, '1.16', '<' ) ) {
1326 - wfLoadExtensionMessages( 'SemanticMediaWiki' );
1327 - }
1328 - if ( in_array( $vlc, explode( ',', wfMsgForContent( 'smw_true_words' ) ), TRUE ) ) {
1329 - $checked_str = ' checked="checked"';
1330 - } else {
1331 - $checked_str = "";
1332 - }
1333 - }
1334 - $text = <<<END
1335 - <input name="{$input_name}[is_checkbox]" type="hidden" value="true" />
1336 - <input id="$input_id" name="{$input_name}[value]" type="checkbox" class="$className" tabindex="$sfgTabIndex" $checked_str $disabled_text/>
1337 -
1338 -END;
1339 - return $text;
1340 - }
1341 -
1342 - public static function getParameters() {
1343 - // Remove the 'mandatory' option - it doesn't make sense for
1344 - // checkboxes.
1345 - $params = array();
1346 - foreach( parent::getParameters() as $param ) {
1347 - if ( $param['name'] != 'mandatory' ) {
1348 - $params[] = $param;
1349 - }
1350 - }
1351 - return $params;
1352 - }
1353 -}
1354 -
13551355 class SFCategoryInput extends SFFormInput {
13561356 public static function getName() {
13571357 return 'category';