DCausse has uploaded a new change for review.
https://gerrit.wikimedia.org/r/281468
Change subject: [WIP] Allow user to customize search suggestion profile.
......................................................................
[WIP] Allow user to customize search suggestion profile.
Adds a new section "completion" in the Search preference tab.
WIP: This does not work properly, I don't understand how 'default' is supposed
to work in User preferences.
It requires an update to the patch in core: profile Api param should be
optionnal with no default (otherwize I don't know when the profile has been
explicitely set as
an api param).
In theory this patch could be moved to core (suggestions welcome).
Change-Id: Icd577c8ebc6e162befe30bde4fe276e633d2e434
---
M CirrusSearch.php
M i18n/en.json
M i18n/qqq.json
M includes/CirrusSearch.php
M includes/Hooks.php
5 files changed, 42 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/68/281468/1
diff --git a/CirrusSearch.php b/CirrusSearch.php
index b1678c3..75afbbf 100644
--- a/CirrusSearch.php
+++ b/CirrusSearch.php
@@ -952,6 +952,7 @@
$wgHooks[ 'GetBetaFeaturePreferences' ][] =
'CirrusSearch\Hooks::getBetaFeaturePreferences';
$wgHooks[ 'APIAfterExecute' ][] = 'CirrusSearch\Hooks::onAPIAfterExecute';
$wgHooks[ 'SpecialSearchResults' ][] =
'CirrusSearch\Hooks::onSpecialSearchResults';
+$wgHooks[ 'GetPreferences' ][] = 'CirrusSearch\Hooks::onGetPreferences';
/**
* i18n
diff --git a/i18n/en.json b/i18n/en.json
index a80b6ee..1777fb0 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -31,5 +31,7 @@
"cirrussearch-completion-profile-strict": "Strict profile with few
punctuation characters removed but diacritics and stress marks are kept.",
"cirrussearch-completion-profile-classic": "Classic prefix, few
punctuation characters and some diacritics removed.",
"cirrussearch-completion-profile-normal": "Few punctuation characters,
some diacritics and stopwords removed.",
- "cirrussearch-completion-profile-fuzzy": "Similar to normal with typo
correction (two typos supported)."
+ "cirrussearch-completion-profile-fuzzy": "Similar to normal with typo
correction (two typos supported).",
+ "cirrussearch-pref-completion-profile-help": "Set the behavior for
autocomplete (search-as-you-type) suggestions.",
+ "prefs-completion": "Search completion"
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 8803a7f..dc0aebc 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -39,5 +39,7 @@
"cirrussearch-completion-profile-strict": "Strict profile for
completion (search as you type).",
"cirrussearch-completion-profile-classic": "Classic profile for
completion (search as you type).",
"cirrussearch-completion-profile-normal": "Normal profile for
completion (search as you type).",
- "cirrussearch-completion-profile-fuzzy": "Fuzzy profile for completion
(search as you type)."
+ "cirrussearch-completion-profile-fuzzy": "Fuzzy profile for completion
(search as you type).",
+ "cirrussearch-pref-completion-profile-help": "Help message for
completion profile settings in the user preferences.",
+ "prefs-completion": "Section name for completion settings in the user
preferences."
}
diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index 80b37ee..0981df0 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -585,6 +585,7 @@
* @return SearchSuggestionSet
*/
protected function completionSearchBackend( $search ) {
+ global $wgUser;
if ( in_array( NS_SPECIAL, $this->namespaces ) ) {
// delegate special search to parent
@@ -603,6 +604,14 @@
return $this->prefixSearch( $search );
}
+ // If the profile is not explicitely set in featureData we try
to use
+ // the user preferences
+ if ( !isset (
$this->features[SearchEngine::COMPLETION_PROFILE_TYPE] )
+ && $wgUser->getOption(
'cirrussearch-pref-completion-profile' ) != null ) {
+ $this->setFeatureData(
SearchEngine::COMPLETION_PROFILE_TYPE,
+ $wgUser->getOption(
'cirrussearch-pref-completion-profile' ) );
+ }
+
if ( isset(
$this->features[SearchEngine::COMPLETION_PROFILE_TYPE] ) ) {
// Fallback to prefixsearch if the classic profile was
selected.
if (
$this->features[SearchEngine::COMPLETION_PROFILE_TYPE] ==
self::COMPLETION_PREFIX_FALLBACK_PROFILE ) {
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 7b0377f..96414b2 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -699,4 +699,30 @@
$textMatches
) );
}
+
+ public static function onGetPreferences( $user, &$preferences ) {
+ $search = new CirrusSearch();
+ $profiles = $search->getProfiles(
\SearchEngine::COMPLETION_PROFILE_TYPE );
+ if ( !empty( $profiles ) ) {
+ $default = null;
+ $options = array();
+ foreach( $profiles as $prof ) {
+ $options[wfMessage( $prof['desc-message']
)->escaped()] = $prof['name'];
+ if ( !empty( $prof['default'] ) ) {
+ $default = $prof['name'];
+ }
+ }
+ $preferences['cirrussearch-pref-completion-profile'] =
array(
+ 'type' => 'radio',
+ 'section' => 'searchoptions/completion',
+ 'options' => $options,
+ // XXX: if I set default here the preference UI
will always select default
+ // if I remove default then the UI is properly
updated
+ // but it triggers an error if the user has not
customized this setting...
+ 'default' => $default,
+ 'help-message' =>
'cirrussearch-completion-pref-profile-help',
+ );
+ }
+ return true;
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/281468
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd577c8ebc6e162befe30bde4fe276e633d2e434
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: DCausse <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits