Page MenuHomePhabricator

Exception thrown by ext.math.editbutton.enabler - TypeError: mw.toolbar is undefined
Closed, ResolvedPublic

Description

At https://www.mediawiki.org/wiki/Special:NewMessages I'm getting this error message in webconsole:

"Exception thrown by ext.math.editbutton.enabler" load.php:150
"TypeError: mw.toolbar is undefined" TypeError: mw.toolbar is undefined
Stack trace:
@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z line 4 > eval:2:2316
@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z line 4 > eval:2:2235
runScript@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:161:128
execute/</checkCssHandles@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:161:613
execute@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:162:392
handlePending@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:159:664
runScript@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:161:140
execute/</checkCssHandles@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:161:613
execute/</cssHandle/<@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:161:743
jQuery.Callbacks/fire@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:45:106
jQuery.Callbacks/self.fireWith@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:46:431
jQuery.Callbacks/self.fire@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:46:474
addEmbeddedCSS@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:156:502
execute@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:162:199
mw.loader</<.implement@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:168:858
@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z line 4 > eval:38:951
.globalEval/<@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:4:666
.globalEval@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:4:632
mw.loader</<.work@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:164:718
request@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:162:903
mw.loader</<.load@https://bits.wikimedia.org/www.mediawiki.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20150107T194503Z:170:449
@https://www.mediawiki.org/wiki/Special:NewMessages:571:1

It doesn't seem to be a problem on any other pages that I can find.

Event Timeline

Quiddity created this task.Jan 8 2015, 9:21 PM
Quiddity updated the task description. (Show Details)
Quiddity raised the priority of this task from to Needs Triage.
Quiddity added a subscriber: Quiddity.
Ciencia_Al_Poder added a subscriber: Ciencia_Al_Poder.

Adding the JavaScript keyword.

This happens on every page that uses LiquidThreads.

The CharInsert buttons don't work on LiquidThreads messages now: they appear, but clicking on them does nothing

Apparently, ext.math.editbutton.enabler should require "mediawiki.toolbar" instead of assuming it has been loaded already:

https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FMath/354c0938dbb353bd9280d5446a79a6158f3d07bc/Math.php#L497

This should be good first bug to fix

Physikerwelt set Security to None.Jan 10 2015, 3:15 PM
Physikerwelt added a subscriber: Esanders.
Physikerwelt moved this task from Incoming to Doing on the Math board.Jan 10 2015, 3:24 PM

Change 184127 had a related patch set uploaded (by Physikerwelt):
Add dependency to mediawiki.toolbar

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

Patch-For-Review

Aklapper triaged this task as High priority.Jan 12 2015, 1:43 PM
He7d3r added a subscriber: He7d3r.Jan 12 2015, 3:59 PM

@Aklapper, what's the intended effect by raising the priority of the issue. I have created a patch that needs to be reviewed and tested. So someone needs to assign himself to do that at some point in time in the future.

@Aklapper, what's the intended effect by raising the priority of the issue.

To keep track of things that should happen rather sooner than later. Feel free to revert/correct if you disagree with the set priority.

@Aklapper, no it's fine. But it might take month until it gets reviewed. So if it would be a really serious problem, I would have to contact someone, who takes care of the code review.

Aklapper lowered the priority of this task from High to Normal.Jan 12 2015, 8:58 PM

The underlying problem is that Math is doing something weird with the edit toolbar.

By design, no module should manually load the "mediawiki.toolbar" module. The toolbar module is loaded by core on the EditPage and then used to construct the classic toolbar. If you're not on an edit page, the code calling mw.toolbar.addButton must not run. If you run it anyway and then avoid the inevitable crash by adding a dependency on mw.toolbar you'd be loading a module that does nothing only to call a function that then also does nothing.

Instead, per https://www.mediawiki.org/wiki/Manual:Custom_edit_buttons:

Load the addButton-code, and guard it with if ( mw.toolbar ). MediaWiki core will load the toolbar module as necessary based on the page, action and user preferences. And it loads it from the top queue so it may be depended on implicitly throughout the page run time.

It previously didn't throw on LiquidThreads, but it wasn't working either. So remove the dependency and add the if block to resolve the exception and restore it to previous working order.

He7d3r added a subscriber: GOIII.EditedJan 14 2015, 11:54 PM

[off-topic]
@GOIII: I don't have the time to check, but I think T86235#976999 might be relevant for the Wikisource scripts (including the ProofreadPage extension and MediaWiki:Gadget-ocr.js) which add things to the old/classical toolbar. But it will probably require updates to the logic which decides which of the toolbars to use, and which modules are necessary...

See also: https://www.mediawiki.org/wiki/Manual:Custom_edit_buttons?diff=1268821

@Krinkle I tried to submit a patch along your description. Can you do a code review?

Change 184127 merged by jenkins-bot:
Add dependency on mediawiki.toolbar

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

Krinkle closed this task as Resolved.Jan 22 2015, 9:56 PM
Krinkle assigned this task to Physikerwelt.
Krinkle removed a subscriber: gerritbot.