Page MenuHomePhabricator

ReferenceError due to CharInsert extension not loading mediawiki.toolbar before it is used
Closed, ResolvedPublic

Description

Recently inserting characters with extension CharInsert stopped working for some users at Swedish Wikipedia. After some testing with different user preferences it looks like mediawiki.toolbar with function insertTags() is no longer loaded for users without preference "Show edit toolbar". This JavaScript is needed for the extension to work for users who are not using the toolbar.

Workaround if you run into this problem: Enable the preference "Show edit toolbar".

Event Timeline

Lejonel raised the priority of this task from to Needs Triage.
Lejonel updated the task description. (Show Details)
Lejonel added a project: CharInsert.
Lejonel subscribed.

Thanks for taking the time to report this!

What is the exact difference to T85787 ? Or do they "just" depend on each other?

Bug T85787 is that CharInsert uses insertTags() which is marked deprecated which gives warning messages. This is not a big problem until the deprecated function is removed, but I think it is nice to avoid warning messages.

This bug (T88922) is that insertTags() and its replacement mw.toolbar.insertTags() are defined in the module mediawiki.toolbar. Most users use the user preference "Show edit toolbar" which I think loads this module. But users who are not using the toolbar get error message "ReferenceError: insertTags is not defined" and no character is inserted when they try to use CharInserts.

Aklapper triaged this task as Medium priority.Feb 10 2015, 1:06 PM

The mediawiki.toolbar module doesn't initialise the toolbar, it provides methods for interacting with the editing area. Essentially the tools needed for something else to make a basic toolbar.

If Charset uses these methods, it should simply declare a dependency on this module to ensure it is loaded. Right now it relies on MediaWiki core providing the classic toolbar and it loading these methods.

Looking deeper, CharInsert really needs maintenance work. It is still using inline event handlers nested in HTML:

function charInsertChar( $start, $end = '' ) {
	..
	return Xml::element( 'a',
		array(
			'onclick' => "insertTags('$estart','$eend','');return false",
			'href'    => "javascript:void()" ),
		$inline );
}

The error

ReferenceError: insertTags is not defined
SyntaxError: expected expression, got ')'

also appears when users click on any link at
https://ro.wikipedia.org/wiki/Special:Upload

After the page is loaded, mw.loader.getState('mediawiki.toolbar') returns "registered". I only get

Use of "insertTags" is deprecated. Use mw.toolbar.insertTags instead.'

after I run mw.loader.load('mediawiki.toolbar') and click on the links again.

He7d3r renamed this task from CharInsert extension needs to make sure mediawiki.toolbar is loaded to ReferenceError due to CharInsert extension not loading mediawiki.toolbar before it is used.Feb 24 2015, 5:32 PM
He7d3r added a project: Regression.

@Krinkle, it's worse, since the whole extension relies on parsing the wikicode of an interface message, and it's only reliable connection between 'desired functionality' and the extension delivering the functionality is that parserhook. This makes it rather difficult to properly correct this problem using RL (or actually even without using RL) until we enable merging i18n parser RL modules into the output page (didn't bartosz have a patch attempt for that somewhere?)

I don't see a good way to solve this quickly though...
Perhaps we should consider restoring the global insertTags() function temporarily.

In rowiki case enabling edit toolbar does not help. Better said, i already had enabled this feature and issue still occur either with or without feature enabled. Problem generally appear only on [[Special:Upload]] page - see He7der's post above.

Also on rowiki, recently one editor reported in local village pump a total disappearance of edit toolbar (https://ro.wikipedia.org/w/index.php?title=Wikipedia:Cafenea&oldid=9315395#Caseta_de_modificare), another one confirming periodical disappearance. I also noticed this issue. See T96043

matmarex claimed this task.
matmarex subscribed.

I'm pretty sure I fixed this in 627c26823efd5ee1ac960d80b06b83e92e15daa5 (September 30). Please reopen if that's not the case.

as T92781 was closed as duplicate of this task, I draw attention again that :ro:MediaWiki:Edittools does not work on :ro:Special:Upload.

PeterBowman subscribed.

@matmarex: I'm reopening, we have recently hit this issue on plwiktionary (report, answer). The steps to reproduce this are still the same:

  1. Disable the preference Show edit toolbar.
  2. Open any page in edit mode and try to insert a character contained in the Edittools box.
  3. TypeError: mw.toolbar is undefined
matmarex added a subscriber: Bawolff.

I'm not sure why this would come back, but I'm pretty sure it'll be fixed for good by the recently-merged rECHIb2f7c4c507e5: Remove inline event handler js from charinsert (it's not live yet). Please reopen if this is still occuring after the 1.27.0-wmf.16 deployment next week (see https://www.mediawiki.org/wiki/MediaWiki_1.27/Roadmap for dates).

While it works on action=edit depending on the user's personal configuration, it's always broken on [[Special:Upload]].

Change 288922 had a related patch set uploaded (by Brian Wolff):
[DO NOT MERGE] Remove inline event handler js from charinsert

https://gerrit.wikimedia.org/r/288922

Change 288922 merged by jenkins-bot:
Remove inline event handler js from charinsert

https://gerrit.wikimedia.org/r/288922

matmarex assigned this task to Bawolff.