Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/222739
Change subject: TitleInputWidget: Add 'relative' option
......................................................................
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
---
M includes/widget/TitleInputWidget.php
M resources/src/mediawiki.widgets/mw.widgets.TitleInputWidget.js
2 files changed, 16 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/39/222739/1
diff --git a/includes/widget/TitleInputWidget.php
b/includes/widget/TitleInputWidget.php
index 173dbb0..7ddc67a 100644
--- a/includes/widget/TitleInputWidget.php
+++ b/includes/widget/TitleInputWidget.php
@@ -15,19 +15,24 @@
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
@@ -38,6 +43,9 @@
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 221de0f..0b1c768 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] If a namespace is set, return a title
relative to it (default; true)
* @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,
--
To view, visit https://gerrit.wikimedia.org/r/222739
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I605df2ca41831cae1c8f0a3331600d4487e7798f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits