r53691 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53690‎ | r53691 | r53692 >
Date:18:05, 23 July 2009
Author:yaron
Status:deferred
Tags:
Comment:
'float' changed to 'number'; fix to always reset time values for date fields; "free text" placeholder changed to work with new HTML-escaping of textarea values
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc
@@ -34,7 +34,7 @@
3535 $code_type = 'code';
3636 $url_type = $datatypeLabels['_uri'];
3737 $email_type = $datatypeLabels['_ema'];
38 - $float_type = $datatypeLabels['_num'];
 38+ $number_type = $datatypeLabels['_num'];
3939 $bool_type = $datatypeLabels['_boo'];
4040 $date_type = $datatypeLabels['_dat'];
4141 $enum_type = 'enumeration'; // not a real type
@@ -45,7 +45,7 @@
4646 $this->setSemanticTypeHook($code_type, false, array('SFFormInputs', 'textAreaHTML'), array());
4747 $this->setSemanticTypeHook($url_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'URL'));
4848 $this->setSemanticTypeHook($email_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'email'));
49 - $this->setSemanticTypeHook($float_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'float'));
 49+ $this->setSemanticTypeHook($number_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'number'));
5050 $this->setSemanticTypeHook($bool_type, false, array('SFFormInputs', 'checkboxHTML'), array());
5151 $this->setSemanticTypeHook($date_type, false, array('SFFormInputs', 'dateEntryHTML'), array());
5252 $this->setSemanticTypeHook($enum_type, false, array('SFFormInputs', 'dropdownHTML'), array());
@@ -611,7 +611,7 @@
612612 // the page, using <free_text> tags - once all the free text
613613 // is known (at the end), it will get substituted in
614614 if ($is_hidden) {
615 - $new_text = SFFormUtils::hiddenFieldHTML('free_text', '<free_text>');
 615+ $new_text = SFFormUtils::hiddenFieldHTML('free_text', '!free_text!');
616616 } else {
617617 if (! array_key_exists('rows', $field_args))
618618 $field_args['rows'] = 5;
@@ -619,7 +619,7 @@
620620 $field_args['cols'] = 80;
621621 $sfgTabIndex++;
622622 $sfgFieldNum++;
623 - list($new_text, $new_javascript_text) = SFFormInputs::textAreaHTML('<free_text>', 'free_text', false, ($form_is_disabled || $is_restricted), $field_args);
 623+ list($new_text, $new_javascript_text) = SFFormInputs::textAreaHTML('!free_text!', 'free_text', false, ($form_is_disabled || $is_restricted), $field_args);
624624 if (in_array('edittools', $free_text_components)) {
625625 // borrowed from EditPage::showEditTools()
626626 $options[] = 'parse';
@@ -636,7 +636,7 @@
637637 }
638638 $free_text_was_included = true;
639639 // add a similar placeholder to the data text
640 - $data_text .= "<free_text>\n";
 640+ $data_text .= "!free_text!\n";
641641 }
642642
643643 if ($template_name == '' || $field_name == '<freetext>') {
@@ -709,6 +709,7 @@
710710 }
711711 }
712712 $year = $cur_value['year'];
 713+ $hour = $minute = $second = $ampm24h = $timezone = null;
713714 if (isset($cur_value['hour'])) $hour = $cur_value['hour'];
714715 if (isset($cur_value['minute'])) $minute = $cur_value['minute'];
715716 if (isset($cur_value['second'])) $second = $cur_value['second'];
@@ -724,10 +725,14 @@
725726 $cur_value_in_template = "$year/$month/$day";
726727 }
727728 // include whatever time information we have
728 - 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);
729 - if(isset($second)) $cur_value_in_template .= ":" . str_pad(intval(substr($second,0,2)),2,'0',STR_PAD_LEFT);
730 - if(isset($ampm24h)) $cur_value_in_template .= " $ampm24h";
731 - if(isset($timezone)) $cur_value_in_template .= " $timezone";
 729+ if (! is_null($hour))
 730+ $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);
 731+ if (! is_null($second))
 732+ $cur_value_in_template .= ":" . str_pad(intval(substr($second,0,2)),2,'0',STR_PAD_LEFT);
 733+ if (! is_null($ampm24h))
 734+ $cur_value_in_template .= " $ampm24h";
 735+ if (! is_null($timezone))
 736+ $cur_value_in_template .= " $timezone";
732737 } else {
733738 $cur_value_in_template = "";
734739 }
@@ -849,7 +854,7 @@
850855 // disabled inputs for some reason don't submit their value
851856 if ($is_restricted && ! $wgUser->isAllowed('editrestrictedfields')) {
852857 if ($field_name == 'free text' || $field_name == '<freetext>') {
853 - $new_text .= SFFormUtils::hiddenFieldHTML('free_text', '<free_text>');
 858+ $new_text .= SFFormUtils::hiddenFieldHTML('free_text', '!free_text!');
854859 } else {
855860 $new_text .= SFFormUtils::hiddenFieldHTML($input_name, $cur_value);
856861 }
@@ -1074,7 +1079,7 @@
10751080 // if it wasn't included in the form definition, add the
10761081 // 'free text' input as a hidden field at the bottom
10771082 if (! $free_text_was_included) {
1078 - $form_text .= SFFormUtils::hiddenFieldHTML('free_text', '<free_text>');
 1083+ $form_text .= SFFormUtils::hiddenFieldHTML('free_text', '!free_text!');
10791084 }
10801085 // get free text, and add to page data, as well as retroactively
10811086 // inserting it into the form
@@ -1100,7 +1105,7 @@
11011106 } elseif ($wgRequest->getCheck('free_text')) {
11021107 $free_text = $wgRequest->getVal('free_text');
11031108 if (! $free_text_was_included) {
1104 - $data_text .= "<free_text>";
 1109+ $data_text .= "!free_text!";
11051110 }
11061111 // or get it from the form definition
11071112 } elseif ($free_text_preload_page != null) {
@@ -1113,7 +1118,7 @@
11141119 $free_text = str_replace("<onlyinclude>",'', $free_text);
11151120 $free_text = str_replace("</onlyinclude>",'', $free_text);
11161121 $free_text = trim($free_text);
1117 - $data_text = str_replace('<free_text>','<onlyinclude><free_text></onlyinclude>', $data_text);
 1122+ $data_text = str_replace('!free_text!','<onlyinclude>!free_text!</onlyinclude>', $data_text);
11181123 }
11191124 // if the FCKeditor extension is installed, use that for the free text input
11201125 global $wgFCKEditorDir;
@@ -1128,8 +1133,8 @@
11291134 $free_text = Sanitizer::safeEncodeAttribute($free_text);
11301135 }
11311136 // now that we have it, substitute free text into the form and page
1132 - $form_text = str_replace('<free_text>', $free_text, $form_text);
1133 - $data_text = str_replace('<free_text>', $free_text, $data_text);
 1137+ $form_text = str_replace('!free_text!', $free_text, $form_text);
 1138+ $data_text = str_replace('!free_text!', $free_text, $data_text);
11341139
11351140 // add a warning in, if we're editing an existing page and that page
11361141 // appears to not have been created with this form

Status & tagging log