mediawiki-extensions-WikiEd.../modules/insertlink/TitleOptionWidget.js
Sam Wilson 6384498d75 Switch to OOUI TitleInputWidget for the link-inserter
In order to get a better look-up experience (images, description,
redirects, and disambigutation pages listed last), swich from
a custom title-autocomplete input (that used jquery.suggestions)
to OOUI's standard one (which is used in a bunch of other places
in MediaWiki).

This means a fair bit of code can be deleted from
jquery.wikiEditor.dialogs.config.js, and some of it moved to
the new OOUI classes.

This patch aims to be the minimum required, and so leaves a few
things for subsequent patches (such as converting the other parts
of the insert-link dialog to OOUI).

Bug: T289214
Change-Id: I9fb7e66bf925eb9a8260d6245d2a7db54a7a2fec
2021-10-08 12:43:55 +00:00

54 lines
1.6 KiB
JavaScript

/**
* A custom TitleOptionWidget that knows about external links.
*
* @class
* @extends mw.widgets.TitleOptionWidget
* @constructor
* @param {Object} config Configuration options.
* @cfg {boolean} [external] Page title is an external link.
*/
function InsertLinkTitleOptionWidget( config ) {
this.external = config.external || false;
if ( this.external ) {
config.icon = 'linkExternal';
config.description = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-external' );
// Lowercase the first character; it was uppercased by the API.
config.url = config.data.substr( 0, 1 ).toLowerCase() + config.data.substr( 1 );
config.data = config.url;
// Prepend http:// if there is no protocol (i.e. if it starts with "www.").
// @TODO This is repeated when the link is inserted (in jquery.wikiEditor.dialogs.config.js).
if ( !config.url.match( /^[a-z]+:\/\/./ ) ) {
config.url = 'http://' + config.url;
}
config.missing = false;
}
this.disambiguation = config.disambiguation || false;
this.missing = config.missing || false;
InsertLinkTitleOptionWidget.super.call( this, config );
}
OO.inheritClass( InsertLinkTitleOptionWidget, mw.widgets.TitleOptionWidget );
/**
* @return {boolean}
*/
InsertLinkTitleOptionWidget.prototype.isExternal = function () {
return this.external;
};
/**
* @return {boolean}
*/
InsertLinkTitleOptionWidget.prototype.isMissing = function () {
return this.missing;
};
/**
* @return {boolean}
*/
InsertLinkTitleOptionWidget.prototype.isDisambiguation = function () {
return this.disambiguation;
};
module.exports = InsertLinkTitleOptionWidget;