r25172 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25171‎ | r25172 | r25173 >
Date:21:28, 26 August 2007
Author:yaron
Status:old
Tags:
Comment:
Added support for 'datetime' and 'datetime with timezone' input types, and
'default=now' property for all date input types
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc
@@ -5,6 +5,7 @@
66 * @author Yaron Koren
77 * @author Nils Oppermann
88 * @author Jeffrey Stuckman
 9+ * @author Matt Williamson
910 */
1011
1112 class SFFormPrinter {
@@ -373,12 +374,23 @@
374375 $yes = $words_for_true[0];
375376 }
376377 $cur_value_in_template = $yes;
377 - } elseif (count($cur_value) == 3) {
 378+ // if it's 3 or greater, assume it's a date or datetime
 379+ } elseif (count($cur_value) >= 3) {
378380 $month = $cur_value['month'];
379381 $day = $cur_value['day'];
380382 $year = $cur_value['year'];
 383+ if (isset($cur_value['hour'])) $hour = $cur_value['hour'];
 384+ if (isset($cur_value['minute'])) $minute = $cur_value['minute'];
 385+ if (isset($cur_value['second'])) $second = $cur_value['second'];
 386+ if (isset($cur_value['ampm24h'])) $ampm24h = $cur_value['ampm24h'];
 387+ if (isset($cur_value['timezone'])) $timezone = $cur_value['timezone'];
381388 if ($month != '' && $day != '' && $year != '') {
382389 $cur_value_in_template = "$month $day, $year";
 390+ # include whatever time information we have
 391+ if(isset($hour)) $cur_value_in_template .= " " . str_pad(intval(substr($hour,0,2)),2,'0',STR_PAD_LEFT) . ":" . str_pad(intval(substr($minute,0,2)),2,'0',STR_PAD_LEFT);
 392+ if(isset($second)) $cur_value_in_template .= ":" . str_pad(intval(substr($second,0,2)),2,'0',STR_PAD_LEFT);
 393+ if(isset($ampm24h)) $cur_value_in_template .= " $ampm24h";
 394+ if(isset($timezone)) $cur_value_in_template .= " $timezone";
383395 } else {
384396 $cur_value_in_template = "";
385397 }
@@ -427,10 +439,16 @@
428440 if ($is_mandatory) {
429441 $input_id = "input_" . $gTabIndex;
430442 $info_id = "info_" . $gTabIndex;
431 - if ($input_type == 'date') {
 443+ if ($input_type == 'date' || $input_type == 'datetime' || $input_type == 'datetime with timezone') {
432444 $js_validation_calls[] = "validate_mandatory_field ('$input_id" . "_1', '$info_id')";
433445 $js_validation_calls[] = "validate_mandatory_field ('$input_id" . "_2', '$info_id')";
434446 $js_validation_calls[] = "validate_mandatory_field ('$input_id" . "_3', '$info_id')";
 447+ if ($input_type == 'datetime' || $input_type == 'datetime with timezone') {
 448+ // TODO - validate the time fields
 449+ if ($input_type == 'datetime with timezone') {
 450+ // TODO - validate the timezone
 451+ }
 452+ }
435453 } else {
436454 $js_validation_calls[] = "validate_mandatory_field ('$input_id', '$info_id')";
437455 }
@@ -831,6 +849,10 @@
832850 $text = SFFormPrinter::textAreaHTML($num_rows, $num_cols, $template_field->input_name, $cur_value);
833851 } elseif ($template_field->input_type == 'date') {
834852 $text = SFFormPrinter::dateEntryHTML($template_field->input_name, $cur_value);
 853+ } elseif ($template_field->input_type == 'datetime') {
 854+ $text = SFFormPrinter::dateTimeEntryHTML($template_field->input_name, $cur_value, false);
 855+ } elseif ($template_field->input_type == 'datetime with timezone') {
 856+ $text = SFFormPrinter::dateTimeEntryHTML($template_field->input_name, $cur_value, true);
835857 } elseif ($template_field->input_type == 'checkbox') {
836858 $text = SFFormPrinter::checkboxHTML($template_field->input_name, $cur_value);
837859 } elseif ($template_field->input_type == 'radiobutton') {
@@ -1018,7 +1040,11 @@
10191041 $month = $date['month'];
10201042 $day = $date['day'];
10211043 } else {
1022 - $actual_date = strtotime($date);
 1044+ if ($date == 'now') { // special value
 1045+ $actual_date = time();
 1046+ } else {
 1047+ $actual_date = strtotime($date);
 1048+ }
10231049 $year = date("Y", $actual_date);
10241050 $month = date("F", $actual_date);
10251051 $day = date("j", $actual_date);
@@ -1037,6 +1063,63 @@
10381064 return $text;
10391065 }
10401066
 1067+ function dateTimeEntryHTML($input_name, $datetime, $include_timezone) {
 1068+ global $gTabIndex, $gDisabledText;
 1069+
 1070+ if ($datetime) {
 1071+ // can show up here either as an array or a string, depending on
 1072+ // whether it came from user input or a wiki page
 1073+ if (is_array($datetime)) {
 1074+ if (isset($datetime['hour'])) $hour = $cur_value['hour'];
 1075+ if (isset($datetime['minute'])) $minute = $cur_value['minute'];
 1076+ if (isset($datetime['second'])) $second = $cur_value['second'];
 1077+ if (isset($datetime['ampm24h'])) $ampm24h = $cur_value['ampm24h'];
 1078+ if (isset($datetime['timezone'])) $timezone = $cur_value['timezone'];
 1079+ } else {
 1080+ if ($datetime == 'now') { // special value
 1081+ $actual_date = time();
 1082+ } else {
 1083+ $actual_date = strtotime($datetime);
 1084+ }
 1085+ $hour = date("g", $actual_date);
 1086+ $minute = date("i", $actual_date);
 1087+ $second = date("s", $actual_date);
 1088+ $ampm24h = date("A", $actual_date);
 1089+ $timezone = date("T", $actual_date);
 1090+ }
 1091+ } else {
 1092+ $cur_date = getdate();
 1093+ $hour = null;
 1094+ $minute = null;
 1095+ $second = "00"; // default at least this value
 1096+ $timezone = "";
 1097+ }
 1098+
 1099+ $text = SFFormPrinter::dateEntryHTML($input_name, $datetime);
 1100+ $text .= ' &nbsp;<input tabindex="' . $gTabIndex . '" name="' . $input_name . '[hour]" type="text" value="' . $hour . '" size="2"/ ' . $gDisabledText . '>';
 1101+ $gTabIndex++;
 1102+ $text .= ' :<input tabindex="' . $gTabIndex . '" name="' . $input_name . '[minute]" type="text" value="' . $minute . '" size="2"/ ' . $gDisabledText . '>';
 1103+ $gTabIndex++;
 1104+ $text .= ':<input tabindex="' . $gTabIndex . '" name="' . $input_name . '[second]" type="text" value="' . $second . '" size="2"/ ' . $gDisabledText . '>' . "\n";
 1105+
 1106+ $gTabIndex++;
 1107+ $text .= ' <select tabindex="' . $gTabIndex . '" name="' . $input_name . "[ampm24h]\" $gDisabledText>\n";
 1108+ $ampm24h_options = array('', 'AM', 'PM');
 1109+ foreach ($ampm24h_options as $value) {
 1110+ $text .= " <option value=\"$value\"";
 1111+ if ($value == $ampm24h) {$text .= " selected=\"selected\""; }
 1112+ $text .= ">$value</option>\n";
 1113+ }
 1114+ $text .= " </select>\n";
 1115+
 1116+ if ($include_timezone) {
 1117+ $gTabIndex++;
 1118+ $text .= ' <input tabindex="' . $gTabIndex . '" name="' . $input_name . '[timezone]" type="text" value="' . $timezone . '" size="2"/ ' . $gDisabledText . '>' . "\n";
 1119+ }
 1120+
 1121+ return $text;
 1122+ }
 1123+
10411124 function radioButtonHTML($input_name, $cur_value, $include_none, $options_array) {
10421125 global $gTabIndex, $gDisabledText;
10431126

Status & tagging log