mw.widgets.TitleWidget: Add 'excludeDynamicNamespaces' config

Allow excluding all pages that are in dynamic (negative) namespaces.

Bug: T208355
Change-Id: I9b39f66ac828bc0c100a2fc347b365f75672efb1
This commit is contained in:
Moriel Schottlender 2019-02-13 13:52:45 -08:00
parent ff75ea4f05
commit a7fd92a95e
3 changed files with 18 additions and 0 deletions

View 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'];

View 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 );
}

View 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;
@ -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,