MathiasLidal has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/71330


Change subject: Fix prefix in search boxes
......................................................................

Fix prefix in search boxes

Currently prefix-search doesn't work for lucene search engine (the only
engine which supports it). For it to work you need to add prefix:foobar
to the search string, not as a http parameter.

This code adds a small javascript snippet which appends the necessary
text to the search field when the user clicks the search button

Change-Id: I14db6e13e53cf7de70d88290a2ae50e15dfd238e
---
M InputBox.classes.php
M InputBox.php
A js/ext.inputbox.js
3 files changed, 21 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/InputBox 
refs/changes/30/71330/1

diff --git a/InputBox.classes.php b/InputBox.classes.php
index 380015c..aad7299 100644
--- a/InputBox.classes.php
+++ b/InputBox.classes.php
@@ -96,12 +96,19 @@
                                'style' => 'margin-left: auto; margin-right: 
auto; text-align: center; background-color:' . $this->mBGColor
                        )
                );
+
+               $onsubmit = "";
+               if ( $this->mPrefix != '' ) {
+                       $onsubmit = "appendPrefix('searchboxInput', '" . 
$this->mPrefix . "');";
+               }
+
                $htmlOut .= Xml::openElement( 'form',
                        array(
                                'name' => 'searchbox',
                                'id' => 'searchbox',
                                'class' => 'searchbox',
                                'action' => SpecialPage::getTitleFor( 'Search' 
)->escapeLocalUrl(),
+                               'onsubmit' => $onsubmit,
                        )
                );
                $htmlOut .= Xml::element( 'input',
diff --git a/InputBox.php b/InputBox.php
index b54baa3..2fdee0f 100644
--- a/InputBox.php
+++ b/InputBox.php
@@ -52,3 +52,13 @@
 // Register parser hook
 $wgHooks['ParserFirstCallInit'][] = 'InputBoxHooks::register';
 $wgHooks['MediaWikiPerformAction'][] = 
'InputBoxHooks::onMediaWikiPerformAction';
+
+$wgResourceModules['ext.inputbox.core'] = array(
+       'scripts' => array(
+               'js/ext.inputbox.js'
+       ),
+       'group' => 'ext.inputbox',
+       'localBasePath' => dirname(__FILE__),
+       'remoteExtPath' => 'InputBox'
+);
+
diff --git a/js/ext.inputbox.js b/js/ext.inputbox.js
new file mode 100644
index 0000000..ba52e37
--- /dev/null
+++ b/js/ext.inputbox.js
@@ -0,0 +1,4 @@
+function appendPrefix(id, prefix) {
+       var input = document.getElementById(id);
+       input.value = input.value + ' prefix:' + prefix;
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/71330
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I14db6e13e53cf7de70d88290a2ae50e15dfd238e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/InputBox
Gerrit-Branch: master
Gerrit-Owner: MathiasLidal <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to