2021-09-01 07:17:53 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2022-02-07 17:26:29 +00:00
|
|
|
config.url = config.data.slice( 0, 1 ).toLowerCase() + config.data.slice( 1 );
|
2021-09-01 07:17:53 +00:00
|
|
|
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).
|
2022-03-03 21:01:50 +00:00
|
|
|
if ( !/^[a-z]+:\/\/./.test( config.url ) ) {
|
2021-09-01 07:17:53 +00:00
|
|
|
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;
|