Page MenuHomePhabricator

JavaScript global variables fail in XHTML mode
Closed, ResolvedPublic

Description

While setting $wgMimeType to application/xhtml+xml to enforce XHTML
well-formedness for testing, I noticed that there seem to be some regressions
where JavaScript behavior doesn't work correctly:

  • wgBreakFrames check on all page views
  • mwEditButtons when building toolbar in edit view

Found this to happen in following browsers:

  • Firefox 2.0, Mac and Windows
  • Firefox 1.5, Mac
  • Opera 9, Mac

The variables, defined respectively inline in a <script> element and in
wikibits.js, don't appear to be visible in the subroutines that use them.
'Undefined variable' or 'has no properties' errors result.

Opera's error messages:

name: ReferenceError
message: Statement on line 51: Reference to undefined variable: wgBreakFrames
Backtrace:

Line 51 of linked script http://katitzi.local/trunk/skins/common/wikibits.js?33
  if (wgBreakFrames)

name: TypeError
message: Statement on line 341: Could not convert undefined or null to object
Backtrace:

Line 341 of linked script http://katitzi.local/trunk/skins/common/wikibits.js?33
  mwEditButtons[mwEditButtons.length] = {imageFile : imageFile, speedTip :

speedTip, tagOpen : tagOpen, tagClose : tagClose, sampleText : sampleText};

Line 3 of inline#1 script in

http://katitzi.local/trunk/index.php?title=Main_Page&action=edit

addButton("/trunk/skins/common/images/button_bold.png", "Bold text", "'''",

"'''", "Bold text");

Offhand I don't see anything wrong with the code; it seems correct to me and as
far as I know should work fine in XHTML mode just as it does in HTML 4 mode
(text/html mime-type).

Removing the 'var' on the declaration in wikibits.js does not appear to have any
effect for mwEditButtons.


Version: 1.9.x
Severity: normal

Details

Reference
bz8264

Related Objects

StatusSubtypeAssignedTask
ResolvedNone
ResolvedNone

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:31 PM
bzimport set Reference to bz8264.
bzimport added a subscriber: Unknown Object (MLST).

Fixed in r18342.

When the inline global variable definition block got expanded, the <script>
contents got wrapped in old-style //<!-- HTML comment blocks.

That's incompatible with XHTML as parsed by a proper XML parser, since the
contents really do get removed before being passed to the JavaScript
interpreter.

Browsers so old they don't understand <script> blocks also don't understand
name-based virtual hosts and don't have a prayer at reaching a typical modern
MediaWiki-based web site, so there's no need to use that technique.

Removed the comment blocks, and replaced it with a /*<![CDATA[*/ /*]]>*/
wrapper to ensure that contents aren't misinterpreted in XHTML mode.