Page MenuHomePhabricator

mw.action.watch.ajax should work $wgActionPaths is configured for watch/unwatch
Closed, ResolvedPublic

Description

Tested as of r81491; relevant bit of code was last touched in r78150.

When initializing the AJAX behavior for the watch tab, it seems that current code tries to divine the target page title from the link URL on the watch tab, then save that title as extra data associated with the link node:

in mediawiki.action.watch.ajax.js:

		var title = mw.util.getParamValue( 'title', link.href );
		$link.data( 'target', title.replace( /_/g, ' ' ) );

This unfortunately fails when the target link doesn't use a query string parameter -- mw.util.getParamValue() is unable to find it, and the next line throws an error:

title is null
[Break On This Error] $link.data('target',title.replace(/_/g,' '));

As a result, AJAX watch fails to initialize properly, and the unhandled exception may also halt initialization of other UI elements.

This code probably doesn't need to be trying to pull a title from the link manually; it should probably just be using the available wgTitle.

Steps to reproduce:

  1. Set some items in $wgActionPaths, say:

    $actions = array('watch', 'unwatch'); foreach ($actions as $a) { $wgActionPaths[$a] = "$wgScriptPath/action/$a/$1"; }
  1. Set up appropriate rewrite rules or helper scripts to pass /action/(un)?watch/Foo over to /index.php?action=blah&title=Foo
  1. Load up a page view while logged in.

Version: 1.18.x
Severity: normal

Details

Reference
bz27146

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:12 PM
bzimport set Reference to bz27146.

Assigning to me as I should've fixed this when rewriting this.

I remember thinking about this but I didn't actually write it down nor fix it.
Although I didn't introduce the bug, I'll finish this up this afternoon.

+ $link.attr( 'href', $link.attr( 'href' ).replace( '&action=' + action , '&action=' + otheraction ) );
should be

wgScript ?title= wgPageName (not wgTitle since that doens't include the namespace) & action= (un)watch

Changing summary, it's not a regression since it was done the same way in the legacy script.

Fixed in r82498.

That doesn't appear to fix the actual bug, which remains in 1.18.0 and trunk:

		var title = mw.util.getParamValue( 'title', link.href );
		$link.data( 'target', title.replace( /_/g, ' ' ) );

This was seen to break the Map extension (depending on load order involving gadgets, extensions, and core) on occupywiki.org.uk, running 1.18.0.

Combination of:

  • watch in wgActionPaths
  • HotCat gadget
  • Map extension

As far as I can tell, the ajax watch setup code's ready handler got called before the Map extension's ready handler when HotCat was present; when the watch code failed, the maps setup code didn't get run.

The line above also tries to get an 'action' param from the same link; this one doesn't happen to crash but will fail to compare properly against 'unwatch'.

Note that the error here is on setup.

Re-fixed in r107354 (major rewrite).