r36742 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36741‎ | r36742 | r36743 >
Date:13:22, 27 June 2008
Author:yaron
Status:old
Tags:
Comment:
Removed SMW-0.7-specific code
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_CreateProperty.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_CreateProperty.php
@@ -23,26 +23,15 @@
2424 function createPropertyText($property_type, $allowed_values_str) {
2525 global $smwgContLang;
2626
27 - $smw_version = SMW_VERSION;
28 - if ($smw_version{0} == '0') {
29 - $namespace_labels = $smwgContLang->getNamespaceArray();
30 - } else {
31 - $namespace_labels = $smwgContLang->getNamespaces();
32 - }
 27+ $namespace_labels = $smwgContLang->getNamespaces();
3328 if ($property_type == $namespace_labels[SMW_NS_RELATION]) {
3429 $text = wfMsgForContent('sf_property_isrelation');
3530 } else {
3631 global $smwgContLang;
3732 $specprops = $smwgContLang->getSpecialPropertiesArray();
38 - if ($smw_version{0} == '0') {
39 - $type_tag = "[[" . $specprops[SMW_SP_HAS_TYPE] . "::" .
40 - $namespace_labels[SMW_NS_TYPE] . ":$property_type|$property_type]]";
41 - $text = wfMsgForContent('sf_property_isattribute', $type_tag);
42 - } else {
43 - $type_tag = "[[" . $specprops[SMW_SP_HAS_TYPE] .
44 - "::$property_type|$property_type]]";
45 - $text = wfMsgForContent('sf_property_isproperty', $type_tag);
46 - }
 33+ $type_tag = "[[" . $specprops[SMW_SP_HAS_TYPE] .
 34+ "::$property_type|$property_type]]";
 35+ $text = wfMsgForContent('sf_property_isproperty', $type_tag);
4736 if ($allowed_values_str != '') {
4837 $text .= "\n\n" . wfMsgForContent('sf_property_allowedvals');
4938 // replace the comma substitution character that has no chance of
@@ -53,7 +42,7 @@
5443 foreach ($allowed_values_array as $i => $value) {
5544 // replace beep with comma, trim
5645 $value = str_replace("\a", $sfgListSeparator, trim($value));
57 - $text .= "\n* [[" . $specprops[SMW_SP_POSSIBLE_VALUE] . ":=$value]]";
 46+ $text .= "\n* [[" . $specprops[SMW_SP_POSSIBLE_VALUE] . "::$value]]";
5847 }
5948 }
6049 }
@@ -81,13 +70,7 @@
8271 $property_name_error_str = wfMsg('sf_blank_error');
8372 } else {
8473 # redirect to wiki interface
85 - $smw_version = SMW_VERSION;
86 - if ($smw_version{0} == '0') {
87 - $namespace_labels = $smwgContLang->getNamespaceArray();
88 - $namespace = ($property_type == $namespace_labels[SMW_NS_RELATION]) ? SMW_NS_RELATION : SMW_NS_ATTRIBUTE;
89 - } else {
90 - $namespace = SMW_NS_PROPERTY;
91 - }
 74+ $namespace = SMW_NS_PROPERTY;
9275 $title = Title::newFromText($property_name, $namespace);
9376 $full_text = createPropertyText($property_type, $allowed_values);
9477 // HTML-encode
@@ -98,50 +81,16 @@
9982 }
10083 }
10184
102 - $smw_version = SMW_VERSION;
103 - if ($smw_version{0} == '0') {
104 - $all_properties = getSemanticProperties_0_7();
105 - $namespace_labels = $smwgContLang->getNamespaceArray();
106 - $datatype_labels = array(
107 - $namespace_labels[SMW_NS_RELATION],
108 - $smwgContLang->getDatatypeLabel('smw_string'),
109 - $smwgContLang->getDatatypeLabel('smw_int'),
110 - $smwgContLang->getDatatypeLabel('smw_float'),
111 - $smwgContLang->getDatatypeLabel('smw_datetime'),
112 - $smwgContLang->getDatatypeLabel('smw_bool'),
113 - $smwgContLang->getDatatypeLabel('smw_enum'),
114 - $smwgContLang->getDatatypeLabel('smw_url'),
115 - $smwgContLang->getDatatypeLabel('smw_uri'),
116 - $smwgContLang->getDatatypeLabel('smw_email'),
117 - $smwgContLang->getDatatypeLabel('smw_temperature'),
118 - $smwgContLang->getDatatypeLabel('smw_geocoordinate')
119 - );
120 - $enum_str = $smwgContLang->getDatatypeLabel('smw_enum');
121 - } else {
122 - $all_properties = getSemanticProperties_1_0();
123 - $datatype_labels = $smwgContLang->getDatatypeLabels();
124 - }
 85+ $all_properties = getSemanticProperties();
 86+ $datatype_labels = $smwgContLang->getDatatypeLabels();
