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

Change subject: Pass User to SearchEngine::getProfiles
......................................................................


Pass User to SearchEngine::getProfiles

Useful for search engines that allow users to customize search profiles.

Depends-On: Icd577c8ebc6e162befe30bde4fe276e633d2e434
Change-Id: I471cd090730d2a25cb70d622ec3bebbe9583118c
---
M includes/api/SearchApi.php
M includes/search/SearchEngine.php
M tests/phpunit/includes/api/ApiOpenSearchTest.php
3 files changed, 12 insertions(+), 5 deletions(-)

Approvals:
  EBernhardson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/api/SearchApi.php b/includes/api/SearchApi.php
index 8ae1192..fb9c4e6 100644
--- a/includes/api/SearchApi.php
+++ b/includes/api/SearchApi.php
@@ -104,7 +104,8 @@
                $searchEngine = 
MediaWikiServices::getInstance()->newSearchEngine();
                $params = [];
                foreach ( $configs as $paramName => $paramConfig ) {
-                       $profiles = $searchEngine->getProfiles( 
$paramConfig['profile-type'] );
+                       $profiles = $searchEngine->getProfiles( 
$paramConfig['profile-type'],
+                               $this->getContext()->getUser() );
                        if ( !$profiles ) {
                                continue;
                        }
@@ -188,4 +189,9 @@
         *  containing 'help-message' and 'profile-type' keys.
         */
        abstract public function getSearchProfileParams();
+
+       /**
+        * @return IContextSource
+        */
+       abstract public function getContext();
 }
diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php
index 1eba141..da93a07 100644
--- a/includes/search/SearchEngine.php
+++ b/includes/search/SearchEngine.php
@@ -648,10 +648,11 @@
         * - default: set to true if this profile is the default
         *
         * @since 1.28
-        * @param $profileType the type of profiles
+        * @param string $profileType the type of profiles
+        * @param User|null $user the user requesting the list of profiles
         * @return array|null the list of profiles or null if none available
         */
-       public function getProfiles( $profileType ) {
+       public function getProfiles( $profileType, User $user = null ) {
                return null;
        }
 
diff --git a/tests/phpunit/includes/api/ApiOpenSearchTest.php 
b/tests/phpunit/includes/api/ApiOpenSearchTest.php
index 39e90c2..5358f29 100644
--- a/tests/phpunit/includes/api/ApiOpenSearchTest.php
+++ b/tests/phpunit/includes/api/ApiOpenSearchTest.php
@@ -9,11 +9,12 @@
                        ->method( 'getSearchTypes' )
                        ->will( $this->returnValue( [ 'the one ring' ] ) );
 
+               $api = $this->createApi();
                $engine = $this->replaceSearchEngine();
                $engine->expects( $this->any() )
                        ->method( 'getProfiles' )
                        ->will( $this->returnValueMap( [
-                               [ SearchEngine::COMPLETION_PROFILE_TYPE, [
+                               [ SearchEngine::COMPLETION_PROFILE_TYPE, 
$api->getUser(), [
                                        [
                                                'name' => 'normal',
                                                'desc-message' => 
'normal-message',
@@ -26,7 +27,6 @@
                                ] ],
                        ] ) );
 
-               $api = $this->createApi();
                $params = $api->getAllowedParams();
 
                $this->assertArrayNotHasKey( 'offset', $params );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I471cd090730d2a25cb70d622ec3bebbe9583118c
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: DCausse <dcau...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: EBernhardson <ebernhard...@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