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 created this task.Feb 8 2015, 10:31 AM
Lejonel updated the task description. (Show Details)
Lejonel raised the priority of this task from to Needs Triage.
Lejonel added a project: CharInsert.
Lejonel added a subscriber: Lejonel.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptFeb 8 2015, 10:31 AM

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.

Lejonel set Security to None.
Aklapper triaged this task as Normal 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 );
}
He7d3r added a subscriber: He7d3r.Feb 24 2015, 5:31 PM

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.
TheDJ added a subscriber: TheDJ.Feb 24 2015, 8:39 PM

@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.

XXN added a subscriber: XXN.Feb 25 2015, 10:25 PM
Aklapper updated the task description. (Show Details)Apr 10 2015, 11:16 AM
XXN added a comment.Apr 14 2015, 7:13 PM

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 closed this task as Resolved.Oct 27 2015, 9:29 PM
matmarex claimed this task.
matmarex added a subscriber: matmarex.

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

Restricted Application added a subscriber: Josve05a. · View Herald TranscriptOct 27 2015, 9:29 PM
XXN added a comment.EditedOct 29 2015, 6:25 PM

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 reopened this task as Open.Mar 2 2016, 8:29 PM
PeterBowman added a subscriber: PeterBowman.

@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 closed this task as Resolved.Mar 3 2016, 7:42 PM
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).

Rillke added a subscriber: Rillke.Mar 14 2016, 11:55 PM

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 closed this task as Resolved.May 27 2016, 12:09 PM
matmarex assigned this task to Bawolff.