2013-10-17 17:35:16 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki UserInterface popup tool classes.
|
|
|
|
*
|
2017-01-03 16:58:33 +00:00
|
|
|
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
|
2013-10-17 17:35:16 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-04-30 13:02:36 +00:00
|
|
|
* MediaWiki UserInterface popup tool.
|
2013-10-17 17:35:16 +00:00
|
|
|
*
|
|
|
|
* @class
|
2015-04-30 13:02:36 +00:00
|
|
|
* @abstract
|
2013-10-17 17:35:16 +00:00
|
|
|
* @extends OO.ui.PopupTool
|
|
|
|
* @constructor
|
2015-08-19 18:37:13 +00:00
|
|
|
* @param {string} title Title
|
2015-04-30 13:02:36 +00:00
|
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
|
|
* @param {Object} [config]
|
|
|
|
*/
|
|
|
|
ve.ui.MWPopupTool = function VeUiMWPopupTool( title, toolGroup, config ) {
|
|
|
|
// Configuration initialization
|
|
|
|
config = ve.extendObject( { popup: { head: true, label: title } }, config );
|
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWPopupTool.super.call( this, toolGroup, config );
|
|
|
|
|
|
|
|
this.$element.addClass( 've-ui-mwPopupTool' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWPopupTool, OO.ui.PopupTool );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki UserInterface notices popup tool.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.MWPopupTool
|
|
|
|
* @constructor
|
|
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
|
|
* @param {Object} [config]
|
2013-10-17 17:35:16 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWNoticesPopupTool = function VeUiMWNoticesPopupTool( toolGroup, config ) {
|
2016-11-22 05:42:31 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWNoticesPopupTool.super.call(
|
|
|
|
this,
|
|
|
|
ve.msg( 'visualeditor-editnotices-tooltip' ),
|
|
|
|
toolGroup,
|
|
|
|
config
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWNoticesPopupTool, ve.ui.MWPopupTool );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWNoticesPopupTool.static.name = 'notices';
|
|
|
|
ve.ui.MWNoticesPopupTool.static.group = 'utility';
|
|
|
|
ve.ui.MWNoticesPopupTool.static.icon = 'alert';
|
|
|
|
ve.ui.MWNoticesPopupTool.static.title = OO.ui.deferMsg( 'visualeditor-editnotices-tooltip' );
|
|
|
|
ve.ui.MWNoticesPopupTool.static.autoAddToCatchall = false;
|
|
|
|
ve.ui.MWNoticesPopupTool.static.autoAddToGroup = false;
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2017-03-16 18:16:27 +00:00
|
|
|
* Set notices to display, and either destroy the tool (if none to display) or open the popup.
|
2016-11-22 05:42:31 +00:00
|
|
|
*
|
|
|
|
* @param {string[]} notices
|
|
|
|
*/
|
|
|
|
ve.ui.MWNoticesPopupTool.prototype.setNotices = function ( notices ) {
|
2015-03-30 19:35:38 +00:00
|
|
|
var tool = this,
|
2016-11-22 05:42:31 +00:00
|
|
|
count = notices.length;
|
2013-10-17 17:35:16 +00:00
|
|
|
|
2017-03-16 18:16:27 +00:00
|
|
|
if ( !count ) {
|
|
|
|
this.destroy();
|
2017-03-16 22:34:37 +00:00
|
|
|
return;
|
2017-03-16 18:16:27 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 05:42:31 +00:00
|
|
|
this.popup.setLabel( ve.msg(
|
|
|
|
'visualeditor-editnotices-tool',
|
|
|
|
mw.language.convertNumber( count )
|
|
|
|
) );
|
2013-10-17 17:35:16 +00:00
|
|
|
|
2017-03-16 17:13:36 +00:00
|
|
|
if ( this.$items ) {
|
|
|
|
this.$items.remove();
|
|
|
|
}
|
|
|
|
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$items = $( '<div>' ).addClass( 've-ui-mwNoticesPopupTool-items' );
|
2013-10-17 17:35:16 +00:00
|
|
|
|
2016-11-22 05:42:31 +00:00
|
|
|
notices.forEach( function ( itemHtml ) {
|
2015-04-14 11:22:47 +00:00
|
|
|
var $node = $( '<div>' )
|
2013-10-17 17:35:16 +00:00
|
|
|
.addClass( 've-ui-mwNoticesPopupTool-item' )
|
2015-04-14 11:22:47 +00:00
|
|
|
.append( $.parseHTML( itemHtml ) );
|
2014-03-12 22:09:47 +00:00
|
|
|
|
2017-03-16 18:16:27 +00:00
|
|
|
// Ensure that any links in the notices open in a new tab/window
|
2015-04-14 11:22:47 +00:00
|
|
|
$node.find( 'a' ).attr( 'target', '_blank' );
|
|
|
|
|
|
|
|
tool.$items.append( $node );
|
2015-03-30 19:35:38 +00:00
|
|
|
} );
|
2014-03-12 22:09:47 +00:00
|
|
|
|
2013-10-17 17:35:16 +00:00
|
|
|
this.popup.$body.append( this.$items );
|
|
|
|
|
2017-03-16 18:16:27 +00:00
|
|
|
this.popup.toggle( true );
|
2013-10-17 17:35:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the tool title.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWNoticesPopupTool.prototype.getTitle = function () {
|
2015-03-30 19:35:38 +00:00
|
|
|
var items = this.toolbar.getTarget().getEditNotices();
|
2013-10-17 17:35:16 +00:00
|
|
|
|
2015-03-30 19:35:38 +00:00
|
|
|
return ve.msg( this.constructor.static.title, items.length );
|
2013-10-17 17:35:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.toolFactory.register( ve.ui.MWNoticesPopupTool );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki UserInterface help popup tool.
|
|
|
|
*
|
|
|
|
* @class
|
2015-04-30 13:02:36 +00:00
|
|
|
* @extends ve.ui.MWPopupTool
|
2013-10-17 17:35:16 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWHelpPopupTool = function VeUiMWHelpPopupTool( toolGroup, config ) {
|
|
|
|
// Parent constructor
|
2015-04-30 13:02:36 +00:00
|
|
|
ve.ui.MWHelpPopupTool.super.call( this, ve.msg( 'visualeditor-help-tool' ), toolGroup, config );
|
2013-10-17 17:35:16 +00:00
|
|
|
|
|
|
|
// Properties
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$items = $( '<div>' );
|
2015-02-23 19:37:03 +00:00
|
|
|
this.feedbackPromise = null;
|
2014-01-17 14:24:12 +00:00
|
|
|
this.helpButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
|
|
|
icon: 'help',
|
|
|
|
title: ve.msg( 'visualeditor-help-title' ),
|
|
|
|
href: new mw.Title( ve.msg( 'visualeditor-help-link' ) ).getUrl(),
|
|
|
|
target: '_blank',
|
|
|
|
label: ve.msg( 'visualeditor-help-label' )
|
2013-10-17 17:35:16 +00:00
|
|
|
} );
|
2014-05-11 22:54:58 +00:00
|
|
|
this.keyboardShortcutsButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
2016-03-15 13:01:49 +00:00
|
|
|
icon: 'keyboard',
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-command-help-title' )
|
2014-05-11 22:54:58 +00:00
|
|
|
} );
|
2014-01-17 14:24:12 +00:00
|
|
|
this.feedbackButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
|
|
|
icon: 'comment',
|
|
|
|
label: ve.msg( 'visualeditor-feedback-tool' )
|
2013-10-17 17:35:16 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Events
|
2014-08-22 20:50:48 +00:00
|
|
|
this.feedbackButton.connect( this, { click: 'onFeedbackClick' } );
|
|
|
|
this.keyboardShortcutsButton.connect( this, { click: 'onKeyboardShortcutsClick' } );
|
2013-10-17 17:35:16 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$items
|
|
|
|
.addClass( 've-ui-mwHelpPopupTool-items' )
|
|
|
|
.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<div>' )
|
2013-10-17 17:35:16 +00:00
|
|
|
.addClass( 've-ui-mwHelpPopupTool-item' )
|
2016-03-08 00:59:33 +00:00
|
|
|
.text( ve.msg( 'visualeditor-beta-warning' ) )
|
2013-10-17 17:35:16 +00:00
|
|
|
)
|
|
|
|
.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<div>' )
|
2013-10-17 17:35:16 +00:00
|
|
|
.addClass( 've-ui-mwHelpPopupTool-item' )
|
2013-11-01 19:45:59 +00:00
|
|
|
.append( this.helpButton.$element )
|
2014-05-11 22:54:58 +00:00
|
|
|
.append( this.keyboardShortcutsButton.$element )
|
2013-11-01 19:45:59 +00:00
|
|
|
.append( this.feedbackButton.$element )
|
2013-10-17 17:35:16 +00:00
|
|
|
);
|
|
|
|
this.$items.find( 'a' ).attr( 'target', '_blank' );
|
|
|
|
this.popup.$body.append( this.$items );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-04-30 13:02:36 +00:00
|
|
|
OO.inheritClass( ve.ui.MWHelpPopupTool, ve.ui.MWPopupTool );
|
2013-10-17 17:35:16 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWHelpPopupTool.static.name = 'help';
|
|
|
|
ve.ui.MWHelpPopupTool.static.group = 'utility';
|
|
|
|
ve.ui.MWHelpPopupTool.static.icon = 'help';
|
2014-02-12 21:45:37 +00:00
|
|
|
ve.ui.MWHelpPopupTool.static.title = OO.ui.deferMsg( 'visualeditor-help-tool' );
|
2014-03-21 18:46:02 +00:00
|
|
|
ve.ui.MWHelpPopupTool.static.autoAddToCatchall = false;
|
|
|
|
ve.ui.MWHelpPopupTool.static.autoAddToGroup = false;
|
2013-10-17 17:35:16 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle clicks on the feedback button.
|
|
|
|
*/
|
|
|
|
ve.ui.MWHelpPopupTool.prototype.onFeedbackClick = function () {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.popup.toggle( false );
|
2015-02-23 19:37:03 +00:00
|
|
|
if ( !this.feedbackPromise ) {
|
|
|
|
this.feedbackPromise = mw.loader.using( 'mediawiki.feedback' ).then( function () {
|
2015-12-10 19:34:56 +00:00
|
|
|
var feedbackConfig, veConfig;
|
|
|
|
|
2015-02-23 19:37:03 +00:00
|
|
|
// This can't be constructed until the editor has loaded as it uses special messages
|
2015-12-10 19:34:56 +00:00
|
|
|
feedbackConfig = {
|
2016-02-18 19:24:00 +00:00
|
|
|
bugsLink: new mw.Uri( 'https://phabricator.wikimedia.org/maniphest/task/edit/form/1/?projects=VisualEditor' ),
|
2015-03-03 18:44:11 +00:00
|
|
|
bugsListLink: new mw.Uri( 'https://phabricator.wikimedia.org/maniphest/query/eSHgNozkIsuv/' ),
|
|
|
|
showUseragentCheckbox: true,
|
|
|
|
useragentCheckboxMandatory: true
|
2015-12-10 19:34:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// If so configured, tell mw.feedback that we're posting to a remote wiki and set the title
|
|
|
|
veConfig = mw.config.get( 'wgVisualEditorConfig' );
|
|
|
|
if ( veConfig.feedbackApiUrl ) {
|
|
|
|
feedbackConfig.apiUrl = veConfig.feedbackApiUrl;
|
|
|
|
feedbackConfig.title = new mw.Title( veConfig.feedbackTitle );
|
|
|
|
} else {
|
|
|
|
feedbackConfig.title = new mw.Title( ve.msg( 'visualeditor-feedback-link' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return new mw.Feedback( feedbackConfig );
|
2013-10-17 17:35:16 +00:00
|
|
|
} );
|
|
|
|
}
|
2015-02-23 19:37:03 +00:00
|
|
|
this.feedbackPromise.done( function ( feedback ) {
|
2015-08-17 16:26:12 +00:00
|
|
|
feedback.launch( {
|
|
|
|
message: ve.msg( 'visualeditor-feedback-defaultmessage', location.toString() )
|
|
|
|
} );
|
2015-02-23 19:37:03 +00:00
|
|
|
} );
|
2013-10-17 17:35:16 +00:00
|
|
|
};
|
|
|
|
|
2014-05-11 22:54:58 +00:00
|
|
|
/**
|
|
|
|
* Handle clicks on the keyboard shortcuts button.
|
|
|
|
*/
|
|
|
|
ve.ui.MWHelpPopupTool.prototype.onKeyboardShortcutsClick = function () {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.popup.toggle( false );
|
2016-03-02 15:22:25 +00:00
|
|
|
this.toolbar.getSurface().executeCommand( 'commandHelp' );
|
2014-05-11 22:54:58 +00:00
|
|
|
};
|
|
|
|
|
2015-11-28 05:38:27 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWHelpPopupTool.prototype.onSelect = function () {
|
|
|
|
var $version;
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWHelpPopupTool.super.prototype.onSelect.apply( this, arguments );
|
|
|
|
|
|
|
|
if ( !this.versionPromise && this.popup.isVisible() ) {
|
|
|
|
$version = $( '<div>' ).addClass( 've-ui-mwHelpPopupTool-item oo-ui-pendingElement-pending' ).text( '\u00a0' );
|
|
|
|
this.$items.append( $version );
|
|
|
|
this.versionPromise = new mw.Api().get( {
|
|
|
|
action: 'query',
|
|
|
|
meta: 'siteinfo',
|
|
|
|
format: 'json',
|
|
|
|
siprop: 'extensions'
|
|
|
|
} )
|
|
|
|
.then( function ( response ) {
|
|
|
|
var extension = response.query.extensions.filter( function ( ext ) {
|
|
|
|
return ext.name === 'VisualEditor';
|
|
|
|
} )[ 0 ];
|
|
|
|
|
|
|
|
if ( extension && extension[ 'vcs-version' ] ) {
|
|
|
|
$version
|
|
|
|
.removeClass( 'oo-ui-pendingElement-pending' )
|
|
|
|
.empty()
|
|
|
|
.append( $( '<span>' )
|
|
|
|
.addClass( 've-ui-mwHelpPopupTool-version-label' )
|
|
|
|
.text( ve.msg( 'visualeditor-version-label' ) )
|
|
|
|
)
|
|
|
|
.append( ' ' )
|
|
|
|
.append( $( '<a>' )
|
|
|
|
.addClass( 've-ui-mwHelpPopupTool-version-link' )
|
|
|
|
.attr( 'target', '_blank' )
|
2016-10-28 00:22:30 +00:00
|
|
|
.attr( 'href', extension[ 'vcs-url' ] )
|
2015-11-28 05:38:27 +00:00
|
|
|
.text( extension[ 'vcs-version' ].slice( 0, 7 ) )
|
|
|
|
)
|
|
|
|
.append( ' ' )
|
|
|
|
.append( $( '<span>' )
|
|
|
|
.addClass( 've-ui-mwHelpPopupTool-version-date' )
|
|
|
|
.text( extension[ 'vcs-date' ] )
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$version.remove();
|
|
|
|
}
|
|
|
|
}, function () {
|
|
|
|
$version.remove();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-17 17:35:16 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.toolFactory.register( ve.ui.MWHelpPopupTool );
|