Page MenuHomePhabricator

Improper javascript array iteration causes problems
Closed, ResolvedPublic


In wikibits.js on line 367 or so, there are two for loops that use the
mechanism to loop through arrays. Since these are arrays and not objects they
should be looped through using plain for loops. Using causes problems
when you include javascript libraries like older versions of prototype that mess
with Object.prototype.

To see the fun bugs it causes, try including prototype in your skin and look at
the edit toolbar.

To fix this, change:

for(i in mwEditButtons) {


for (var i = 0; i < mwEditButtons.length; i++) {


for(i in mwCustomEditButtons) {


for (var i = 0; i < mwCustomEditButtons.length; i++) {

For further information about properly iterating arrays in javascript see:

Version: 1.8.x
Severity: minor



Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 9:20 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz6684.
bzimport added a subscriber: Unknown Object (MLST).

dto wrote:

Just wanted to say that I had to do the same, with the latest version of prototype.

By the way, this isn't because prototype messes with Object, but because it
messes with Array. (For example, the loop on line 470 works fine
because ta is an Object, not an Array.)

dto wrote:

Patch for wikibits.js fixing protoype incompatibility

Not sure how things work around a diff easier to commit than
scrolling to line 369?


ayg wrote:

Attached patches should generally be in unified diff format. If a dev would
prefer to just manually scroll to the right lines, they can do that too.

dto wrote:

Attached patches should generally be in unified diff format.

Was my attachment in the right format?

Thanks for the patch Dan.

Applied in r19744.