Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/213503

Change subject: [WIP] Move MWTitleInputWidget into core
......................................................................

[WIP] Move MWTitleInputWidget into core

Imported from VisualEditor. Renamed from ve.ui.MWTitleInputWidget
to OO.ui.MWTitleInputWidget.

Change-Id: Idd344a35feccdc72693a6b1a575a0c567998741f
---
M .jshintrc
M resources/Resources.php
A resources/src/oojs-ui/OO.ui.MWTitleInputWidget.css
A resources/src/oojs-ui/OO.ui.MWTitleInputWidget.js
4 files changed, 140 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/03/213503/1

diff --git a/.jshintrc b/.jshintrc
index 4bb2440..64be746 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -23,6 +23,7 @@
                "JSON": true,
                "jQuery": false,
                "QUnit": false,
-               "sinon": false
+               "sinon": false,
+               "OO": false
        }
 }
diff --git a/resources/Resources.php b/resources/Resources.php
index 71a8f29..a2ba37e 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -1883,4 +1883,11 @@
                'selectorWithVariant' => '.oo-ui-image-{variant} 
.oo-ui-icon-{name}, .oo-ui-image-{variant}.oo-ui-icon-{name}, 
.mw-ui-icon-{name}-{variant}:after, .mw-ui-icon-{name}-{variant}:before, 
.mw-ui-hovericon:hover .mw-ui-icon-{name}-{variant}-hover:before, 
.mw-ui-hovericon.mw-ui-icon-{name}-{variant}-hover:hover:before',
        ),
 
+       'oojs-ui.MWTitleInputWidget' => array(
+               'scripts' => 
'resources/src/oojs-ui/OO.ui.MWTitleInputWidget.js',
+               'styles' => 
'resources/src/oojs-ui/OO.ui.MWTitleInputWidget.css',
+               'dependencies' => 'oojs-ui',
+               'targets' => array( 'desktop', 'mobile' ),
+       ),
+
 );
diff --git a/resources/src/oojs-ui/OO.ui.MWTitleInputWidget.css 
b/resources/src/oojs-ui/OO.ui.MWTitleInputWidget.css
new file mode 100644
index 0000000..05dd29d
--- /dev/null
+++ b/resources/src/oojs-ui/OO.ui.MWTitleInputWidget.css
@@ -0,0 +1,3 @@
+.oo-ui-mwTitleInputWidget {
+       width:30em;
+}
diff --git a/resources/src/oojs-ui/OO.ui.MWTitleInputWidget.js 
b/resources/src/oojs-ui/OO.ui.MWTitleInputWidget.js
new file mode 100644
index 0000000..8a0fd62
--- /dev/null
+++ b/resources/src/oojs-ui/OO.ui.MWTitleInputWidget.js
@@ -0,0 +1,128 @@
+( function ( $, mw ) {
+
+/**
+ * Creates an OO.ui.MWTitleInputWidget object.
+ *
+ * @class
+ * @extends OO.ui.TextInputWidget
+ * @mixins OO.ui.LookupElement
+ *
+ * @constructor
+ * @param {Object} [config] Configuration options
+ * @cfg {number} [namespace] Namespace to prepend to queries
+ */
+OO.ui.MWTitleInputWidget = function OoUiMWTitleInputWidget( config ) {
+       // Config initialization
+       config = config || {};
+
+       // Parent constructor
+       OO.ui.TextInputWidget.call( this, config );
+
+       // Mixin constructors
+       OO.ui.LookupElement.call( this, config );
+
+       // Properties
+       this.namespace = config.namespace || null;
+
+       // Initialization
+       this.$element.addClass( 'oo-ui-mwTitleInputWidget' );
+       this.lookupMenu.$element.addClass( 'oo-ui-mwTitleInputWidget-menu' );
+};
+
+/* Inheritance */
+
+OO.inheritClass( OO.ui.MWTitleInputWidget, OO.ui.TextInputWidget );
+
+OO.mixinClass( OO.ui.MWTitleInputWidget, OO.ui.LookupElement );
+
+/* Methods */
+
+/**
+ * @inheritdoc
+ */
+OO.ui.MWTitleInputWidget.prototype.onLookupMenuItemChoose = function ( item ) {
+       this.closeLookupMenu();
+       this.setLookupsDisabled( true );
+       this.setValue( item.getData() );
+       this.setLookupsDisabled( false );
+};
+
+/**
+ * @inheritdoc
+ */
+OO.ui.MWTitleInputWidget.prototype.getLookupRequest = function () {
+       var value = this.value;
+
+       // Prefix with default namespace name
+       if ( this.namespace !== null && mw.Title.newFromText( value, 
this.namespace ) ) {
+               value = mw.Title.newFromText( value, this.namespace 
).getPrefixedText();
+       }
+
+       // Dont send leading ':' to open search
+       if ( value.charAt( 0 ) === ':' ) {
+               value = value.slice( 1 );
+       }
+
+       return new mw.Api().get( {
+               action: 'opensearch',
+               search: value,
+               suggest: ''
+       } );
+};
+
+/**
+ * @inheritdoc
+ */
+OO.ui.MWTitleInputWidget.prototype.getLookupCacheDataFromResponse = function ( 
data ) {
+       return data[1] || [];
+};
+
+/**
+ * @inheritdoc
+ */
+OO.ui.MWTitleInputWidget.prototype.getLookupMenuOptionsFromData = function ( 
data ) {
+       var i, len, title, value,
+               items = [],
+               matchingPages = data,
+               linkCacheUpdate = {};
+
+       // Matching pages
+       if ( matchingPages && matchingPages.length ) {
+               for ( i = 0, len = matchingPages.length; i < len; i++ ) {
+                       title = new mw.Title( matchingPages[i] );
+                       if ( this.namespace !== null ) {
+                               value = title.getRelativeText( this.namespace );
+                       } else {
+                               value = title.getPrefixedText();
+                       }
+                       items.push( new OO.ui.MenuOptionWidget( {
+                               data: value,
+                               label: value
+                       } ) );
+               }
+       }
+
+       return items;
+};
+
+/**
+ * Get title object corresponding to #getValue
+ *
+ * @returns {mw.Title|null} Title object, or null if value is invalid
+ */
+OO.ui.MWTitleInputWidget.prototype.getTitle = function () {
+       var title = this.getValue(),
+               // mw.Title doesn't handle null well
+               titleObj = mw.Title.newFromText( title, this.namespace !== null 
? this.namespace : undefined );
+
+       return titleObj;
+};
+
+/**
+ * @inheritdoc
+ */
+OO.ui.MWTitleInputWidget.prototype.isValid = function () {
+       return $.Deferred().resolve( !!this.getTitle() ).promise();
+};
+
+}( jQuery, mediaWiki ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/213503
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd344a35feccdc72693a6b1a575a0c567998741f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Catrope <roan.katt...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to