From: Moriel Schottlender Date: Wed, 13 Feb 2019 21:52:45 +0000 (-0800) Subject: mw.widgets.TitleWidget: Add 'excludeDynamicNamespaces' config X-Git-Tag: 1.34.0-rc.0~2763^2 X-Git-Url: https://git.cyclocoop.org/admin/Duna?a=commitdiff_plain;h=a7fd92a95e2ee3bee58b46e77a0699b8bedb98de;p=lhc%2Fweb%2Fwiklou.git mw.widgets.TitleWidget: Add 'excludeDynamicNamespaces' config Allow excluding all pages that are in dynamic (negative) namespaces. Bug: T208355 Change-Id: I9b39f66ac828bc0c100a2fc347b365f75672efb1 --- diff --git a/includes/htmlform/fields/HTMLTitlesMultiselectField.php b/includes/htmlform/fields/HTMLTitlesMultiselectField.php index 7b099ca0d0..1cfbd5fef7 100644 --- a/includes/htmlform/fields/HTMLTitlesMultiselectField.php +++ b/includes/htmlform/fields/HTMLTitlesMultiselectField.php @@ -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']; diff --git a/includes/widget/TitlesMultiselectWidget.php b/includes/widget/TitlesMultiselectWidget.php index 3246e7d891..ac342596a8 100644 --- a/includes/widget/TitlesMultiselectWidget.php +++ b/includes/widget/TitlesMultiselectWidget.php @@ -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 ); } diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js index cb1281d42c..6f4c72c501 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js @@ -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; @@ -238,6 +240,11 @@ 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,