Last modified: 2013-01-07 20:12:22 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T29894, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 27894 - Move 'editondblclick' event listener down from body to div#bodyContent
Move 'editondblclick' event listener down from body to div#bodyContent
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
unspecified
All All
: Normal minor (vote)
: ---
Assigned To: Krinkle
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-03-06 13:34 UTC by The Evil IP address
Modified: 2013-01-07 20:12 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
proposed patch for this bug (2.01 KB, patch)
2011-05-12 06:09 UTC, Nik
Details
patch revision (2.00 KB, patch)
2011-05-18 06:29 UTC, Nik
Details
Follow-up patch implementing the points above (1.93 KB, patch)
2011-07-08 19:43 UTC, Krinkle
Details

Description The Evil IP address 2011-03-06 13:34:37 UTC
Currently, when you activate the "edit on double click" setting, any double-click anywhere on the body will open the edit form. I have found that to be somewhat confusing already, for example when mistakenly double-clicking on the sidebar, the search box or other parts outside the actual page content. Thus, I believe that this script should probably be added via Resource Loader as an event listener on div#bodyContent instead of on the <body> tag, as it currently is the case.
Comment 1 Platonides 2011-03-06 14:54:27 UTC
It was added directly to the body tag.

$bodyAttrs['ondblclick'] = "document.location = '" . Xml::escapeJsString( $this->getTitle()->getEditURL() ) . "'";

However, <div id="bodyContent"> is added dirrectly by the skin, it doesn't seem a good idea to add it there. So yes, an event listener seems the way to go.
Comment 2 Krinkle 2011-03-09 00:12:22 UTC
The id and locatin of that tag is variable per-skin.

The mw.util class has a $content variable though which contains a jQuery object of the content element in the current skin.

should be as simple as attaching a .dblclick() to mw.util.$content
Comment 3 Nik 2011-05-12 06:09:56 UTC
Created attachment 8531 [details]
proposed patch for this bug

Krinkle, I used the skin-independent mw.util.$content variable like you suggested. I removed the php-generated 'ondblclick' attribute to <body> and made a jQuery event listener. This solution works for me.
Comment 4 Krinkle 2011-05-16 21:21:54 UTC
(In reply to comment #3)
> Created attachment 8531 [details]
> proposed patch for this bug
> 
> Krinkle, I used the skin-independent mw.util.$content variable like you
> suggested. I removed the php-generated 'ondblclick' attribute to <body> and
> made a jQuery event listener. This solution works for me.

Hi Nik,

Thanks for your patch.

Two notes though:

1) document.location was originally a read-only property, although Gecko browsers (like Firefox) allow you to assign to it as well. For cross-browser safety, use window.location instead. [1]


2) Appending '&action=url' to the url is not safe and prone to error. The following three urls are all examples of how MediaWiki can be configured that are popular and supported:

- Using rewrite rules with wgArticlePath:
-- http://somewi.ki/wiki/Article

- Using rewrite rules and wgActionPaths:
-- http://somewi.ki/view/Article

- The default:
-- http://somewi.ki/w/index.php/Article

-- Full url (almost never used, but works)
- http://somewi.ki/w/index.php?title=Article

Appending '&action' only works for the last one. I suggest using the wgScript mw.config variable ( mw.config.get( 'wgScript' ) ), and manually building a url with the title (wgPageName) and action (edit) parameters.

--
Krinkle


[1] https://developer.mozilla.org/en/document.location#Notes
Comment 5 Nik 2011-05-18 06:29:17 UTC
Created attachment 8547 [details]
patch revision

Krinkle, thanks for your suggestions. I've revised the patch, the edit URL is now reliable since I'm building it manually instead of appending to the existing URL.

However, this means that when double-clicking to edit, the edit URL will always be in this format:
 - http://somewi.ki/wiki/index.php?title=Main_Page&action=edit

Regardless of the URL format of the rest of the wiki.
Comment 6 The Evil IP address 2011-06-09 13:42:12 UTC
Nice to see the follow-ups on this bug. I've recently noted another problem with this event listener that would be nice to fix already in this revision. We shouldn't use an anonymous function here, as these can't be removed via Element.removeEventListener(). Removing them would be useful for scripts like Twinkle: Currently, double-clicking a page while using Twinkle opens the edit mode, which is quite annoying.
Comment 7 Krinkle 2011-06-09 15:07:24 UTC
(In reply to comment #6)
> Nice to see the follow-ups on this bug. I've recently noted another problem
> with this event listener that would be nice to fix already in this revision. We
> shouldn't use an anonymous function here, as these can't be removed via
> Element.removeEventListener(). Removing them would be useful for scripts like
> Twinkle: Currently, double-clicking a page while using Twinkle opens the edit
> mode, which is quite annoying.

Remember that this is an opt-in preference. Either Twinkle users shouldn't enable that preference or Twink should $content.unbind('dblclick') or something like that (perhaps namespace the event)
Comment 8 Krinkle 2011-07-06 22:10:13 UTC
@Nik: I've reviewed your patch. It looks good.

If you're familiar with event namespaces (in particular in jQuery) it would be nice if you could bind it to "dblclick" with the "mw-editondblclick" namespace so that scritps can use .unbind() for that namespace only without removing all events.

It's a bit beyond the scope of "easy" though, so if you don't feel like doing that I will apply your good patch as-is and then apply an additional fix for the namespace.

Thanks in advance,
Comment 9 Brion Vibber 2011-07-06 22:31:13 UTC
Patch has several bugs:
* fails to take revision ID (oldid parameter) into account, and possibly others
* hardcodes use of script & action=edit instead of using $wgActionPaths
* clutters mediawiki.util.js with rarely-used code for all users

I would recommend:
* grab the edit URL from the edit tab to avoid having to recalculate it manually (which causes the first two bugs above)
* move from mediawiki.util.js to its own module, and only add that module when the option is being used
Comment 10 Brion Vibber 2011-07-06 22:31:58 UTC
(patch also doesn't do URL escaping on the title, which can cause failures when eg title contains a literal &)
Comment 11 Krinkle 2011-07-08 19:40:25 UTC
nice catc(In reply to comment #9)
> Patch has several bugs:
Nice catches.

A few more:
* Loading of module needs to be moved out of OutputPage->headElement probably
* Should account for the situation in which there is no edit link on the page (ie. not bind the event, because if MediaWiki decided not to output that tab, it probably has a good reason)
* There ar differences in skins in where this link will be. This is a common problem we are encountering more and more often lately (just look at the code that makes mw.util.$content and addPortletLink work, it's disguisting). Probably need to make some radical changes to skins in the future, but oh well. This can be fixed in the long term by not allowing skins to use different IDs for core elements or by requiring skins to log into a method how/where elements are) – back to the present this can be solved by either:
-- exporting the edit-tab link through a config variable (alert! this is not a config variable)
-- exporting it as a piece of information in the per-module configuration (sounds good, except that such a thing doesn't exist yet)
-- scrapping HTML for "#ca-edit a" and not caring about other skins.
-- a switch-case for all skins.

The last two options will be ugly and not extendable by custom skins.
Comment 12 Krinkle 2011-07-08 19:43:47 UTC
Created attachment 8759 [details]
Follow-up patch implementing the points above
Comment 13 Krinkle 2011-08-01 22:13:50 UTC
Sorry for the long delay.

Patch applied in r93664.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links