Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/toolgroups/ve.ui.MWHelpListToolGroup.js

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