r90765 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90764‎ | r90765 | r90766 >
Date:11:34, 25 June 2011
Author:devayon
Status:deferred
Tags:
Comment:
Changed the autocomplete to use ajax and MW API. Addressed bug 27687
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php
@@ -179,8 +179,8 @@
180180
181181 /**
182182 * 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
185185 * @since 1.5.2
186186 */
187187 protected static function addAutocompletionJavascriptAndCSS() {
@@ -213,32 +213,7 @@
214214 foreach ( $scripts as $js ) {
215215 $wgOut->addScriptFile( $js );
216216 }
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+
243218 $javascript_autocomplete_text = <<<END
244219 <script type="text/javascript">
245220 function split(val) {
@@ -284,10 +259,15 @@
285260
286261 jQuery(document).ready(function(){
287262 jQuery("#add_property").autocomplete({
288 - minLength: 1,
 263+ minLength: 2,
289264 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+ });
292272 },
293273 focus: function() {
294274 // prevent value inserted on focus

Follow-up revisions

RevisionCommit summaryAuthorDate
r91251Followup to r90836, r90834 and r90765devayon06:40, 1 July 2011