r93041 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93040‎ | r93041 | r93042 >
Date:04:20, 25 July 2011
Author:yaron
Status:deferred
Tags:
Comment:
Replaced 'var' initialization of class fields with a mix of 'private' and 'public' (these eventually should all be private); added some necessary getter and setter methods; updated handling of SFTemplateField objects
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormField.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormField.php
@@ -13,28 +13,25 @@
1414 * @ingroup SF
1515 */
1616 class SFFormField {
17 - var $num;
18 - var $template_field;
19 - var $input_type;
20 - var $is_mandatory;
21 - var $is_hidden;
22 - var $is_restricted;
23 - var $possible_values;
 17+ private $num;
 18+ public $template_field;
 19+ private $input_type;
 20+ public $is_mandatory;
 21+ public $is_hidden;
 22+ private $is_restricted;
 23+ private $possible_values;
 24+ public $is_list;
2425 // the following fields are not set by the form-creation page
2526 // (though they could be)
26 - var $is_uploadable;
27 - var $field_args;
28 - var $autocomplete_source;
29 - var $autocomplete_field_type;
30 - var $no_autocomplete;
31 - var $part_of_multiple;
 27+ private $is_uploadable;
 28+ private $field_args;
3229 // somewhat of a hack - these two fields are for a field in a specific
3330 // representation of a form, not the form definition; ideally these
3431 // should be contained in a third 'field' class, called something like
3532 // SFFormInstanceField, that holds these fields plus an instance of
3633 // SFFormField. Too much work?
37 - var $input_name;
38 - var $is_disabled;
 34+ public $input_name;
 35+ public $is_disabled;
3936
4037 static function create( $num, $template_field ) {
4138 $f = new SFFormField();
@@ -58,7 +55,7 @@
5956 // setting in the form definition
6057 $the_field = null;
6158 foreach ( $all_fields as $cur_field ) {
62 - if ( $field_name == $cur_field->field_name ) {
 59+ if ( $field_name == $cur_field->getFieldName() ) {
6360 $the_field = $cur_field;
6461 break;
6562 }
@@ -89,6 +86,22 @@
9087 return $f;
9188 }
9289
 90+ public function getTemplateField() {
 91+ return $this->template_field;
 92+ }
 93+
 94+ public function getInputType() {
 95+ return $this->input_type;
 96+ }
 97+
 98+ public function setTemplateField( $templateField ) {
 99+ $this->template_field = $templateField;
 100+ }
 101+
 102+ public function setSemanticProperty( $semanticProperty ) {
 103+ $this->template_field->setSemanticProperty( $semanticProperty );
 104+ }
 105+
93106 function inputTypeDropdownHTML( $field_form_text, $default_input_type, $possible_input_types, $cur_input_type ) {
94107 if ( !is_null( $default_input_type ) ) {
95108 array_unshift( $possible_input_types, $default_input_type );
@@ -119,15 +132,15 @@
120133 function creationHTML( $template_num ) {
121134 $field_form_text = $template_num . "_" . $this->num;
122135 $template_field = $this->template_field;
123 - $text = '<h3>' . wfMsg( 'sf_createform_field' ) . " '" . $template_field->field_name . "'</h3>\n";
124 - $prop_link_text = SFUtils::linkText( SMW_NS_PROPERTY, $template_field->semantic_property );
 136+ $text = '<h3>' . wfMsg( 'sf_createform_field' ) . " '" . $template_field->getFieldName() . "'</h3>\n";
 137+ $prop_link_text = SFUtils::linkText( SMW_NS_PROPERTY, $template_field->getSemanticProperty() );
125138 // TODO - remove this probably-unnecessary check?
126 - if ( $template_field->semantic_property == "" ) {
 139+ if ( $template_field->getSemanticProperty() == "" ) {
127140 // Print nothing if there's no semantic property.
128 - } elseif ( $template_field->property_type == "" ) {
 141+ } elseif ( $template_field->getPropertyType() == "" ) {
129142 $text .= '<p>' . wfMsg( 'sf_createform_fieldpropunknowntype', $prop_link_text ) . "</p>\n";
130143 } else {
131 - if ( $template_field->is_list ) {
 144+ if ( $template_field->getIsList() ) {
132145 $propDisplayMsg = 'sf_createform_fieldproplist';
133146 } else {
134147 $propDisplayMsg = 'sf_createform_fieldprop';
@@ -139,13 +152,13 @@
140153 if ( $smwgContLang != null ) {
141154 $datatypeLabels = $smwgContLang->getDatatypeLabels();
142155 $datatypeLabels['enumeration'] = 'enumeration';
143 - $propertyType = $datatypeLabels[$template_field->property_type];
 156+ $propertyTypeLabel = $datatypeLabels[$template_field->getPropertyType()];
144157 if ( class_exists( 'SMWDIProperty' ) ) {
145158 // "Type:" namespace was removed in SMW 1.6.
146159 // TODO: link to Special:Types instead?
147 - $propertyTypeStr = $propertyType;
 160+ $propertyTypeStr = $propertyTypeLabel;
148161 } else {
149 - $propertyTypeStr = SFUtils::linkText( SMW_NS_TYPE, $propertyType );
 162+ $propertyTypeStr = SFUtils::linkText( SMW_NS_TYPE, $propertyTypeLabel );
150163 }
151164 }
152165 $text .= Xml::tags( 'p', null, wfMsg( $propDisplayMsg, $prop_link_text, $propertyTypeStr ) ) . "\n";
@@ -157,7 +170,7 @@
158171 'type' => 'text',
159172 'name' => 'label_' . $field_form_text,
160173 'size' => 20,
161 - 'value' => $template_field->label,
 174+ 'value' => $template_field->getLabel(),
162175 ), null );
163176 $input_type_text = wfMsg( 'sf_createform_inputtype' );
164177 $text .= <<<END
@@ -167,17 +180,17 @@
168181
169182 END;
170183 global $sfgFormPrinter;
171 - if ( is_null( $template_field->property_type ) ) {
 184+ if ( is_null( $template_field->getPropertyType() ) ) {
172185 $default_input_type = null;
173186 $possible_input_types = $sfgFormPrinter->getAllInputTypes();
174187 } else {
175 - $default_input_type = $sfgFormPrinter->getDefaultInputType( $template_field->is_list, $template_field->property_type );
176 - $possible_input_types = $sfgFormPrinter->getPossibleInputTypes( $template_field->is_list, $template_field->property_type );
 188+ $default_input_type = $sfgFormPrinter->getDefaultInputType( $template_field->getIsList(), $template_field->getPropertyType() );
 189+ $possible_input_types = $sfgFormPrinter->getPossibleInputTypes( $template_field->getIsList(), $template_field->getPropertyType() );
177190 }
178 - $text .= $this->inputTypeDropdownHTML( $field_form_text, $default_input_type, $possible_input_types, $template_field->input_type );
 191+ $text .= $this->inputTypeDropdownHTML( $field_form_text, $default_input_type, $possible_input_types, $template_field->getInputType() );
179192
180 - if (! is_null( $template_field->input_type ) ) {
181 - $cur_input_type = $template_field->input_type;
 193+ if (! is_null( $template_field->getInputType() ) ) {
 194+ $cur_input_type = $template_field->getInputType();
182195 } elseif (! is_null( $default_input_type ) ) {
183196 $cur_input_type = $default_input_type;
184197 } else {
@@ -214,20 +227,19 @@
215228 // such templates in form definitions gets more sophisticated
216229 function createMarkup( $part_of_multiple, $is_last_field_in_template ) {
217230 $text = "";
218 - if ( $this->template_field->label != "" ) {
 231+ if ( $this->template_field->getLabel() != '' ) {
219232 if ( $part_of_multiple ) {
220 - $text .= "'''" . $this->template_field->label . ":''' ";
 233+ $text .= "'''" . $this->template_field->getLabel() . ":''' ";
221234 } else {
222 - $text .= "! " . $this->template_field->label . ":\n";
 235+ $text .= "! " . $this->template_field->getLabel() . ":\n";
223236 }
224237 }
225238 if ( ! $part_of_multiple ) { $text .= "| "; }
226 - $text .= "{{{field|" . $this->template_field->field_name;
 239+ $text .= "{{{field|" . $this->template_field->getFieldName();
227240 if ( $this->is_hidden ) {
228241 $text .= "|hidden";
229 - } elseif ( isset( $this->template_field->input_type ) &&
230 - $this->template_field->input_type != null ) {
231 - $text .= "|input type=" . $this->template_field->input_type;
 242+ } elseif ( $this->template_field->getInputType() != '' ) {
 243+ $text .= "|input type=" . $this->template_field->getInputType();
232244 }
233245 foreach ( $this->field_args as $arg => $value ) {
234246 if ( $value === true ) {
@@ -264,25 +276,25 @@
265277 if ( $this->possible_values != null )
266278 $other_args['possible_values'] = $this->possible_values;
267279 else {
268 - $other_args['possible_values'] = $this->template_field->possible_values;
269 - $other_args['value_labels'] = $this->template_field->value_labels;
 280+ $other_args['possible_values'] = $this->template_field->getPossibleValues();
 281+ $other_args['value_labels'] = $this->template_field->getValueLabels();
270282 }
271 - $other_args['is_list'] = ( $this->is_list || $this->template_field->is_list );
272 - if ( $this->template_field->semantic_property != '' &&
 283+ $other_args['is_list'] = ( $this->is_list || $this->template_field->getIsList() );
 284+ if ( $this->template_field->getSemanticProperty() != '' &&
273285 ! array_key_exists( 'semantic_property', $other_args ) ) {
274 - $other_args['semantic_property'] = $this->template_field->semantic_property;
275 - $other_args['property_type'] = $this->template_field->property_type;
 286+ $other_args['semantic_property'] = $this->template_field->getSemanticProperty();
 287+ $other_args['property_type'] = $this->template_field->getPropertyType();
276288 }
277289 // If autocompletion hasn't already been hardcoded in the form,
278290 // and it's a property of type page, or a property of another
279291 // type with 'autocomplete' specified, set the necessary
280292 // parameters.
281293 if ( ! array_key_exists( 'autocompletion source', $other_args ) ) {
282 - if ( $this->template_field->property_type == '_wpg' ) {
283 - $other_args['autocompletion source'] = $this->template_field->semantic_property;
 294+ if ( $this->template_field->getPropertyType() == '_wpg' ) {
 295+ $other_args['autocompletion source'] = $this->template_field->getSemanticProperty();
284296 $other_args['autocomplete field type'] = 'relation';
285297 } elseif ( array_key_exists( 'autocomplete', $other_args ) || array_key_exists( 'remote autocompletion', $other_args ) ) {
286 - $other_args['autocompletion source'] = $this->template_field->semantic_property;
 298+ $other_args['autocompletion source'] = $this->template_field->getSemanticProperty();
287299 $other_args['autocomplete field type'] = 'attribute';
288300 }
289301 }