From: Kunal Mehta Date: Sat, 4 Jul 2015 07:39:41 +0000 (-0700) Subject: TitleInputWidget: Add 'relative' option X-Git-Tag: 1.31.0-rc.0~10872^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=ddca1c657e21bd49c01ead2e5e0fbcdb9ee26255;p=lhc%2Fweb%2Fwiklou.git TitleInputWidget: Add 'relative' option Currently the JavaScript widget will return a value that is relative to the namespace, so for "Category:Foo", it will return "Foo". This is problematic for server-side forms that want a full title returned, so make this configurable. Change-Id: I605df2ca41831cae1c8f0a3331600d4487e7798f --- diff --git a/includes/widget/TitleInputWidget.php b/includes/widget/TitleInputWidget.php index 173dbb07c9..7ddc67ac45 100644 --- a/includes/widget/TitleInputWidget.php +++ b/includes/widget/TitleInputWidget.php @@ -15,21 +15,26 @@ use OOUI\TextInputWidget; class TitleInputWidget extends TextInputWidget { protected $namespace = null; + protected $relative = null; /** * @param array $config Configuration options - * @param number|null $config['namespace'] Namespace to prepend to queries + * @param int|null $config['namespace'] Namespace to prepend to queries + * @param bool|null $config['relative'] If a namespace is set, return a title relative to it (default; true) */ public function __construct( array $config = array() ) { // Parent constructor parent::__construct( array_merge( $config, array( 'infusable' => true ) ) ); - // Properties + // Properties, which are ignored in PHP and just shipped back to JS if ( isset( $config['namespace'] ) ) { - // Actually ignored in PHP, we just ship it back to JS $this->namespace = $config['namespace']; } + if ( isset( $config['relative'] ) ) { + $this->relative = $config['relative']; + } + // Initialization $this->addClasses( array( 'mw-widget-TitleInputWidget' ) ); } @@ -38,6 +43,9 @@ class TitleInputWidget extends TextInputWidget { if ( $this->namespace !== null ) { $config['namespace'] = $this->namespace; } + if ( $this->relative !== null ) { + $config['relative'] = $this->relative; + } return parent::getConfig( $config ); } } diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleInputWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleInputWidget.js index 221de0f0a2..df2f1a7dee 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.TitleInputWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleInputWidget.js @@ -16,6 +16,7 @@ * @param {Object} [config] Configuration options * @cfg {number} [limit=10] Number of results to show * @cfg {number} [namespace] Namespace to prepend to queries + * @cfg {boolean} [relative=true] If a namespace is set, return a title relative to it * @cfg {boolean} [showRedirectTargets=true] Show the targets of redirects * @cfg {boolean} [showRedlink] Show red link to exact match if it doesn't exist * @cfg {boolean} [showImages] Show page images @@ -37,6 +38,7 @@ // Properties this.limit = config.limit || 10; this.namespace = config.namespace || null; + this.relative = config.relative !== undefined ? config.relative : true; this.showRedirectTargets = config.showRedirectTargets !== false; this.showRedlink = !!config.showRedlink; this.showImages = !!config.showImages; @@ -258,7 +260,9 @@ mw.widgets.TitleInputWidget.prototype.getOptionWidgetData = function ( title, data ) { var mwTitle = new mw.Title( title ); return { - data: this.namespace !== null ? mwTitle.getRelativeText( this.namespace ) : title, + data: this.namespace !== null && this.relative + ? mwTitle.getRelativeText( this.namespace ) + : title, imageUrl: this.showImages ? data.imageUrl : null, description: this.showDescriptions ? data.description : null, missing: data.missing,