1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/*!
* VisualEditor MediaWiki UserInterface help list toolgroup classes.
*
* @copyright See AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* MediaWiki UserInterface edit mode tool.
*
* This extends ListToolGroup to add a footer below the tool list.
* The footer contains the version number.
*
* @class
* @extends OO.ui.ListToolGroup
*
* @constructor
* @param {OO.ui.Toolbar} toolbar
* @param {Object} [config] Configuration options
*/
ve.ui.MWHelpListToolGroup = function VeUiMwHelpListToolGroup() {
this.$footer = $( '<div>' ).addClass( 've-ui-mwHelpListToolGroup-tools-footer' );
// Parent constructor
ve.ui.MWHelpListToolGroup.super.apply( this, arguments );
// Initialization
this.$element.addClass( 've-ui-mwHelpListToolGroup' );
this.$group.addClass( 've-ui-mwHelpListToolGroup-tools' );
};
/* Setup */
OO.inheritClass( ve.ui.MWHelpListToolGroup, OO.ui.ListToolGroup );
/* Static Properties */
/**
* @static
* @inheritdoc
*/
ve.ui.MWHelpListToolGroup.static.name = 'mwHelpList';
/* Methods */
ve.ui.MWHelpListToolGroup.prototype.insertItemElements = function () {
// Mixin method
OO.ui.mixin.GroupElement.prototype.insertItemElements.apply( this, arguments );
this.$group.append( this.$footer );
};
ve.ui.MWHelpListToolGroup.prototype.setActive = function () {
// Parent method
ve.ui.MWHelpListToolGroup.super.prototype.setActive.apply( this, arguments );
if ( this.active && !this.versionPromise ) {
const $version = $( '<div>' ).addClass( 'oo-ui-pendingElement-pending' ).text( '\u00a0' );
this.$footer.append( $version );
this.versionPromise = ve.init.target.getLocalApi().get( {
action: 'query',
meta: 'siteinfo',
siprop: 'extensions'
} ).then( ( response ) => {
const extension = response.query.extensions.filter( ( ext ) => ext.name === 'VisualEditor' )[ 0 ];
if ( extension && extension[ 'vcs-version' ] ) {
$version
.removeClass( 'oo-ui-pendingElement-pending' )
.empty()
.append( $( '<a>' )
.addClass( 've-ui-mwHelpListToolGroup-version-link' )
.attr( 'target', '_blank' )
.attr( 'rel', 'noopener' )
.attr( 'href', extension[ 'vcs-url' ] )
.append( $( '<span>' )
.addClass( 've-ui-mwHelpListToolGroup-version-label' )
.text( ve.msg( 'visualeditor-version-label' ) + ' ' + extension[ 'vcs-version' ].slice( 0, 7 ) )
)
)
.append( ' ' )
.append( $( '<span>' )
.addClass( 've-ui-mwHelpListToolGroup-version-date' )
.text( extension[ 'vcs-date' ] )
);
} else {
$version.remove();
}
}, () => {
$version.remove();
} );
}
};
/* Registration */
ve.ui.toolGroupFactory.register( ve.ui.MWHelpListToolGroup );
/**
* User guide tool.
*
* @class
* @extends ve.ui.Tool
* @constructor
* @param {OO.ui.ToolGroup} toolGroup
* @param {Object} [config] Configuration options
*/
ve.ui.MWUserGuideTool = function VeUiMWUserGuideTool() {
ve.ui.MWUserGuideTool.super.apply( this, arguments );
this.setDisabled( false );
};
OO.inheritClass( ve.ui.MWUserGuideTool, ve.ui.Tool );
ve.ui.MWUserGuideTool.static.name = 'mwUserGuide';
ve.ui.MWUserGuideTool.static.group = 'help';
ve.ui.MWUserGuideTool.static.icon = 'help';
ve.ui.MWUserGuideTool.static.title =
OO.ui.deferMsg( 'visualeditor-help-label' );
ve.ui.MWUserGuideTool.static.autoAddToCatchall = false;
// Never disabled
ve.ui.MWUserGuideTool.prototype.onUpdateState = function () {};
ve.ui.MWUserGuideTool.prototype.onSelect = function () {
this.setActive( false );
const urlOrTitle = ve.msg( 'visualeditor-help-link' );
if ( urlOrTitle.indexOf( '//' ) !== -1 ) {
window.open( urlOrTitle );
} else {
// This link used to be internal link to mw:, but that doesn't work
// on 3rd party installations (T367267). Keep support for internal
// links as many wikis have local overrides which are internal.
window.open( new mw.Title( urlOrTitle ).getUrl() );
}
};
ve.ui.toolFactory.register( ve.ui.MWUserGuideTool );
/**
* Feedback dialog tool.
*
* @class
* @extends ve.ui.Tool
* @constructor
* @param {OO.ui.ToolGroup} toolGroup
* @param {Object} [config] Configuration options
*/
ve.ui.MWFeedbackDialogTool = function VeUiMWFeedbackDialogTool() {
ve.ui.MWFeedbackDialogTool.super.apply( this, arguments );
this.setDisabled( false );
};
OO.inheritClass( ve.ui.MWFeedbackDialogTool, ve.ui.Tool );
ve.ui.MWFeedbackDialogTool.static.name = 'mwFeedbackDialog';
ve.ui.MWFeedbackDialogTool.static.group = 'help';
ve.ui.MWFeedbackDialogTool.static.icon = 'speechBubble';
ve.ui.MWFeedbackDialogTool.static.title =
OO.ui.deferMsg( 'visualeditor-feedback-tool' );
ve.ui.MWFeedbackDialogTool.static.autoAddToCatchall = false;
// Never disabled
ve.ui.MWFeedbackDialogTool.prototype.onUpdateState = function () {};
ve.ui.MWFeedbackDialogTool.prototype.onSelect = function () {
this.setActive( false );
if ( !this.feedbackPromise ) {
this.feedbackPromise = mw.loader.using( 'mediawiki.feedback' ).then( () => {
const mode = this.toolbar.getSurface().getMode();
// This can't be constructed until the editor has loaded as it uses special messages
const feedbackConfig = {
bugsLink: 'https://phabricator.wikimedia.org/maniphest/task/edit/form/1/?projects=VisualEditor',
showUseragentCheckbox: true,
useragentCheckboxMandatory: true
};
// If so configured, tell mw.feedback that we're posting to a remote wiki and set the title
const veConfig = mw.config.get( 'wgVisualEditorConfig' );
if ( veConfig.feedbackApiUrl ) {
feedbackConfig.apiUrl = veConfig.feedbackApiUrl;
feedbackConfig.title = new mw.Title(
mode === 'source' ?
veConfig.sourceFeedbackTitle : veConfig.feedbackTitle
);
} else {
feedbackConfig.title = new mw.Title(
mode === 'source' ?
ve.msg( 'visualeditor-feedback-source-link' ) : ve.msg( 'visualeditor-feedback-link' )
);
}
return new mw.Feedback( feedbackConfig );
} );
}
this.feedbackPromise.done( ( feedback ) => {
feedback.launch( {
message: ve.msg( 'visualeditor-feedback-defaultmessage', location.toString() )
} );
} );
};
ve.ui.toolFactory.register( ve.ui.MWFeedbackDialogTool );
|