r23724 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23723‎ | r23724 | r23725 >
Date:02:30, 5 July 2007
Author:yaron
Status:old
Tags:
Comment:
New version, 0.3.6 - better formatting of code, new 'hidden' property in form
definition files, slight fix for multiple-template-instance-removal bug.
Modified paths:
  • /trunk/extensions/SemanticForms/INSTALL (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormClasses.inc (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_TemplateField.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/INSTALL
@@ -1,4 +1,4 @@
2 -[[Semantic Forms 0.3.5]]
 2+[[Semantic Forms 0.3.6]]
33
44 Contents:
55 * Disclaimer
Index: trunk/extensions/SemanticForms/includes/SF_TemplateField.inc
@@ -37,24 +37,23 @@
3838 'value_string',
3939 $conditions, $fname);
4040 if ($db->numRows( $res ) > 0) {
41 - if ($row = $db->fetchObject($res)) {
42 - $f->attribute_type = $row->value_string;
43 - // set possible values if it's an enumeration
44 - if ($f->attribute_type == $smwgContLang->smwDatatypeLabels['smw_enum']) {
45 - $conditions = "subject_namespace = " . SMW_NS_ATTRIBUTE .
46 - " AND subject_title = '$semantic_field_db_str' AND property_id = " .
47 - SMW_SP_POSSIBLE_VALUE;
48 - $res2 = $db->select( $db->tableName('smw_specialprops'),
49 - 'value_string',
50 - $conditions, $fname);
51 - if ($db->numRows( $res2 ) > 0) {
52 - while ($row = $db->fetchObject($res2)) {
53 - $f->possible_values[] = $row->value_string;
54 - }
55 - }
56 - $db->freeResult($res2);
57 - }
58 - }
 41+ if ($row = $db->fetchObject($res)) {
 42+ $f->attribute_type = $row->value_string;
 43+ // set possible values if it's an enumeration
 44+ if ($f->attribute_type == $smwgContLang->smwDatatypeLabels['smw_enum']) {
 45+ $conditions = "subject_namespace = " . SMW_NS_ATTRIBUTE .
 46+ " AND subject_title = '$semantic_field_db_str' AND property_id = " .
 47+ SMW_SP_POSSIBLE_VALUE;
 48+ $res2 = $db->select( $db->tableName('smw_specialprops'),
 49+ 'value_string', $conditions, $fname);
 50+ if ($db->numRows( $res2 ) > 0) {
 51+ while ($row = $db->fetchObject($res2)) {
 52+ $f->possible_values[] = $row->value_string;
 53+ }
 54+ }
 55+ $db->freeResult($res2);
 56+ }
 57+ }
5958 }
6059 $db->freeResult($res);
6160 }
Index: trunk/extensions/SemanticForms/includes/SF_FormClasses.inc
@@ -175,7 +175,8 @@
176176 if ($template_field->attribute_type == "")
177177 $text .= '<p>' . wfMsg('sf_createform_fieldattrunknowntype', $attr_link_text, sffLinkText(SMW_NS_TYPE, 'String')) . "</p>\n";
178178 else
179 - $text .= '<p>' . wfMsg('sf_createform_fieldattr', $attr_link_text, sffLinkText(SMW_NS_TYPE, $template_field->attribute_type)) . "</p>\n";
 179+ $text .= '<p>' . wfMsg('sf_createform_fieldattr', $attr_link_text,
 180+ sffLinkText(SMW_NS_TYPE, $template_field->attribute_type)) . "</p>\n";
180181
181182 } elseif ($template_field->attr_or_rel == "relation") {
182183 $rel_link_text = sffLinkText(SMW_NS_RELATION, $template_field->semantic_field);
@@ -200,19 +201,17 @@
201202 }
202203
203204 function createMarkup() {
204 - if (! $this->is_hidden) {
205 - $text = " <p>";
206 - if ($this->template_field->label != "")
207 - $text .= "<strong>" . $this->template_field->label . ":</strong> ";
208 - $text .= "{{{field|" . $this->template_field->field_name;
209 - if ($this->is_mandatory) {
210 - $text .= "|mandatory";
211 - }
212 - $text .= "}}}</p>\n";
213 - return $text;
214 - } else {
215 - return "";
 205+ $text = " <p>";
 206+ if ($this->template_field->label != "")
 207+ $text .= "<strong>" . $this->template_field->label . ":</strong> ";
 208+ $text .= "{{{field|" . $this->template_field->field_name;
 209+ if ($this->is_mandatory) {
 210+ $text .= "|mandatory";
 211+ } elseif ($this->is_hidden) {
 212+ $text .= "|hidden";
216213 }
 214+ $text .= "}}}</p>\n";
 215+ return $text;
217216 }
218217 }
219218
Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc
@@ -64,9 +64,9 @@
6565 $passed_validation = true;
6666 $data_text = "";
6767 $template_name = "";
 68+ $instance_was_deleted = false;
