Deprecate usage of SearchEngine:transformSearchTerm
authorDavid Causse <dcausse@wikimedia.org>
Mon, 25 Jun 2018 17:19:32 +0000 (19:19 +0200)
committerErik Bernhardson <ebernhardson@wikimedia.org>
Tue, 17 Jul 2018 21:41:08 +0000 (14:41 -0700)
This method was introduced in 4115586000a575eb814a80868c817d18ee169d3b
to support the prefix URI param introduced by the InputBox extension.
There are no reasons that this logic is exposed to SearchEngine users
and should be handled internally by SearchEngine implementations
that supports it.
Previously the search query was updated, now the prefix param will passed
along using SpecialSearch::$extraParams.

Bug: T198318
Change-Id: I33518d3f3ddee741ff4f3b47eb4928009bea66d1
Depends-On: I67c7f1886dd6a2d07c12015e2711c138e9f140e9

RELEASE-NOTES-1.32
includes/api/ApiQuerySearch.php
includes/search/SearchEngine.php
includes/specials/SpecialSearch.php
includes/widget/search/SearchFormWidget.php
languages/i18n/en.json
languages/i18n/qqq.json

index 1dbc787..4f1cd79 100644 (file)
@@ -267,6 +267,12 @@ because of Phabricator reports.
   the Parsoid v3 API in May 2015.
 * $input is deprecated in hook 'LogEventsListGetExtraInputs'. Use
   $formDescriptor instead.
+* SearchEngine::transformSearchTerm( $term ) should no longer be called prior
+  to running searchText. This method was mainly implemented to support the
+  'prefix' URI param in SpecialSearch, but there are no reasons to expose this
+  logic as it should be handled internally by SearchEngine implementations
+  supporting this feature. SearchEngine implementations should no longer
+  override this methods.
 
 === Other changes in 1.32 ===
 * (T198811) The following tables have had their UNIQUE indexes turned into
index 3d87a5f..2153fdc 100644 (file)
@@ -66,7 +66,12 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                $search->setFeatureData( 'rewrite', (bool)$params['enablerewrites'] );
                $search->setFeatureData( 'interwiki', (bool)$interwiki );
 
-               $query = $search->transformSearchTerm( $query );
+               $nquery = $search->transformSearchTerm( $query );
+               if ( $nquery !== $query ) {
+                       $query = $nquery;
+                       wfDeprecated( 'SearchEngine::transformSearchTerm() (overridden by ' .
+                               get_class( $search ) . ')', '1.32' );
+               }
                $query = $search->replacePrefixes( $query );
 
                // Perform the actual search
