Page MenuHomePhabricator

Avoid multiple checks for action=edit and action=submit in akeytt
Closed, ResolvedPublic

Description

Author: md5

Description:
The akeytt() function currently does a regex match against
window.location.search on every iteration of the main loop to see if the current
page has either "action=edit" or "action=submit". This check should be done
before the loop since the result is the same every time. I didn't see a huge
performance improvment from the change, but it can't hurt.

The changes can be seen at
http://en.wikipedia.org/wiki/User:Mike_Dillon/Scripts/timeOnload.js


Version: 1.9.x
Severity: enhancement
URL: http://en.wikipedia.org/skins-1.5/common/wikibits.js

Details

Reference
bz8622

Event Timeline

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

md5 wrote:

I also changed the check to be more readable:

if (a && !(isEditOrSubmit && (id == 'ca-watch' || id == 'ca-unwatch')))

The old version seems a little inverted and hard to understand.

Searching for action=edit or action=submit in the URL is *extremely* unreliable,
as the URL doesn't necessarily contain those (POST requests, $wgActionUrls, etc).

If some code relies on these it is buggy and must be removed or fixed.

md5 wrote:

I was actually thinking the same thing. In this case, it would probably be good
to use wgIsArticle==false instead, but I haven't tested it.

That assumes that ca-watch and ca-unwatch should only have their accesskey
settings ignored when wgIsArticle is false, which seems like a safe assumption
as those tabs are only added to pages that can be edited and in the case that an
edit is in progress wgIsArticle is false.

I'm not sure why this code exists to begin with...

Either the tabs are *present* or they're *not present*. If they're present, make
sure their tooltips are set right. If they're not present, don't mess with them.

I don't see any requirement for such a check.

md5 wrote:

I think the idea was that the accessKey conflicts with the one used for the
checkbox when in editing mode. But I'm not certain either.

ayg wrote:

(In reply to comment #5)

I think the idea was that the accessKey conflicts with the one used for the
checkbox when in editing mode. But I'm not certain either.

That's correct.

In that case the sensible thing is probably to check for the existence of the
checkbox, rather than trying to guess that it _might_ be present based on
aura/phase of the moon. ;)

It should be easy to identify by its id:
<input tabindex='4' type='checkbox' name='wpWatchthis' checked='checked'
accesskey="w" id='wpWatchthis' />

ayg wrote:

D'oh. Good point. Fixed in r19223.