2013-10-17 17:35:16 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki UserInterface popup tool classes.
|
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 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 ) {
|
2015-03-30 19:35:38 +00:00
|
|
|
var tool = this,
|
2013-10-17 17:35:16 +00:00
|
|
|
items = toolGroup.getToolbar().getTarget().getEditNotices(),
|
2015-03-30 19:35:38 +00:00
|
|
|
count = items.length,
|
2013-10-17 17:35:16 +00:00
|
|
|
title = ve.msg( 'visualeditor-editnotices-tool', count );
|
|
|
|
|
|
|
|
// Parent constructor
|
2015-04-30 13:02:36 +00:00
|
|
|
ve.ui.MWNoticesPopupTool.super.call( this, title, toolGroup, config );
|
2013-10-17 17:35:16 +00:00
|
|
|
|
|
|
|
// Properties
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$items = $( '<div>' ).addClass( 've-ui-mwNoticesPopupTool-items' );
|
2013-10-17 17:35:16 +00:00
|
|
|
|
|
|
|
// Initialization
|
2015-04-14 11:22:47 +00:00
|
|
|
items.forEach( function ( itemHtml ) {
|
|
|
|
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
|
|
|
|
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 );
|
|
|
|
|
2015-01-16 07:21:15 +00:00
|
|
|
if ( !count ) {
|
2014-11-25 14:17:53 +00:00
|
|
|
this.$element = $( [] );
|
2013-10-17 17:35:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-04-30 13:02:36 +00:00
|
|
|
OO.inheritClass( ve.ui.MWNoticesPopupTool, ve.ui.MWPopupTool );
|
2013-10-17 17:35:16 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWNoticesPopupTool.static.name = 'notices';
|
|
|
|
ve.ui.MWNoticesPopupTool.static.group = 'utility';
|
|
|
|
ve.ui.MWNoticesPopupTool.static.icon = 'alert';
|
2014-02-26 23:51:54 +00:00
|
|
|
ve.ui.MWNoticesPopupTool.static.title = OO.ui.deferMsg( 'visualeditor-editnotices-tooltip' );
|
2014-03-21 18:46:02 +00:00
|
|
|
ve.ui.MWNoticesPopupTool.static.autoAddToCatchall = false;
|
|
|
|
ve.ui.MWNoticesPopupTool.static.autoAddToGroup = false;
|
2013-10-17 17:35:16 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
icon: 'help',
|
|
|
|
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' )
|
2015-06-29 21:11:39 +00:00
|
|
|
.text( ve.msg( 'visualeditor-beta-warning', $( '#ca-edit' ).text() ) )
|
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 () {
|
|
|
|
// This can't be constructed until the editor has loaded as it uses special messages
|
|
|
|
return new mw.Feedback( {
|
|
|
|
title: new mw.Title( ve.msg( 'visualeditor-feedback-link' ) ),
|
|
|
|
bugsLink: new mw.Uri( 'https://phabricator.wikimedia.org/maniphest/task/create/?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-02-23 19:37:03 +00:00
|
|
|
} );
|
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 );
|
2015-07-31 15:24:51 +00:00
|
|
|
ve.init.target.commandRegistry.lookup( 'commandHelp' ).execute( this.toolbar.getSurface() );
|
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' )
|
|
|
|
.attr( 'href', extension[ 'vcs-url' ] )
|
|
|
|
.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 );
|