mw.widgets.TitleWidget: Add 'excludeDynamicNamespaces' config
authorMoriel Schottlender <moriel@gmail.com>
Wed, 13 Feb 2019 21:52:45 +0000 (13:52 -0800)
committerMoriel Schottlender <moriel@gmail.com>
Fri, 15 Feb 2019 01:26:03 +0000 (17:26 -0800)
Allow excluding all pages that are in dynamic (negative) namespaces.

Bug: T208355
Change-Id: I9b39f66ac828bc0c100a2fc347b365f75672efb1

includes/htmlform/fields/HTMLTitlesMultiselectField.php
includes/widget/TitlesMultiselectWidget.php
resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js

index 7b099ca..1cfbd5f 100644 (file)
@@ -102,6 +102,9 @@ class HTMLTitlesMultiselectField extends HTMLTitleTextField {
                if ( isset( $this->mParams['showMissing'] ) ) {
                        $params['showMissing'] = $this->mParams['showMissing'];
                }
+               if ( isset( $this->mParams['excludeDynamicNamespaces'] ) ) {
+                       $params['excludeDynamicNamespaces'] = $this->mParams['excludeDynamicNamespaces'];
+               }
 
                if ( isset( $this->mParams['input'] ) ) {
                        $params['input'] = $this->mParams['input'];
index 3246e7d..ac34259 100644 (file)
@@ -11,10 +11,12 @@ namespace MediaWiki\Widget;
 class TitlesMultiselectWidget extends TagMultiselectWidget {
 
        protected $showMissing = null;
+       protected $excludeDynamicNamespaces = null;
 
        /**
         * @param array $config Configuration options
         *   - bool $config['showMissing'] Show missing pages
+        *   - bool $config['excludeDynamicNamespaces'] Exclude pages in negative namespaces
         */
        public function __construct( array $config = [] ) {
                parent::__construct( $config );
@@ -23,6 +25,9 @@ class TitlesMultiselectWidget extends TagMultiselectWidget {
                if ( isset( $config['showMissing'] ) ) {
                        $this->showMissing = $config['showMissing'];
                }
+               if ( isset( $config['excludeDynamicNamespaces'] ) ) {
+                       $this->excludeDynamicNamespaces = $config['excludeDynamicNamespaces'];
+               }
 
                $this->addClasses( [ 'mw-widgets-titlesMultiselectWidget' ] );
        }
@@ -35,6 +40,9 @@ class TitlesMultiselectWidget extends TagMultiselectWidget {
                if ( $this->showMissing !== null ) {
                        $config['showMissing'] = $this->showMissing;
                }
+               if ( $this->excludeDynamicNamespaces !== null ) {
+                       $config['excludeDynamicNamespaces'] = $this->excludeDynamicNamespaces;
+               }
 
                return parent::getConfig( $config );
        }
index cb1281d..6f4c72c 100644 (file)
@@ -26,6 +26,7 @@
         * @cfg {boolean} [showMissing=true] Show missing pages
         * @cfg {boolean} [addQueryInput=true] Add exact user's input query to results
         * @cfg {boolean} [excludeCurrentPage] Exclude the current page from suggestions
+        * @cfg {boolean} [excludeDynamicNamespaces] Exclude pages whose namespace is negative
         * @cfg {boolean} [validateTitle=true] Whether the input must be a valid title
         * @cfg {boolean} [required=false] Whether the input must not be empty
         * @cfg {boolean} [highlightSearchQuery=true] Highlight the partial query the user used for this title
@@ -51,6 +52,7 @@
                this.showMissing = config.showMissing !== false;
                this.addQueryInput = config.addQueryInput !== false;
                this.excludeCurrentPage = !!config.excludeCurrentPage;
+               this.excludeDynamicNamespaces = !!config.excludeDynamicNamespaces;
                this.validateTitle = config.validateTitle !== undefined ? config.validateTitle : true;
                this.highlightSearchQuery = config.highlightSearchQuery === undefined ? true : !!config.highlightSearchQuery;
                this.cache = config.cache;
                        if ( this.excludeCurrentPage && suggestionPage.title === currentPageName && suggestionPage.title !== titleObj.getPrefixedText() ) {
                                continue;
                        }
+
+                       // When excludeDynamicNamespaces is set, ignore all pages with negative namespace
+                       if ( this.excludeDynamicNamespaces && suggestionPage.ns < 0 ) {
+                               continue;
+                       }
                        pageData[ suggestionPage.title ] = {
                                known: suggestionPage.known !== undefined,
                                missing: suggestionPage.missing !== undefined,