mw.toolbar.insertTags should be independent from mediawiki.toolbar module
Closed, DeclinedPublic

Description

The function mw.toolbar.insertTags (documentation) is currently bundled with the mediawiki.toolbar module, while it is useful without it as well. The advantage of that function over the jquery.textSelection module is that it works on the input for the edit comment, too. It should be possible to load and use it without having the old toolbar initialized (which is hidden when WikiEditor is used). So it should go to mediawiki.action.edit.js or something like that.

See also: T39084: WikiEditor: Toolbar should insert tags in edit summary input (if focussed)

Schnark created this task.Feb 9 2015, 11:00 AM
Schnark updated the task description. (Show Details)
Schnark raised the priority of this task from to Needs Triage.
Schnark added a subscriber: Schnark.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptFeb 9 2015, 11:00 AM
Aklapper triaged this task as Normal priority.Feb 11 2015, 9:19 PM
He7d3r updated the task description. (Show Details)Feb 12 2015, 12:22 AM
He7d3r set Security to None.

What is your use case for this?

That seems unrelated. Or rather, proof that task indicates that this task is requesting separation we don't need. The extension is using methods of a module without depending on the module. It previously worked by mere luck (ever since MediaWiki 1.17 introduced the module system).

The various gadgets to insert special characters are the use case for this. Currently they have to declare a dependency on mediawiki.toolbar, which will load and initialize the classical toolbar, even when it is not used (because WikiEditor is active and hides the classical toolbar). This isn't a big problem, but I think that the separation of mediawiki.action.edit and mediawiki.toolbar were done for a good reason, so forcing all wikis to depend on and load mediawiki.toolbar because they need one function that doesn't depend on the toolbar (rather the other way round, the toolbar depends on mw.toolbar.insertTags), doesn't seem the right thing for me.

The various gadgets to insert special characters are the use case for this. Currently they have to declare a dependency on mediawiki.toolbar, which will load and initialize the classical toolbar, even when it is not used [..]

I agree there is a use case for gadgets to insert characters into a text field of their choosing. However the problem, as you already mention, is that mediawiki.toolbar is not the appropiate module to use in that case.

This task was originally created with the following claim:

The function mw.toolbar.insertTags [..] is useful without it (mediawiki.toolbar) as well. The advantage of that function over jquery.textSelection is that it works on the input for the edit comment, too.

I don't understand what you mean here. Below we examine the code behind insertTags.

mediawiki.toolbar
insertTags: function ( pre, peri, post ) {
	if ( current && current.length ) {
		current.textSelection(
			'encapsulateSelection', { pre: pre, peri: peri, post: post }
		);
	}
}

The above code contains no logic besides calling textSelection(), so I would recommend gadgets wanting to use it simply call it directly. There is no special support here for input fields (one line), edit summaries, or text areas (larger, multiple lines). The jquery.textSelection module supports all of them, <input> and <textarea>.

Jdforrester-WMF closed this task as Declined.Jan 9 2018, 10:50 PM
Jdforrester-WMF added a subscriber: Jdforrester-WMF.

Yeah, I agree with Timo.

Restricted Application removed a subscriber: Liuxinyu970226. · View Herald TranscriptJan 9 2018, 10:50 PM