From: Antoine Musso Date: Thu, 12 Jan 2012 09:03:38 +0000 (+0000) Subject: bug 33583 search ns user pref ignored! X-Git-Tag: 1.31.0-rc.0~25338 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=ca27814f63df59050027695c4b6781ead03f790f;p=lhc%2Fweb%2Fwiklou.git bug 33583 search ns user pref ignored! r106780 to fix bug 33270 introduced a new bug that prevented selected namespaces for search to be applied. This patch fix the issue. Credits to Brad Jorsch --- diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 927464fbb1..3fa86875d6 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -110,6 +110,8 @@ class SpecialSearch extends SpecialPage { /** * Set up basic search parameters from the request and user settings. + * + * @see tests/phpunit/includes/specials/SpecialSearchTest.php */ public function load() { $request = $this->getRequest(); @@ -117,27 +119,30 @@ class SpecialSearch extends SpecialPage { $this->mPrefix = $request->getVal( 'prefix', '' ); $user = $this->getUser(); + # Extract manually requested namespaces $nslist = $this->powerSearch( $request ); + if ( !count( $nslist ) ) { + # Fallback to user preference + $nslist = SearchEngine::userNamespaces( $user ); + } + $profile = null; if ( !count( $nslist ) ) { $profile = 'default'; } + $profile = $request->getVal( 'profile', $profile ); $profiles = $this->getSearchProfiles(); if ( $profile === null ) { // BC with old request format $profile = 'advanced'; - if ( count( $nslist ) ) { - foreach( $profiles as $key => $data ) { - if ( $nslist === $data['namespaces'] && $key !== 'advanced') { - $profile = $key; - } + foreach( $profiles as $key => $data ) { + if ( $nslist === $data['namespaces'] && $key !== 'advanced') { + $profile = $key; } - $this->namespaces = $nslist; - } else { - $this->namespaces = SearchEngine::userNamespaces( $user ); } + $this->namespaces = $nslist; } elseif ( $profile === 'advanced' ) { $this->namespaces = $nslist; } else { diff --git a/tests/phpunit/includes/specials/SpecialSearchTest.php b/tests/phpunit/includes/specials/SpecialSearchTest.php index b1c06cdf6d..eb60cf2048 100644 --- a/tests/phpunit/includes/specials/SpecialSearchTest.php +++ b/tests/phpunit/includes/specials/SpecialSearchTest.php @@ -14,11 +14,12 @@ class SpecialSearchTest extends MediaWikiTestCase { function tearDown() { } /** + * @covers SpecialSearch::load * @dataProvider provideSearchOptionsTests * @param $requested Array Request parameters. For example array( 'ns5' => true, 'ns6' => true). NULL to use default options. * @param $userOptions Array User options to test with. For example array('searchNs5' => 1 );. NULL to use default options. */ - function testFoobar( + function testProfileAndNamespaceLoading( $requested, $userOptions, $expectedProfile, $expectedNS, $message = 'Profile name andnamespaces mismatches!' ) { @@ -79,14 +80,11 @@ class SpecialSearchTest extends MediaWikiTestCase { 'advanced', array( 5), 'Web request with specific NS should override user preference' ), - /* FIXME this test is for bug 33583 - array( - $EMPTY_REQUEST, array( 'searchNs2' ), - 'advanced', array( 2 ), - 'Bug 33583: search with no option should honor User search preferences' - ), - */ - + array( + $EMPTY_REQUEST, array( 'searchNs2' => 1, 'searchNs14' => 1 ), + 'advanced', array( 2, 14 ), + 'Bug 33583: search with no option should honor User search preferences' + ), ); }