jenkins-bot has submitted this change and it was merged.

Change subject: Completion suggester user pref page
......................................................................


Completion suggester user pref page

Custom pref page for completion suggester settings.

Bug: T148010
Change-Id: Ic59644ddd2ef8741e5eaf366d0e6f69e40cbc508
---
M autoload.php
M i18n/en.json
M i18n/qqq.json
A includes/HTMLCompletionProfileSettings.php
M includes/Hooks.php
5 files changed, 143 insertions(+), 13 deletions(-)

Approvals:
  Cindy-the-browser-test-bot: Looks good to me, but someone else must approve
  EBernhardson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/autoload.php b/autoload.php
index a580379..5a39953 100644
--- a/autoload.php
+++ b/autoload.php
@@ -177,4 +177,5 @@
        'CirrusSearch\\UserTesting' => __DIR__ . '/includes/UserTesting.php',
        'CirrusSearch\\Util' => __DIR__ . '/includes/Util.php',
        'CirrusSearch\\Version' => __DIR__ . '/includes/Version.php',
+       'CirrusSearch\\HTMLCompletionProfileSettings' => __DIR__ . 
'/includes/HTMLCompletionProfileSettings.php',
 ];
diff --git a/i18n/en.json b/i18n/en.json
index f7d4b10..08e5f50 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -36,5 +36,21 @@
        "cirrussearch-qi-profile-classic-noboostlinks": "Ranking based on some 
templates, article language and recency when activated on this wiki.",
        "cirrussearch-qi-profile-empty": "Ranking based solely on query 
dependent features (for debug only).",
        "cirrussearch-pref-completion-profile-help": "Set the behavior for 
autocomplete (search-as-you-type) suggestions.",
-       "prefs-completion": "Search completion"
+       "prefs-completion": "Search completion",
+       "cirrussearch-pref-completion-section-desc": "Completion suggester",
+       "cirrussearch-pref-completion-section-legend": "The 
[https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:CirrusSearch/CompletionSuggester
 completion suggester] is an algorithm for search suggestions with better typo 
correction and search relevance.",
+       "cirrussearch-completion-profile-fuzzy-pref-name": "Default 
(recommended).",
+       "cirrussearch-completion-profile-fuzzy-pref-desc": "Corrects up to two 
typos. Resolves close redirects.",
+       "cirrussearch-completion-profile-fuzzy-subphrases-pref-name": "Suphrase 
matching (recommended for longer article titles)",
+       "cirrussearch-completion-profile-fuzzy-subphrases-pref-desc": "Corrects 
up to two types. Resolves close redirects. Matches subphrase in titles.",
+       "cirrussearch-completion-profile-strict-pref-name": "Strict mode 
(advanced)",
+       "cirrussearch-completion-profile-strict-pref-desc": "No typo 
correction. No accent folding. Strict matching.",
+       "cirrussearch-completion-profile-normal-pref-name": "Redirect mode 
(advanced)",
+       "cirrussearch-completion-profile-normal-pref-desc": "No typo 
correction. Resolves close redirects.",
+       "cirrussearch-completion-profile-normal-subphrases-pref-name": 
"Redirect mode with subphrase matching (advanced)",
+       "cirrussearch-completion-profile-normal-subphrases-pref-desc": "No typo 
correction. Resolves close redirects. Matches subphrase in titles.",
+       "cirrussearch-pref-completion-legacy-section-desc": "Prefix search",
+       "cirrussearch-pref-completion-legacy-section-legend": "The legacy 
search-as-you-type suggestion algorithm.",
+       "cirrussearch-completion-profile-classic-pref-name": "Classic prefix 
search",
+       "cirrussearch-completion-profile-classic-pref-desc": "No typo 
correction. Matches the beginning of titles."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 46293ed..c587dd3 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -44,5 +44,21 @@
        "cirrussearch-qi-profile-classic-noboostlinks": "Classic query 
