mediawiki.page.watch.ajax: Fail early if updateWatchLink is called wrong
authorThiemo Mättig <thiemo.maettig@wikimedia.de>
Thu, 6 Feb 2014 14:33:01 +0000 (15:33 +0100)
committerKrinkle <krinklemail@gmail.com>
Thu, 20 Mar 2014 18:13:32 +0000 (18:13 +0000)
commit40dff673debeb93297a673c91eeb74d4d102739e
tree6a406df0643cf2a0e761caa1f338e35337071058
parent0f0b88c5b38b515c3beca380b5eb8a55cf96ea3b
mediawiki.page.watch.ajax: Fail early if updateWatchLink is called wrong

If the exposed function is called from a gadget or user script but
no watch/unwatch link was found the function fails even if the
first parameter is a valid jQuery object as required by the
documentation. $link.attr(...) returns null and null.match(...)
fails.

A very simple example why this can happen is as follows:
mw.page.watch.updateWatchLink( $( '#ca-watch a' ), 'watch', 'loading' );
mw.page.watch.updateWatchLink( $( '#ca-watch a.loading' ), 'unwatch' );
(starts the spinning loading animation and tries to stop it
afterwards but may fail if something went wrong, e.g. the user
clicked the star).

The action parameter needs to be checked because it is used to
build an ID and a message key. Bad values turn the page in an
unrecoverable state (the watch link gets an empty action=, the
label turns into something <undefined> and no script can recover
that broken state since the ID turned into whatever). While such a
check is not necesarry in most cases it is here, because the
function is exposed.

Change-Id: I6ee9a7ee6b7c0fc7a5444674afd1ed6f8cacc858
resources/mediawiki.page/mediawiki.page.watch.ajax.js