r90836 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90835‎ | r90836 | r90837 >
Date:16:16, 26 June 2011
Author:devayon
Status:deferred
Tags:
Comment:
Added AutoSuggest for properties
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialSearchByProperty.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialSearchByProperty.php
@@ -399,14 +399,72 @@
400400 * @return string HTML for the query form
401401 */
402402 private function queryForm() {
 403+ self::addAutoComplete();
403404 $spectitle = SpecialPage::getTitleFor( 'SearchByProperty' );
404405 $html = '<form name="searchbyproperty" action="' . $spectitle->escapeLocalURL() . '" method="get">' . "\n" .
405406 '<input type="hidden" name="title" value="' . $spectitle->getPrefixedText() . '"/>' ;
406 - $html .= wfMsg( 'smw_sbv_property' ) . ' <input type="text" name="property" value="' . htmlspecialchars( $this->propertystring ) . '" />' . "&#160;&#160;&#160;\n";
 407+ $html .= wfMsg( 'smw_sbv_property' ) . ' <input type="text" id="property_box" name="property" value="' . htmlspecialchars( $this->propertystring ) . '" />' . "&#160;&#160;&#160;\n";
407408 $html .= wfMsg( 'smw_sbv_value' ) . ' <input type="text" name="value" value="' . htmlspecialchars( $this->valuestring ) . '" />' . "\n";
408409 $html .= '<input type="submit" value="' . wfMsg( 'smw_sbv_submit' ) . "\"/>\n</form>\n";
409410
410411 return $html;
411412 }
412413
 414+ /**
 415+ * Creates the JS needed for adding auto-completion to queryForm(). Uses the
 416+ * MW API to fetch suggestions.
 417+ *
 418+ */
 419+ protected static function addAutoComplete() {
 420+ global $wgOut, $smwgScriptPath, $smwgJQueryIncluded, $smwgJQueryUIIncluded;
 421+
 422+ // Add CSS and JavaScript for jQuery and jQuery UI.
 423+ $wgOut->addExtensionStyle( "$smwgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" );
 424+
 425+ $scripts = array();
 426+
 427+ if ( !$smwgJQueryIncluded ) {
 428+ $realFunction = array( 'OutputPage', 'includeJQuery' );
 429+ if ( is_callable( $realFunction ) ) {
 430+ $wgOut->includeJQuery();
 431+ } else {
 432+ $scripts[] = "$smwgScriptPath/libs/jquery-1.4.2.min.js";
 433+ }
 434+
 435+ $smwgJQueryIncluded = true;
 436+ }
 437+
 438+ if ( !$smwgJQueryUIIncluded ) {
 439+ $scripts[] = "$smwgScriptPath/libs/jquery-ui/jquery.ui.core.min.js";
 440+ $scripts[] = "$smwgScriptPath/libs/jquery-ui/jquery.ui.widget.min.js";
 441+ $scripts[] = "$smwgScriptPath/libs/jquery-ui/jquery.ui.position.min.js";
 442+ $scripts[] = "$smwgScriptPath/libs/jquery-ui/jquery.ui.autocomplete.min.js";
 443+ $smwgJQueryUIIncluded = true;
 444+ }
 445+
 446+ foreach ( $scripts as $js ) {
 447+ $wgOut->addScriptFile( $js );
 448+ }
 449+
 450+ $javascript_autocomplete_text = <<<END
 451+<script type="text/javascript">
 452+jQuery(document).ready(function(){
 453+ jQuery("#property_box").autocomplete({
 454+ minLength: 2,
 455+ source: function(request, response) {
 456+ jQuery.getJSON(wgScriptPath+'/api.php?action=opensearch&limit=10&namespace=102&form&search='+request.term, function(data){
 457+ //remove the word 'Property:' from returned data
 458+ for(i=0;i<data[1].length;i++) data[1][i]= data[1][i].substr(9); // 9 because "Property:".length==9
 459+ response(data[1]);
 460+ });
 461+ }
 462+ });
 463+});
 464+</script>
 465+
 466+END;
 467+
 468+ $wgOut->addScript( $javascript_autocomplete_text );
 469+ }
 470+
413471 }

Follow-up revisions

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