r46856 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46855‎ | r46856 | r46857 >
Date:17:16, 5 February 2009
Author:yaron
Status:deferred
Tags:
Comment:
Moved more template-field functionality into this class
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_TemplateField.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_TemplateField.inc
@@ -10,22 +10,46 @@
1111 class SFTemplateField {
1212 var $field_name;
1313 var $label;
14 - var $semantic_field;
1514 var $semantic_property;
16 - var $is_relation;
1715 var $field_type;
1816 var $possible_values;
1917 var $is_list;
2018
21 - static function newWithValues($name, $label) {
 19+ static function create($name, $label) {
2220 $f = new SFTemplateField();
2321 $f->field_name = trim(str_replace('\\', '', $name));
2422 $f->label = trim(str_replace('\\', '', $label));
2523 return $f;
2624 }
2725
 26+ /**
 27+ * Create an SFTemplateField object based on the corresponding field
 28+ * in the template definition (which we first have to find)
 29+ */
 30+ static function createFromList($field_name, $all_fields, $strict_parsing) {
 31+ // see if this field matches one of the fields defined for
 32+ // the template it's part of - if it is, use all available
 33+ // information about that field; if it's not, either create
 34+ // an object for it or not, depending on whether the
 35+ // template has a 'strict' setting in the form definition
 36+ $the_field = null;
 37+ foreach ($all_fields as $cur_field) {
 38+ if ($field_name == $cur_field->field_name) {
 39+ $the_field = $cur_field;
 40+ break;
 41+ }
 42+ }
 43+ if ($the_field == null) {
 44+ if ($strict_parsing) {
 45+ return null;
 46+ }
 47+ $the_field = new SFTemplateField();
 48+ }
 49+ return $the_field;
 50+ }
 51+
2852 function setTypeAndPossibleValues() {
29 - $proptitle = Title::newFromText($this->semantic_field, SMW_NS_PROPERTY);
 53+ $proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->semantic_property);
3054 if ($proptitle === NULL)
3155 return;
3256 $store = smwfGetStore();
@@ -44,7 +68,7 @@
4569
4670 foreach ($allowed_values as $value) {
4771 // HTML-unencode each value
48 - $this->possible_values[] = html_entity_decode($value->getXSDValue());
 72+ $this->possible_values[] = html_entity_decode($value->getWikiValue());
4973 }
5074 // HACK - if there were any possible values, set the field
5175 // type to be 'enumeration', regardless of what the actual type is
@@ -53,30 +77,45 @@
5478 }
5579 }
5680
57 - // setSemanticData() - called when template is parsed during the creation
58 - // of a form
59 - function setSemanticData($semantic_field, $is_relation, $is_list) {
60 - $this->semantic_field = str_replace('\\', '', $semantic_field);
61 - $this->is_relation = $is_relation;
 81+ /**
 82+ * Called when template is parsed during the creation of a form
 83+ */
 84+ function setSemanticProperty($semantic_property) {
 85+ $this->semantic_property = str_replace('\\', '', $semantic_property);
6286 $this->possible_values = array();
63 - $this->is_list = $is_list;
6487 // set field type and possible values, if any
6588 $this->setTypeAndPossibleValues();
6689 }
6790
 91+ /**
 92+ * Returns whether the semantic property represented by this field
 93+ * has the passed-in type constant (e.g., '_str', '_wpg')
 94+ */
 95+ function propertyIsOfType($type_constant) {
 96+ global $smwgContLang;
 97+ $datatypeLabels = $smwgContLang->getDatatypeLabels();
 98+ $page_type = $datatypeLabels[$type_constant];
 99+ return ($this->field_type == $page_type);
 100+ }
 101+
68102 function createTemplateText($template_name, $template_fields, $category, $aggregating_property, $aggregating_label, $template_format) {
69 - $text = "<noinclude>\n";
70 - $text .= wfMsgForContent('sf_template_docu', $template_name) . "\n";
71 - $text .= "<pre>\n";
72 - $text .= "{{" . $template_name;
 103+ $template_header = wfMsgForContent('sf_template_docu', $template_name);
 104+ $text =<<<END
 105+<noinclude>
 106+$template_header
 107+<pre>
 108+
 109+END;
 110+ $text .= '{{' . $template_name;
73111 if (count($template_fields) > 0) { $text .= "\n"; }
74112 foreach ($template_fields as $field) {
75113 $text .= "|" . $field->field_name . "=\n";
76114 }
77 - $text .= "}}\n";
78 - $text .= "</pre>\n";
79 - $text .= wfMsgForContent('sf_template_docufooter') . "\n";
 115+ $template_footer = wfMsgForContent('sf_template_docufooter');
80116 $text .=<<<END
 117+}}
 118+</pre>
 119+$template_footer
81120 </noinclude><includeonly>
82121
83122 END;

Status & tagging log