Index: trunk/extensions/SemanticForms/includes/SF_Utils.inc |
— | — | @@ -14,6 +14,10 @@ |
15 | 15 | $sf_props = $sfgContLang->getPropertyLabels(); |
16 | 16 | SMWPropertyValue::registerProperty('_SF_DF', '__spf', $sf_props[SF_SP_HAS_DEFAULT_FORM], true); |
17 | 17 | SMWPropertyValue::registerProperty('_SF_AF', '__spf', $sf_props[SF_SP_HAS_ALTERNATE_FORM], true); |
| 18 | + // also initialize hardcoded English values, if it's a non-English-language wiki |
| 19 | + SMWPropertyValue::registerProperty('_SF_DF_BACKUP', '__spf', 'Has default form', true); |
| 20 | + SMWPropertyValue::registerProperty('_SF_AF_BACKUP', '__spf', 'Has alternate form', true); |
| 21 | + |
18 | 22 | return true; |
19 | 23 | } |
20 | 24 | |
— | — | @@ -82,6 +86,53 @@ |
83 | 87 | } |
84 | 88 | |
85 | 89 | /** |
| 90 | + * Includes the necessary Javascript and CSS files for the form |
| 91 | + * to display and work correctly |
| 92 | + */ |
| 93 | + static function addJavascriptAndCSS() { |
| 94 | + global $wgOut, $sfgScriptPath, $sfgYUIBase, $wgFCKEditorDir; |
| 95 | + |
| 96 | + $mainCssUrl = $sfgScriptPath . '/skins/SF_main.css'; |
| 97 | + $wgOut->addLink( array( |
| 98 | + 'rel' => 'stylesheet', |
| 99 | + 'type' => 'text/css', |
| 100 | + 'media' => "screen, projection", |
| 101 | + 'href' => $mainCssUrl |
| 102 | + )); |
| 103 | + $wgOut->addLink( array( |
| 104 | + 'rel' => 'stylesheet', |
| 105 | + 'type' => 'text/css', |
| 106 | + 'media' => "screen, projection", |
| 107 | + 'href' => $sfgYUIBase . "autocomplete/assets/skins/sam/autocomplete.css" |
| 108 | + )); |
| 109 | + $wgOut->addLink( array( |
| 110 | + 'rel' => 'stylesheet', |
| 111 | + 'type' => 'text/css', |
| 112 | + 'media' => "screen, projection", |
| 113 | + 'href' => $sfgScriptPath . '/skins/SF_yui_autocompletion.css' |
| 114 | + )); |
| 115 | + $wgOut->addLink( array( |
| 116 | + 'rel' => 'stylesheet', |
| 117 | + 'type' => 'text/css', |
| 118 | + 'media' => "screen, projection", |
| 119 | + 'href' => $sfgScriptPath . '/skins/floatbox.css' |
| 120 | + )); |
| 121 | + $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'yahoo/yahoo-min.js"></script>' . "\n"); |
| 122 | + $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'dom/dom-min.js"></script>' . "\n"); |
| 123 | + $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'event/event-min.js"></script>' . "\n"); |
| 124 | + $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'get/get-min.js"></script>' . "\n"); |
| 125 | + $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'connection/connection-min.js"></script>' . "\n"); |
| 126 | + $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'json/json-min.js"></script>' . "\n"); |
| 127 | + $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'datasource/datasource-min.js"></script>' . "\n"); |
| 128 | + $wgOut->addScript('<script type="text/javascript" src="' . $sfgYUIBase . 'autocomplete/autocomplete-min.js"></script>' . "\n"); |
| 129 | + $wgOut->addScript('<script type="text/javascript" src="' . $sfgScriptPath . '/libs/SF_yui_autocompletion.js"></script>' . "\n"); |
| 130 | + $wgOut->addScript('<script type="text/javascript" src="' . $sfgScriptPath . '/libs/floatbox.js"></script>' . "\n"); |
| 131 | + if ($wgFCKEditorDir) |
| 132 | + $wgOut->addScript('<script type="text/javascript" src="' . "$wgScriptPath/$wgFCKEditorDir" . '/fckeditor.js"></script>' . "\n"); |
| 133 | + $wgOut->addMeta('robots','noindex,nofollow'); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
86 | 137 | * A helper function to generate a property object given its name, |
87 | 138 | * since the class for properties changed from Title to |
88 | 139 | * SMWPropertyValue in SMW 1.4 |
— | — | @@ -139,87 +190,29 @@ |
140 | 191 | return $str; |
141 | 192 | } |
142 | 193 | |
143 | | - |
144 | | - static function getAllValuesForProperty_orig($is_relation, $property_name, $substring = null) { |
| 194 | + /* |
| 195 | + * This function, unlike the others, doesn't take in a substring |
| 196 | + * because it uses the SMW data store, which can't perform |
| 197 | + * case-insensitive queries; for queries with a substring, the |
| 198 | + * function SFAutocompletAPI::getAllValuesForProperty() exists. |
| 199 | + */ |
| 200 | + static function getAllValuesForProperty($property_name) { |
145 | 201 | global $sfgMaxAutocompleteValues; |
146 | 202 | |
147 | | - $fname = "getAllValuesForProperty_orig"; |
148 | | - $values = array(); |
149 | | - $db = wfGetDB( DB_SLAVE ); |
150 | | - $sql_options = array(); |
151 | | - $sql_options['LIMIT'] = $sfgMaxAutocompleteValues; |
152 | | - $property_field = ($is_relation) ? 'relation_title' : 'attribute_title'; |
153 | | - $value_field = ($is_relation) ? 'object_title' : 'value_xsd'; |
154 | | - $property_table = ($is_relation) ? 'smw_relations' : 'smw_attributes'; |
155 | | - $property_name = str_replace(' ', '_', $property_name); |
156 | | - $conditions = "$property_field = '$property_name'"; |
157 | | - if ($substring != null) { |
158 | | - $substring = str_replace(' ', '_', strtolower($substring)); |
159 | | - $substring = str_replace('_', '\_', $substring); |
160 | | - $substring = str_replace("'", "\'", $substring); |
161 | | - $conditions .= " AND (LOWER($value_field) LIKE '" . $substring . "%' OR LOWER($value_field) LIKE '%\_" . $substring . "%')"; |
162 | | - } |
163 | | - $sql_options['ORDER BY'] = $value_field; |
164 | | - $res = $db->select( $db->tableName($property_table), |
165 | | - "DISTINCT $value_field", |
166 | | - $conditions, $fname, $sql_options); |
167 | | - while ($row = $db->fetchRow($res)) { |
168 | | - if ($substring != null) { |
169 | | - $values[] = array('title' => str_replace('_', ' ', $row[0])); |
170 | | - } else { |
171 | | - $cur_value = str_replace("'", "\'", $row[0]); |
172 | | - $values[] = str_replace('_', ' ', $cur_value); |
173 | | - } |
174 | | - } |
175 | | - $db->freeResult($res); |
176 | | - return $values; |
177 | | - } |
178 | | - |
179 | | - static function getAllValuesForProperty_1_2($property_name, $substring = null) { |
180 | | - global $sfgMaxAutocompleteValues; |
181 | | - |
182 | 203 | $store = smwfGetStore(); |
183 | 204 | $requestoptions = new SMWRequestOptions(); |
184 | 205 | $requestoptions->limit = $sfgMaxAutocompleteValues; |
185 | | - if ($substring != null) { |
186 | | - $requestoptions->addStringCondition($substring, SMWStringCondition::STRCOND_PRE); |
187 | | - } |
188 | 206 | $property = SFUtils::createProperty($property_name); |
189 | 207 | $data_values = $store->getPropertyValues(null, $property, $requestoptions); |
190 | 208 | $values = array(); |
191 | 209 | foreach ($data_values as $dv) { |
192 | 210 | // getPropertyValues() gets many repeat values - we want |
193 | 211 | // only one of each value |
194 | | - $string_value = str_replace('_', ' ', $dv->getXSDValue()); |
195 | | - $string_value = str_replace("'", "\'", $string_value); |
| 212 | + $string_value = str_replace('_', ' ', $dv->getWikiValue()); |
196 | 213 | if (array_search($string_value, $values) === false) |
197 | 214 | $values[] = $string_value; |
198 | 215 | } |
199 | | - // if there was a substring specified, also find values that |
200 | | - // have it after a space, not just at the beginning of the value |
201 | | - if ($substring != null) { |
202 | | - $requestoptions2 = new SMWRequestOptions(); |
203 | | - $requestoptions2->limit = $sfgMaxAutocompleteValues; |
204 | | - $requestoptions2->addStringCondition(" $substring", SMWStringCondition::STRCOND_MID); |
205 | | - $data_values = $store->getPropertyValues(null, $property, $requestoptions2); |
206 | | - foreach ($data_values as $dv) { |
207 | | - $string_value = str_replace('_', ' ', $dv->getXSDValue()); |
208 | | - if (array_search($string_value, $values) === false) |
209 | | - $values[] = $string_value; |
210 | | - } |
211 | | - } |
212 | | - if ($substring == null) |
213 | | - return $values; |
214 | | - else { |
215 | | - $autocomplete_vals = array(); |
216 | | - foreach ($values as $value) { |
217 | | - // if these values are being returned for remote |
218 | | - // autocompletion, undo the apostrophe-escaping |
219 | | - $value = str_replace("\'", "'", $value); |
220 | | - $autocomplete_vals[] = array('title' => $value); |
221 | | - } |
222 | | - return $autocomplete_vals; |
223 | | - } |
| 216 | + return $values; |
224 | 217 | } |
225 | 218 | |
226 | 219 | /* |
— | — | @@ -302,6 +295,9 @@ |
303 | 296 | } |
304 | 297 | */ |
305 | 298 | $concept = Title::makeTitleSafe(SMW_NS_CONCEPT, $concept_name); |
| 299 | + // escape if there's a problem |
| 300 | + if ($concept == null) |
| 301 | + return array(); |
306 | 302 | $desc = new SMWConceptDescription($concept); |
307 | 303 | $printout = new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, ""); |
308 | 304 | $desc->addPrintRequest($printout); |
— | — | @@ -322,7 +318,7 @@ |
323 | 319 | global $wgContLang; |
324 | 320 | $namespaces = $wgContLang->getNamespaces(); |
325 | 321 | $db = wfGetDB( DB_SLAVE ); |
326 | | - $fname = "getAllPagesForNamespace"; |
| 322 | + $fname = "SFUtils::getAllPagesForNamespace"; |
327 | 323 | $pages = array(); |
328 | 324 | foreach ($namespaces as $ns_code => $ns_name) { |
329 | 325 | if ($ns_name == $namespace_name) { |