index 63c4610..ea86a4b 100644 (file)
@@ -244,6 +244,8 @@ abstract class SearchEngine {
         * search=test&prefix=Main_Page/Archive -> test prefix:Main Page/Archive
         * @param string $term
         * @return string
+        * @deprecated since 1.32 this should now be handled internally by the
+        * search engine
         */
        public function transformSearchTerm( $term ) {
                return $term;
index 13259c9..15349b8 100644 (file)
@@ -194,6 +194,9 @@ class SpecialSearch extends SpecialPage {
                $request = $this->getRequest();
                list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, '' );
                $this->mPrefix = $request->getVal( 'prefix', '' );
+               if ( $this->mPrefix !== '' ) {
+                       $this->setExtraParam( 'prefix', $this->mPrefix );
+               }
 
                $user = $this->getUser();
 
@@ -300,7 +303,6 @@ class SpecialSearch extends SpecialPage {
                $search->setLimitOffset( $this->limit, $this->offset );
                $search->setNamespaces( $this->namespaces );
                $search->prefix = $this->mPrefix;
-               $term = $search->transformSearchTerm( $term );
 
                Hooks::run( 'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] );
                if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
@@ -312,6 +314,13 @@ class SpecialSearch extends SpecialPage {
                $showSuggestion = $title === null || !$title->isKnown();
                $search->setShowSuggestion( $showSuggestion );
 
+               $nterm = $search->transformSearchTerm( $term );
+               if ( $nterm !== $term ) {
+                       $term = $nterm;
+                       wfDeprecated( 'SearchEngine::transformSearchTerm() (overridden by ' .
+                               get_class( $search ) . ')', '1.32' );
+               }
+
                // fetch search results
                $rewritten = $search->replacePrefixes( $term );
 
@@ -531,6 +540,28 @@ class SpecialSearch extends SpecialPage {
                        );
                }
 
+               if ( $this->mPrefix !== '' ) {
+                       $subtitle = $this->msg( 'search-filter-title-prefix' )->plaintextParams( $this->mPrefix );
+                       $params = $this->powerSearchOptions();
+                       unset( $params['prefix'] );
+                       $params += [
+                               'search' => $term,
+                               'fulltext' => 1,
+                       ];
+
+                       $subtitle .= ' (';
+                       $subtitle .= Xml::element(
+                               'a',
+                               [
+                                       'href' => $this->getPageTitle()->getLocalURL( $params ),
+                                       'title' => $this->msg( 'search-filter-title-prefix-reset' ),
+                               ],
+                               $this->msg( 'search-filter-title-prefix-reset' )
+                       );
+                       $subtitle .= ')';
+                       $out->setSubtitle( $subtitle );
+               }
+
                $out->addJsConfigVars( [ 'searchTerm' => $term ] );
                $out->addModules( 'mediawiki.special.search' );
                $out->addModuleStyles( [
@@ -712,6 +743,18 @@ class SpecialSearch extends SpecialPage {
                $this->extraParams[$key] = $value;
        }
 
+       /**
+        * The prefix value send to Special:Search using the 'prefix' URI param
+        * It means that the user is willing to search for pages whose titles start with
+        * this prefix value.
+        * (Used by the InputBox extension)
+        *
+        * @return string
+        */
+       public function getPrefix() {
+               return $this->mPrefix;
+       }
+
        protected function getGroupName() {
                return 'pages';
        }
index e40ae29..2302177 100644 (file)
@@ -100,6 +100,10 @@ class SearchFormWidget {
 
                $html .= $layout;
 
+               if ( $this->specialSearch->getPrefix() !== '' ) {
+                       $html .= Html::hidden( 'prefix', $this->specialSearch->getPrefix() );
+               }
+
                if ( $totalResults > 0 && $offset < $totalResults ) {
                        $html .= Xml::tags(
                                'div',
index fae5221..bc35c9e 100644 (file)
        "difference-missing-revision": "{{PLURAL:$2|One revision|$2 revisions}} of this difference ($1) {{PLURAL:$2|was|were}} not found.\n\nThis is usually caused by following an outdated diff link to a page that has been deleted.\nDetails can be found in the [{{fullurl:{{#Special:Log}}/delete|page={{FULLPAGENAMEE}}}} deletion log].",
        "search-summary": "",
        "searchresults": "Search results",
+       "search-filter-title-prefix": "Only searching in pages whose title starts with \"$1\"",
+       "search-filter-title-prefix-reset": "Search all pages",
        "searchresults-title": "Search results for \"$1\"",
        "titlematches": "Page title matches",
        "textmatches": "Page text matches",
index 0477512..573c029 100644 (file)
        "difference-missing-revision": "Text displayed when the requested revision does not exist using a diff link.\n\nExample: [{{canonicalurl:Project:News|diff=426850&oldid=99999999}} Diff with invalid revision#]\n\nParameters:\n* $1 - the list of missing revisions IDs\n* $2 - the number of items in $1 (one or two)",
        "search-summary": "{{doc-specialpagesummary|search}}",
        "searchresults": "This is the title of the page that contains the results of a search.\n\n{{Identical|Search results}}",
+       "search-filter-title-prefix": "Subtitle added to indicate that the user is filtering for pages whose title starts with $1, \n* $1 - the title prefix",
+       "search-filter-title-prefix-reset": "Appears next to {{msg-mw|search-filter-title-prefix}} as a link to let users reset the prefix filter",
        "searchresults-title": "Appears as page title in the html header of the search result special page.\n\nParameters:\n* $1 - the search term",
        "titlematches": "Used as section header in [[Special:Search]].\n\nThis message is followed by search results.",
        "textmatches": "When displaying search results",