Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php |
— | — | @@ -179,8 +179,8 @@ |
180 | 180 | |
181 | 181 | /** |
182 | 182 | * Creates and adds the JavaScript and JS needed for autocompletion to $wgOut. |
183 | | - * |
184 | | - * @bug This method asks the store for all used and unused property names, which can be very expensive. It does not even use a limit to restrict the number of results. Cheaper ways to get the labels need to be sought. What sense does it make to add unused properties to the options on autocomplete for a query interface? |
| 183 | + * Uses the MW API to get suggestions for properties. |
| 184 | + * @TODO Test for non-english wikis, add caching on client to improve performance |
185 | 185 | * @since 1.5.2 |
186 | 186 | */ |
187 | 187 | protected static function addAutocompletionJavascriptAndCSS() { |
— | — | @@ -213,32 +213,7 @@ |
214 | 214 | foreach ( $scripts as $js ) { |
215 | 215 | $wgOut->addScriptFile( $js ); |
216 | 216 | } |
217 | | - |
218 | | - /* collect property names for autocomplete */ |
219 | | - $propertyNames[] = array(); |
220 | | - $results = smwfGetStore()->getPropertiesSpecial(); |
221 | | - |
222 | | - foreach ( $results as $result ) { |
223 | | - $propertyNames[] = $result[0]->getLabel(); |
224 | | - } |
225 | | - |
226 | | - $results = smwfGetStore()->getUnusedPropertiesSpecial(); |
227 | | - |
228 | | - foreach ( $results as $result ) { |
229 | | - $propertyNames[] = $result->getLabel(); |
230 | | - } |
231 | | - |
232 | | - sort( $propertyNames ); |
233 | | - |
234 | | - $properties_po = "["; |
235 | | - foreach ( $propertyNames as $i => $property ) { |
236 | | - if ( $i > 0 ) { |
237 | | - $properties_po .= ", "; |
238 | | - } |
239 | | - $properties_po .= "'?" . $property . "'"; |
240 | | - } |
241 | | - $properties_po .= "]"; |
242 | | - |
| 217 | + |
243 | 218 | $javascript_autocomplete_text = <<<END |
244 | 219 | <script type="text/javascript"> |
245 | 220 | function split(val) { |
— | — | @@ -284,10 +259,15 @@ |
285 | 260 | |
286 | 261 | jQuery(document).ready(function(){ |
287 | 262 | jQuery("#add_property").autocomplete({ |
288 | | - minLength: 1, |
| 263 | + minLength: 2, |
289 | 264 | source: function(request, response) { |
290 | | - // delegate back to autocomplete, but extract the last term |
291 | | - response(jQuery.ui.autocomplete.filter({$properties_po}, escapeQuestion(extractLast(request.term)))); |
| 265 | + request.term=request.term.substr(request.term.lastIndexOf("\\n")+1); |
| 266 | + |
| 267 | + jQuery.getJSON(wgScriptPath+'/api.php?action=opensearch&limit=10&namespace=102&form&search='+request.term, function(data){ |
| 268 | + //remove the word 'Property:' from returned data and add prefix '?' |
| 269 | + for(i=0;i<data[1].length;i++) data[1][i]="?"+data[1][i].substr(9); // 9 because "Property:".length==9 |
| 270 | + response(jQuery.ui.autocomplete.filter(data[1], escapeQuestion(extractLast(request.term)))); |
| 271 | + }); |
292 | 272 | }, |
293 | 273 | focus: function() { |
294 | 274 | // prevent value inserted on focus |