mediawiki.searchSuggest: Add support for search namespace preferences
authorPaladox <thomasmulhall410@yahoo.com>
Sun, 15 Jan 2017 18:18:29 +0000 (18:18 +0000)
committerKrinkle <krinklemail@gmail.com>
Tue, 3 Oct 2017 17:56:36 +0000 (17:56 +0000)
This way it allows namespaces other then NS_MAIN.

Bug: T26214
Change-Id: I6a545eb8563e81a66de39a8295ef2e40c3e73f95

resources/src/mediawiki/mediawiki.searchSuggest.js

index 1c1150e..e7859cf 100644 (file)
@@ -2,6 +2,12 @@
  * Add search suggestions to the search form.
  */
 ( function ( mw, $ ) {
+       var searchNS = $.map( mw.config.get( 'wgFormattedNamespaces' ), function ( nsName, nsID ) {
+               if ( nsID >= 0 && mw.user.options.get( 'searchNs' + nsID ) ) {
+                       // Cast string key to number
+                       return Number( nsID );
+               }
+       } );
        mw.searchSuggest = {
                // queries the wiki and calls response with the result
                request: function ( api, query, response, maxRows, namespace ) {
@@ -9,7 +15,7 @@
                                formatversion: 2,
                                action: 'opensearch',
                                search: query,
-                               namespace: namespace || 0,
+                               namespace: namespace || searchNS,
                                limit: maxRows,
                                suggest: true
                        } ).done( function ( data, jqXHR ) {