independent search profile without boost links (affects fulltext search ranking 
algorithm).",
        "cirrussearch-qi-profile-empty": "Empty query independent search 
profile (affects fulltext search ranking algorithm).",
        "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."
+       "prefs-completion": "Section name for completion settings in the user 
preferences.",
+       "cirrussearch-pref-completion-section-desc": "Name of the subsection 
Completion Suggester in the user preferences.",
+       "cirrussearch-pref-completion-section-legend": "Legend of the 
subsection Completion Suggester in the user preferences.",
+       "cirrussearch-completion-profile-fuzzy-pref-name": "Name of the 
completion profile fuzzy.",
+       "cirrussearch-completion-profile-fuzzy-pref-desc": "Description of the 
completion profile fuzzy.",
+       "cirrussearch-completion-profile-fuzzy-subphrases-pref-name": "Name of 
the completion profile fuzzy-subphrases",
+       "cirrussearch-completion-profile-fuzzy-subphrases-pref-desc": 
"Description of the completion profile fuzzy-subphrases.",
+       "cirrussearch-completion-profile-strict-pref-name": "Name of the 
completion profile strict.",
+       "cirrussearch-completion-profile-strict-pref-desc": "Description of the 
completion profile strict.",
+       "cirrussearch-completion-profile-normal-pref-name": "Name of the 
completion profile normal.",
+       "cirrussearch-completion-profile-normal-pref-desc": "Description of the 
completion profile normal.",
+       "cirrussearch-completion-profile-normal-subphrases-pref-name": "Name of 
the completion profile normal-subphrases.",
+       "cirrussearch-completion-profile-normal-subphrases-pref-desc": 
"Description of the completion profile normal-subphrase.",
+       "cirrussearch-pref-completion-legacy-section-desc": "Name of the 
subsection Prefix search in the user preferences",
+       "cirrussearch-pref-completion-legacy-section-legend": "Legend of the 
subsection Prefix search in the user preferences.",
+       "cirrussearch-completion-profile-classic-pref-name": "Name of the 
completion profile classic.",
+       "cirrussearch-completion-profile-classic-pref-desc": "Description of 
the completion profile classic."
 }