12587
12688 $javascript_text =<<<END
12789 function toggleAllowedValues() {
12890 var values_div = document.getElementById("allowed_values");
 91+}
12992
13093 END;
131 - // add toggling of 'possible values' entry only if this is SMW 0.7 or
132 - // lower; otherwise, it should always appear
133 - if ($smw_version{0} == '0') {
134 - $javascript_text .=<<<END
135 - var prop_dropdown = document.getElementById("property_dropdown");
136 - if (prop_dropdown.value == "$enum_str") {
137 - values_div.style.display = "block";
138 - } else {
139 - values_div.style.display = "none";
140 - }
14194
142 -END;
143 - }
144 - $javascript_text .= "}\n";
145 -
14695 // set 'title' as hidden field, in case there's no URL niceness
14796 global $wgContLang;
14897 $mw_namespace_labels = $wgContLang->getNamespaces();
@@ -160,11 +109,10 @@
161110 $text .= " <option>$label</option>\n";
162111 }
163112
164 - $values_input_display = ($smw_version{0} == '0') ? "display: none;" : "";
165113 $values_input = wfMsg('sf_createproperty_allowedvalsinput');
166114 $text .=<<<END
167115 </select>
168 - <div id="allowed_values" style="$values_input_display margin-bottom: 15px;">
 116+ <div id="allowed_values" style="margin-bottom: 15px;">
169117 <p>$values_input</p>
170118 <p><input size="35" name="values" value=""></p>
171119 </div>
Index: trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php
@@ -20,7 +20,7 @@
2121
2222 SpecialPage::addPage( new SpecialPage('CreateTemplate','',true,'doSpecialCreateTemplate',false) );
2323
24 -// Custom sort function, used in both getSemanticProperties() functions
 24+// Custom sort function, used in getSemanticProperties()
2525 function cmp($a, $b) {
2626 if ($a == $b) {
2727 return 0;
@@ -31,37 +31,9 @@
3232 }
3333 }
3434
35 -function getSemanticProperties_0_7() {
36 - $dbr = wfGetDB( DB_SLAVE );
 35+function getSemanticProperties() {
3736 $all_properties = array();
3837
39 - $res = $dbr->query("SELECT page_title FROM " . $dbr->tableName('page') .
40 - " WHERE page_namespace = " . SMW_NS_ATTRIBUTE .
41 - " AND page_is_redirect = 0");
42 - while ($row = $dbr->fetchRow($res)) {
43 - $attribute_name = str_replace('_', ' ', $row[0]);
44 - $all_properties[$attribute_name . ":="] = $attribute_name;
45 - }
46 - $dbr->freeResult($res);
47 -
48 - $res = $dbr->query("SELECT page_title FROM " . $dbr->tableName('page') .
49 - " WHERE page_namespace = " . SMW_NS_RELATION .
50 - " AND page_is_redirect = 0");
51 - while ($row = $dbr->fetchRow($res)) {
52 - $relation_name = str_replace('_', ' ', $row[0]);
53 - $all_properties[$relation_name . "::"] = $relation_name;
54 - }
55 - $dbr->freeResult($res);
56 -
57 - // sort properties list alphabetically - custom sort function is needed
58 - // because the regular sort function destroys the "keys" of the array
59 - uasort($all_properties, "cmp");
60 - return $all_properties;
61 -}
62 -
63 -function getSemanticProperties_1_0() {
64 - $all_properties = array();
65 -
6638 // set limit on results - a temporary fix until SMW's getProperties()
6739 // functions stop requiring a limit
6840 global $smwgIP;
@@ -119,12 +91,7 @@
12092 function doSpecialCreateTemplate() {
12193 global $wgOut, $wgRequest, $wgUser, $sfgScriptPath, $wgContLang;
12294
123 - $smw_version = SMW_VERSION;
124 - if ($smw_version{0} == '0') {
125 - $all_properties = getSemanticProperties_0_7();
126 - } else {
127 - $all_properties = getSemanticProperties_1_0();
128 - }
 95+ $all_properties = getSemanticProperties();
12996
13097 $template_name = $wgRequest->getVal('template_name');
13198 $template_name_error_str = "";

Status & tagging log