r44409 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44408‎ | r44409 | r44410 >
Date:16:31, 10 December 2008
Author:yaron
Status:deferred
Tags:
Comment:
Patrick Nagel's fixes for handling non-American date format and 24-hour time format
in form inputs
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormInputs.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.inc
@@ -5,6 +5,7 @@
66 * @author Yaron Koren
77 * @author Jeffrey Stuckman
88 * @author Matt Williamson
 9+ * @author Patrick Nagel
910 */
1011
1112 class SFFormInputs {
@@ -465,7 +466,7 @@
466467 }
467468
468469 function dateEntryHTML($date, $input_name, $is_mandatory, $is_disabled, $other_args) {
469 - global $sfgTabIndex, $sfgFieldNum, $sfgJSValidationCalls;
 470+ global $sfgTabIndex, $sfgFieldNum, $sfgJSValidationCalls, $wgAmericanDates;
470471
471472 $input_id = "input_$sfgFieldNum";
472473 $info_id = "info_$sfgFieldNum";
@@ -495,16 +496,22 @@
496497 $month = $cur_date['month'];
497498 $day = null; // no need for day
498499 }
 500+ $text = "";
499501 $disabled_text = ($is_disabled) ? "disabled" : "";
500 - $text = SFFormInputs::monthDropdownHTML($month, $input_name, $is_disabled);
501 - $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_day" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>' . "\n";
 502+ if ($wgAmericanDates) {
 503+ $text .= SFFormInputs::monthDropdownHTML($month, $input_name, $is_disabled);
 504+ $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_day" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>' . "\n";
 505+ } else {
 506+ $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_day" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>' . "\n";
 507+ $text .= SFFormInputs::monthDropdownHTML($month, $input_name, $is_disabled);
 508+ }
502509 $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_year" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4" ' . $disabled_text . '/>' . "\n";
503510 $text .= " <span id=\"$info_id\" class=\"errorMessage\"></span>";
504511 return array($text, null);
505512 }
506513
507514 function dateTimeEntryHTML($datetime, $input_name, $is_mandatory, $is_disabled, $other_args) {
508 - global $sfgTabIndex;
 515+ global $sfgTabIndex, $sfg24HourTime;
509516
510517 $include_timezone = $other_args['include_timezone'];
511518
@@ -515,14 +522,22 @@
516523 if (isset($datetime['hour'])) $hour = $cur_value['hour'];
517524 if (isset($datetime['minute'])) $minute = $cur_value['minute'];
518525 if (isset($datetime['second'])) $second = $cur_value['second'];
519 - if (isset($datetime['ampm24h'])) $ampm24h = $cur_value['ampm24h'];
 526+ if (! $sfg24HourTime) {
 527+ if (isset($datetime['ampm24h'])) $ampm24h = $cur_value['ampm24h'];
 528+ }
520529 if (isset($datetime['timezone'])) $timezone = $cur_value['timezone'];
521530 } else {
522531 $actual_date = strtotime($datetime);
523 - $hour = date("g", $actual_date);
 532+ if ($sfg24HourTime) {
 533+ $hour = date("G", $actual_date);
 534+ } else {
 535+ $hour = date("g", $actual_date);
 536+ }
524537 $minute = date("i", $actual_date);
525538 $second = date("s", $actual_date);
526 - $ampm24h = date("A", $actual_date);
 539+ if (! $sfg24HourTime) {
 540+ $ampm24h = date("A", $actual_date);
 541+ }
527542 $timezone = date("T", $actual_date);
528543 }
529544 } else {
@@ -541,15 +556,17 @@
542557 $sfgTabIndex++;
543558 $text .= ':<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[second]" type="text" value="' . $second . '" size="2"/ ' . $disabled_text . '>' . "\n";
544559
545 - $sfgTabIndex++;
546 - $text .= ' <select tabindex="' . $sfgTabIndex . '" name="' . $input_name . "[ampm24h]\" $disabled_text>\n";
547 - $ampm24h_options = array('', 'AM', 'PM');
548 - foreach ($ampm24h_options as $value) {
549 - $text .= " <option value=\"$value\"";
550 - if ($value == $ampm24h) {$text .= " selected=\"selected\""; }
551 - $text .= ">$value</option>\n";
 560+ if (! $sfg24HourTime) {
 561+ $sfgTabIndex++;
 562+ $text .= ' <select tabindex="' . $sfgTabIndex . '" name="' . $input_name . "[ampm24h]\" $disabled_text>\n";
 563+ $ampm24h_options = array('', 'AM', 'PM');
 564+ foreach ($ampm24h_options as $value) {
 565+ $text .= " <option value=\"$value\"";
 566+ if ($value == $ampm24h) {$text .= " selected=\"selected\""; }
 567+ $text .= ">$value</option>\n";
 568+ }
 569+ $text .= " </select>\n";
552570 }
553 - $text .= " </select>\n";
554571
555572 if ($include_timezone) {
556573 $sfgTabIndex++;

Status & tagging log