r93038 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93037‎ | r93038 | r93039 >
Date:04:03, 25 July 2011
Author:yaron
Status:deferred
Tags:
Comment:
Turned all class fields into private fields, renamed with "m" prefix for clarity, added some necessary getter and setter methods
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_TemplateField.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_TemplateField.php
@@ -10,19 +10,21 @@
1111 */
1212
1313 class SFTemplateField {
14 - var $field_name;
15 - var $value_labels;
16 - var $label;
17 - var $semantic_property;
18 - var $property_type;
19 - var $possible_values;
20 - var $is_list;
21 - var $input_type;
 14+ private $mFieldName;
 15+ private $mValueLabels;
 16+ private $mLabel;
 17+ private $mSemanticProperty;
 18+ private $mPropertyType;
 19+ private $mPossibleValues;
 20+ private $mIsList;
 21+ private $mInputType;
2222
23 - static function create( $name, $label ) {
 23+ static function create( $name, $label, $semanticProperty = null, $isList = null ) {
2424 $f = new SFTemplateField();
25 - $f->field_name = trim( str_replace( '\\', '', $name ) );
26 - $f->label = trim( str_replace( '\\', '', $label ) );
 25+ $f->mFieldName = trim( str_replace( '\\', '', $name ) );
 26+ $f->mLabel = trim( str_replace( '\\', '', $label ) );
 27+ $f->setSemanticProperty( $semanticProperty );
 28+ $f->mIsList = $isList;
2729 return $f;
2830 }
2931
@@ -38,7 +40,7 @@
3941 // template has a 'strict' setting in the form definition.
4042 $the_field = null;
4143 foreach ( $all_fields as $cur_field ) {
42 - if ( $field_name == $cur_field->field_name ) {
 44+ if ( $field_name == $cur_field->mFieldName ) {
4345 $the_field = $cur_field;
4446 break;
4547 }
@@ -53,7 +55,7 @@
5456 }
5557
5658 function setTypeAndPossibleValues() {
57 - $proptitle = Title::makeTitleSafe( SMW_NS_PROPERTY, $this->semantic_property );
 59+ $proptitle = Title::makeTitleSafe( SMW_NS_PROPERTY, $this->mSemanticProperty );
5860 if ( $proptitle === null ) {
5961 return;
6062 }
@@ -64,29 +66,29 @@
6567 $label_formats = SFUtils::getSMWPropertyValues( $store, $proptitle, "Has field label format" );
6668 if ( class_exists( 'SMWDIProperty' ) ) {
6769 // SMW 1.6+
68 - $propValue = SMWDIProperty::newFromUserLabel( $this->semantic_property );
69 - $this->property_type = $propValue->findPropertyTypeID();
 70+ $propValue = SMWDIProperty::newFromUserLabel( $this->mSemanticProperty );
 71+ $this->mPropertyType = $propValue->findPropertyTypeID();
7072 } else {
71 - $propValue = SMWPropertyValue::makeUserProperty( $this->semantic_property );
72 - $this->property_type = $propValue->getPropertyTypeID();
 73+ $propValue = SMWPropertyValue::makeUserProperty( $this->mSemanticProperty );
 74+ $this->mPropertyType = $propValue->getPropertyTypeID();
7375 }
7476
7577 foreach ( $allowed_values as $allowed_value ) {
7678 // HTML-unencode each value
77 - $this->possible_values[] = html_entity_decode( $allowed_value );
 79+ $this->mPossibleValues[] = html_entity_decode( $allowed_value );
7880 if ( count( $label_formats ) > 0 ) {
7981 $label_format = $label_formats[0];
80 - $prop_instance = SMWDataValueFactory::findTypeID( $this->property_type );
 82+ $prop_instance = SMWDataValueFactory::findTypeID( $this->mPropertyType );
8183 $label_value = SMWDataValueFactory::newTypeIDValue( $prop_instance, $wiki_value );
8284 $label_value->setOutputFormat( $label_format );
83 - $this->value_labels[$wiki_value] = html_entity_decode( $label_value->getWikiValue() );
 85+ $this->mValueLabels[$wiki_value] = html_entity_decode( $label_value->getWikiValue() );
8486 }
8587 }
8688
8789 // HACK - if there were any possible values, set the property
8890 // type to be 'enumeration', regardless of what the actual type is
89 - if ( count( $this->possible_values ) > 0 ) {
90 - $this->property_type = 'enumeration';
 91+ if ( count( $this->mPossibleValues ) > 0 ) {
 92+ $this->mPropertyType = 'enumeration';
9193 }
9294 }
9395
@@ -95,12 +97,52 @@
9698 * a template is parsed during the creation of a form.
9799 */
98100 function setSemanticProperty( $semantic_property ) {
99 - $this->semantic_property = str_replace( '\\', '', $semantic_property );
100 - $this->possible_values = array();
 101+ $this->mSemanticProperty = str_replace( '\\', '', $semantic_property );
 102+ $this->mPossibleValues = array();
101103 // set field type and possible values, if any
102104 $this->setTypeAndPossibleValues();
103105 }
104106
 107+ function getFieldName() {
 108+ return $this->mFieldName;
 109+ }
 110+
 111+ function getValueLabels() {
 112+ return $this->mValueLabels;
 113+ }
 114+
 115+ function getLabel() {
 116+ return $this->mLabel;
 117+ }
 118+
 119+ function getSemanticProperty() {
 120+ return $this->mSemanticProperty;
 121+ }
 122+
 123+ function getPropertyType() {
 124+ return $this->mPropertyType;
 125+ }
 126+
 127+ function getPossibleValues() {
 128+ return $this->mPossibleValues;
 129+ }
 130+
 131+ function getIsList() {
 132+ return $this->mIsList;
 133+ }
 134+
 135+ function getInputType() {
 136+ return $this->mInputType;
 137+ }
 138+
 139+ function setTemplateField( $templateField ) {
 140+ $this->mTemplateField = $templateField;
 141+ }
 142+
 143+ function setLabel( $label ) {
 144+ $this->mLabel = $label;
 145+ }
 146+
105147 /**
106148 * Creates the text of a template, when called from either
107149 * Special:CreateTemplate or Special:CreateClass.
@@ -119,7 +161,7 @@
120162 $text .= '{{' . $template_name;
121163 if ( count( $template_fields ) > 0 ) { $text .= "\n"; }
122164 foreach ( $template_fields as $field ) {
123 - $text .= "|" . $field->field_name . "=\n";
 165+ $text .= "|" . $field->mFieldName . "=\n";
124166 }
125167 $template_footer = wfMsgForContent( 'sf_template_docufooter' );
126168 $text .= <<<END
@@ -156,35 +198,35 @@
157199 if ( $i > 0 ) {
158200 $tableText .= "|-\n";
159201 }
160 - $tableText .= "! " . $field->label . "\n";
161 - if ( $field->semantic_property == null || $field->semantic_property == '' ) {
162 - $tableText .= "| {{{" . $field->field_name . "|}}}\n";
 202+ $tableText .= "! " . $field->mLabel . "\n";
 203+ if ( empty( $field->mSemanticProperty ) ) {
 204+ $tableText .= "| {{{" . $field->mFieldName . "|}}}\n";
163205 // if this field is meant to contain a list,
164206 // add on an 'arraymap' function, that will
165207 // call this semantic markup tag on every
166208 // element in the list
167209 } elseif ( !is_null( $setInternalText ) ) {
168 - if ( $field->is_list ) {
169 - $setInternalText .= '|' . $field->semantic_property . '#list={{{' . $field->field_name . '|}}}';
 210+ if ( $field->mIsList ) {
 211+ $setInternalText .= '|' . $field->mSemanticProperty . '#list={{{' . $field->mFieldName . '|}}}';
170212 } else {
171 - $setInternalText .= '|' . $field->semantic_property . '={{{' . $field->field_name . '|}}}';
 213+ $setInternalText .= '|' . $field->mSemanticProperty . '={{{' . $field->mFieldName . '|}}}';
172214 }
173 - } elseif ( $field->is_list ) {
 215+ } elseif ( $field->mIsList ) {
174216 // find a string that's not in the semantic
175217 // field call, to be used as the variable
176218 $var = "x"; // default - use this if all the attempts fail
177 - if ( strstr( $field->semantic_property, $var ) ) {
 219+ if ( strstr( $field->mSemanticProperty, $var ) ) {
178220 $var_options = array( 'y', 'z', 'xx', 'yy', 'zz', 'aa', 'bb', 'cc' );
179221 foreach ( $var_options as $option ) {
180 - if ( ! strstr( $field->semantic_property, $option ) ) {
 222+ if ( ! strstr( $field->mSemanticProperty, $option ) ) {
181223 $var = $option;
182224 break;
183225 }
184226 }
185227 }
186 - $tableText .= "| {{#arraymap:{{{" . $field->field_name . "|}}}|,|$var|[[" . $field->semantic_property . "::$var]]}}\n";
 228+ $tableText .= "| {{#arraymap:{{{" . $field->mFieldName . "|}}}|,|$var|[[" . $field->mSemanticProperty . "::$var]]}}\n";
187229 } else {
188 - $tableText .= "| [[" . $field->semantic_property . "::{{{" . $field->field_name . "|}}}]]\n";
 230+ $tableText .= "| [[" . $field->mSemanticProperty . "::{{{" . $field->mFieldName . "|}}}]]\n";
189231 }
190232 }
191233