Page MenuHomePhabricator

wikibits.js: scrollEditBox overwrites onsubmit, should use hookEvent method
Closed, ResolvedPublic

Description

In skins/common/wikibits.js, function scrollEditBox is setting the form's
onsubmit handler directly, overwriting any other onsubmit handlers. Therefore
it's not possible for an extension to add an onsubmit handler to EditPage.php.

I suggest scrollEditBox should use wikibits.js:hookEvent() instead of setting
form.onsubmit directly.

The code:
editFormEl.onsubmit = function() {
...


Version: 1.9.x
Severity: normal
OS: Windows Server 2003
Platform: PC

Details

Reference
bz9437

Event Timeline

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

hookEvent() can't be used directly because it adds events only to the window
object. So I suggest wikibits.js get a new, more general function,
hookObjectEvent, that works on any object, and you rewrite hookEvent in terms of it.

// wikibits.js
function hookObjectEvent(obj, hookName, hookFunct) {

if (obj.addEventListener) {
  obj.addEventListener(hookName, hookFunct, false);
} else if (obj.attachEvent) {
  obj.attachEvent("on" + hookName, hookFunct);
}

}

function hookEvent(hookName, hookFunct) {

hookObjectEvent(window, hookName, hookFunct);

}

This is a very simple fix and I've provided full source code for it. Any chance that someone will consider it? It does not affect MediaWiki's behavior at all, but allows extension writers to add onsubmit handlers properly.