From: David Causse Date: Mon, 25 Jun 2018 17:19:32 +0000 (+0200) Subject: Deprecate usage of SearchEngine:transformSearchTerm X-Git-Tag: 1.34.0-rc.0~4738 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=46c17ddb1ff10a1e073742c9d8b831cd915802f3;p=lhc%2Fweb%2Fwiklou.git Deprecate usage of SearchEngine:transformSearchTerm 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 --- diff --git a/RELEASE-NOTES-1.32 b/RELEASE-NOTES-1.32 index 1dbc787ff4..4f1cd798c6 100644 --- a/RELEASE-NOTES-1.32 +++ b/RELEASE-NOTES-1.32 @@ -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 diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 3d87a5f06a..2153fdc75c 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -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 diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 63c46108b2..ea86a4b580 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -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; diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 13259c9b3a..15349b8a41 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -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'; } diff --git a/includes/widget/search/SearchFormWidget.php b/includes/widget/search/SearchFormWidget.php index e40ae2909a..2302177f28 100644 --- a/includes/widget/search/SearchFormWidget.php +++ b/includes/widget/search/SearchFormWidget.php @@ -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', diff --git a/languages/i18n/en.json b/languages/i18n/en.json index fae5221720..bc35c9e02c 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -964,6 +964,8 @@ "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", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 0477512deb..573c0290fd 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1164,6 +1164,8 @@ "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",