diff --git a/includes/HTMLCompletionProfileSettings.php 
b/includes/HTMLCompletionProfileSettings.php
new file mode 100644
index 0000000..fe76d6e
--- /dev/null
+++ b/includes/HTMLCompletionProfileSettings.php
@@ -0,0 +1,102 @@
+<?php
+
+namespace CirrusSearch;
+
+use Html;
+use HTMLFormField;
+
+/**
+ * Completion Suggester preferences UI.
+ * Select the profile used by search autocompletion.
+ */
+class HTMLCompletionProfileSettings extends HTMLFormField {
+       /** @var string[] profiles available */
+       private $profiles;
+
+       /** @var string[] Order in which we propose comp suggest profiles */
+       private $compProfilesPreferedOrder = [
+               'fuzzy',
+               'fuzzy-subphrases',
+               'strict',
+               'normal',
+               'normal-subphrases',
+       ];
+
+       public function __construct( $params ) {
+               parent::__construct( $params );
+
+               $this->profiles = [];
+               foreach( $params['profiles'] as $prof ) {
+                       $this->profiles[] = $prof['name'];
+               }
+       }
+
+       /**
+        * @param string $value
+        * @return string
+        */
+       function getInputHTML( $value ) {
+               $html = Html::openElement( 'div' );
+               $html .= Html::element( 'legend',
+                       [],
+                       wfMessage( 'cirrussearch-pref-completion-profile-help' )
+               );
+
+               $html .= Html::element( 'strong',
+                       [],
+                       wfMessage( 'cirrussearch-pref-completion-section-desc' 
)->text()
+               );
+               $html .= Html::rawElement( 'legend',
+                       [],
+                       wfMessage( 
'cirrussearch-pref-completion-section-legend' )->parse()
+               );
+               foreach( $this->compProfilesPreferedOrder as $prof ) {
+                       if ( in_array( $prof, $this->profiles ) ) {
+                               $html .= $this->addCompSuggestOption( $prof, 
$value );
+                       }
+               }
+
+               $html .= Html::element( 'strong',
+                       [],
+                       wfMessage( 
'cirrussearch-pref-completion-legacy-section-desc' )->text()
+               );
+               $html .= Html::rawElement( 'legend',
+                       [],
+                       wfMessage( 
'cirrussearch-pref-completion-legacy-section-legend' )->parse()
+               );
+               $html .= $this->addCompSuggestOption( 'classic', $value );
+               $html .= Html::closeElement( 'div' );
+               return $html;
+       }
+
+       /**
+        * @param string $prof profile name
+        * @param string $value selected profile name
+        * @return string html
+        */
+       private function addCompSuggestOption( $prof, $value ) {
+               $html = Html::openElement( 'div' );
+               $html .= Html::openElement( 'div', [ 'style' => 
'vertical-align:top; display:inline-block;' ] );
+               $radioId = $this->mID . "-$prof";
+               $radioAttrs = [
+                       'id' => $radioId,
+               ];
+               if ( $prof === $value ) {
+                       $radioAttrs['checked'] = 'checked';
+               }
+               $html .= Html::input( $this->mID, $prof, 'radio', $radioAttrs );
+               $html .= Html::closeElement( 'div' );
+               $html .= Html::openElement( 'div', [ 'style' => 
'display:inline-block' ] );
+               $html .= Html::element( 'label',
+                       ['for' => $radioId, 'style' => 'font-weight: bold'],
+                       wfMessage( 
"cirrussearch-completion-profile-$prof-pref-name" )->text()
+               );
+               $html .= Html::element( 'div',
+                       [],
+                       wfMessage( 
"cirrussearch-completion-profile-$prof-pref-desc" )->text()
+               );
+               $html .= Html::closeElement( 'div' );
+               $html .= Html::closeElement( 'div' );
+               return $html;
+       }
+}
diff --git a/includes/Hooks.php b/includes/Hooks.php
index d87d373..5e13c98 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -807,20 +807,15 @@
                ] );
        }
 
-       public static function onGetPreferences( $user, &$preferences ) {
+       public static function onGetPreferences( $user, &$prefs ) {
                $search = new CirrusSearch();
                $profiles = $search->getProfiles( 
\SearchEngine::COMPLETION_PROFILE_TYPE, $user );
-               if ( !empty( $profiles ) ) {
-                       $options = [];
-                       foreach( $profiles as $prof ) {
-                               $options[wfMessage( $prof['desc-message'] 
)->text()] = $prof['name'];
-                       }
-                       $preferences['cirrussearch-pref-completion-profile'] = 
array(
-                               'type' => 'radio',
+               if ( !empty( $profiles ) && count( $profiles ) > 1 ) {
+                       $prefs['cirrussearch-pref-completion-profile'] = [
+                               'class' => HTMLCompletionProfileSettings::class,
                                'section' => 'searchoptions/completion',
-                               'options' => $options,
-                               'help-message' => 
'cirrussearch-pref-completion-profile-help',
-                       );
+                               'profiles' => $profiles
+                       ];
                }
                return true;
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic59644ddd2ef8741e5eaf366d0e6f69e40cbc508
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: DCausse <dcau...@wikimedia.org>
Gerrit-Reviewer: Cindy-the-browser-test-bot <bernhardsone...@gmail.com>
Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Gehel <gleder...@wikimedia.org>
Gerrit-Reviewer: Jdrewniak <jdrewn...@wikimedia.org>
Gerrit-Reviewer: Manybubbles <never...@wikimedia.org>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: Smalyshev <smalys...@wikimedia.org>
Gerrit-Reviewer: Tjones <tjo...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to