6869 $allow_multiple = false;
6970 $strict_parsing = false;
70 - $instance_was_deleted = false;
7171 for ($section_num = 0; $section_num < count($form_def_sections); $section_num++) {
7272 $tif = new SFTemplateInForm();
7373 $start_position = 0;
@@ -212,6 +212,7 @@
213213 $field_name = trim($tag_components[1]);
214214 // cycle through the other components
215215 $is_mandatory = false;
 216+ $is_hidden = false;
216217 $input_type = null;
217218 $no_autocomplete = false;
218219 $autocomplete_category = null;
@@ -224,6 +225,8 @@
225226 $component = trim($tag_components[$i]);
226227 if ($component == 'mandatory') {
227228 $is_mandatory = true;
 229+ } elseif ($component == 'hidden') {
 230+ $is_hidden = true;
228231 } else {
229232 $sub_components = explode('=', $component);
230233 if (count($sub_components) == 2) {
@@ -278,9 +281,8 @@
279282 }
280283 // the template display name might be different from what's in
281284 // the query string, if a previous instance was deleted
282 - if ($instance_was_deleted) {
283 - $instance_num--;
284 - $template_display_name = $query_template_name . '_' . $instance_num;
 285+ if ($allow_multiple && $instance_was_deleted) {
 286+ $template_display_name = $query_template_name . '_' . ($instance_num - 1);
285287 } else {
286288 $template_display_name = $full_template_name;
287289 }
@@ -352,7 +354,9 @@
353355 } else { // value is not an array
354356 $cur_value_in_template = $cur_value;
355357 }
356 - $new_text = SFFormPrinter::formTemplateFieldHTML($template_display_name, $field_name, $instance_num, $cur_value, $is_mandatory, $input_type, $size, $num_rows, $num_cols, $no_autocomplete, $autocomplete_category, $error_str, $all_fields, $strict_parsing);
 358+ $new_text = SFFormPrinter::formTemplateFieldHTML($template_display_name, $field_name, $instance_num,
 359+ $cur_value, $is_mandatory, $is_hidden, $input_type, $size, $num_rows, $num_cols, $no_autocomplete,
 360+ $autocomplete_category, $error_str, $all_fields, $strict_parsing);
357361 if ($new_text) {
358362 if (is_numeric($field_name)) {
359363 // if the value is null, don't include it at all -
@@ -452,7 +456,7 @@
453457 return array($form_text, $title, $data_text, $passed_validation);
454458 }
455459
456 - function formTemplateFieldHTML($template_name, $field_name, $instance_num, $cur_value, $is_mandatory, $input_type, $size, $num_rows, $num_cols, $no_autocomplete, $autocomplete_category, $error_str, $all_fields, $strict_parsing) {
 460+ function formTemplateFieldHTML($template_name, $field_name, $instance_num, $cur_value, $is_mandatory, $is_hidden, $input_type, $size, $num_rows, $num_cols, $no_autocomplete, $autocomplete_category, $error_str, $all_fields, $strict_parsing) {
457461
458462 // see if this field matches one of the fields defined for this template -
459463 // if it is, use all available information about that field; if it's not,
@@ -460,22 +464,24 @@
461465 // has 'strict' setting in the form definition
462466 foreach ($all_fields as $cur_field) {
463467 if ($field_name == $cur_field->field_name) {
464 - $text = SFFormPrinter::formFieldHTML($template_name, $field_name, $cur_field, $instance_num, $cur_value, $is_mandatory, $input_type, $size, $num_rows, $num_cols, $no_autocomplete, $autocomplete_category, $error_str);
 468+ $text = SFFormPrinter::formFieldHTML($template_name, $field_name, $cur_field, $instance_num, $cur_value, $is_mandatory, $is_hidden, $input_type, $size, $num_rows, $num_cols, $no_autocomplete, $autocomplete_category, $error_str);
465469 return $text;
466470 }
467471 }
468472 // if we're still here, field wasn't found
469473 if (! $strict_parsing) {
470474 $dummy_field = new SFTemplateField();
471 - $text = SFFormPrinter::formFieldHTML($template_name, $field_name, $dummy_field, $instance_num, $cur_value, $is_mandatory, $input_type, $size, $num_rows, $num_cols, $no_autocomplete, $autocomplete_category, $error_str);
 475+ $text = SFFormPrinter::formFieldHTML($template_name, $field_name, $dummy_field, $instance_num, $cur_value, $is_mandatory, $is_hidden, $input_type, $size, $num_rows, $num_cols, $no_autocomplete, $autocomplete_category, $error_str);
472476 return $text;
473477 }
474478 return null;
475479 }
476480
477 - function formFieldHTML($template_name, $field_name, $template_field, $instance_num, $cur_value, $is_mandatory, $input_type, $size, $num_rows, $num_cols, $no_autocomplete, $autocomplete_category, $error_str) {
 481+ function formFieldHTML($template_name, $field_name, $template_field, $instance_num, $cur_value, $is_mandatory, $is_hidden, $input_type, $size, $num_rows, $num_cols, $no_autocomplete, $autocomplete_category, $error_str) {
478482 global $smwgContLang;
479 - if ($autocomplete_category != null) {
 483+ if ($is_hidden) {
 484+ $text = SFFormPrinter::hiddenFieldHTML($template_name, $field_name, $cur_value);
 485+ } elseif ($autocomplete_category != null) {
480486 if ($size == null) $size = 35;
481487 $text = SFFormPrinter::textEntryWithAutocompleteHTML($size, $template_name, $field_name, $instance_num, $autocomplete_category, false, $cur_value, $error_str);
482488 } elseif ($input_type == 'text') {
@@ -524,7 +530,6 @@
525531 global $sfgMaxAutocompleteValues;
526532 $fname = 'SFFormPrinter::createAutocompleteValuesString';
527533 $db = & wfGetDB( DB_SLAVE );
528 - #$limit_str = ($sfgMaxAutocompleteValues) ? "LIMIT $sfgMaxAutocompleteValues" : "";
529534 $sql_options = array();
530535 $sql_options['LIMIT'] = $sfgMaxAutocompleteValues;
531536 // the query depends on whether this field is a relation or a category
@@ -748,6 +753,18 @@
749754 return $text;
750755 }
751756
 757+ function hiddenFieldHTML($template_name, $field_name, $cur_value) {
 758+ if ($template_name == null || $template_name == '')
 759+ $input_name = $field_name;
 760+ else
 761+ $input_name = $template_name . '[' . $field_name . ']';
 762+ $text =<<<END
 763+ <input type="hidden" name="$input_name" value="$cur_value" />
 764+
 765+END;
 766+ return $text;
 767+ }
 768+
752769 function redirectText($page_name, $data_text) {
753770 global $wgUser, $wgRequest;
754771
Index: trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php
@@ -3,7 +3,7 @@
44 * Global functions and constants for Semantic Forms.
55 */
66
7 -define('SF_VERSION','0.3.5');
 7+define('SF_VERSION','0.3.6');
88
99 $wgExtensionFunctions[] = 'sfgSetupExtension';
1010
@@ -37,7 +37,8 @@
3838 /**********************************************/
3939 /***** credits (see "Special:Version") *****/
4040 /**********************************************/
41 - $wgExtensionCredits['parserhook'][]= array('name'=>'Semantic Forms', 'version'=>SF_VERSION, 'author'=>'Yaron Koren', 'url'=>'http://discoursedb.org/SemanticForms/', 'description' => 'Forms for adding and editing semantic data');
 41+ $wgExtensionCredits['parserhook'][]= array('name'=>'Semantic Forms', 'version'=>SF_VERSION, 'author'=>'Yaron Koren',
 42+ 'url'=>'http://discoursedb.org/SemanticForms/', 'description' => 'Forms for adding and editing semantic data');
4243
4344 return true;
4445 }
@@ -180,7 +181,9 @@
181182 */
182183 function sffGetDefaultForm($db, $page_title, $page_namespace) {
183184 $default_form_relation = str_replace(' ', '_', wfMsgForContent('sf_form_relation'));
184 - $sql = "SELECT DISTINCT object_title FROM {$db->tableName('smw_relations')} WHERE subject_title = '$page_title' AND subject_namespace = '" . $page_namespace . "' AND relation_title = '$default_form_relation' AND object_namespace = " . SF_NS_FORM;
 185+ $sql = "SELECT DISTINCT object_title FROM {$db->tableName('smw_relations')} " .
 186+ "WHERE subject_title = '$page_title' AND subject_namespace = '" . $page_namespace .
 187+ "' AND relation_title = '$default_form_relation' AND object_namespace = " . SF_NS_FORM;
185188 $res = $db->query( $sql );
186189 if ($db->numRows( $res ) > 0) {
187190 $row = $db->fetchRow($res);

Status & tagging log