bug 33583 search ns user pref ignored!
authorAntoine Musso <hashar@users.mediawiki.org>
Thu, 12 Jan 2012 09:03:38 +0000 (09:03 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Thu, 12 Jan 2012 09:03:38 +0000 (09:03 +0000)
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

includes/specials/SpecialSearch.php
tests/phpunit/includes/specials/SpecialSearchTest.php

index 927464f..3fa8687 100644 (file)
@@ -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 {
index b1c06cd..eb60cf2 100644 (file)
@@ -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'
+                       ),
                );
        }