$links = $links.filter( ':not( #bodyContent *, #content * )' );
$links.click( function ( e ) {
- var action, api, $link;
+ var mwTitle, action, api, $link;
+ mwTitle = mw.Title.newFromText( title );
action = mwUriGetAction( this.href );
- if ( action !== 'watch' && action !== 'unwatch' ) {
+ if ( !mwTitle || ( action !== 'watch' && action !== 'unwatch' ) ) {
// Let native browsing handle the link
return true;
}
api[ action ]( title )
.done( function ( watchResponse ) {
- var mwTitle, message, otherAction = action === 'watch' ? 'unwatch' : 'watch';
+ var message, otherAction = action === 'watch' ? 'unwatch' : 'watch';
- mwTitle = mw.Title.newFromText( title );
- if ( mwTitle && mwTitle.getNamespaceId() > 0 && mwTitle.getNamespaceId() % 2 === 1 ) {
+ if ( mwTitle.getNamespaceId() > 0 && mwTitle.getNamespaceId() % 2 === 1 ) {
message = action === 'watch' ? 'addedwatchtext-talk' : 'removedwatchtext-talk';
} else {
message = action === 'watch' ? 'addedwatchtext' : 'removedwatchtext';
}
- mw.notify( mw.message( message, title ).parseDom(), {
+ mw.notify( mw.message( message, mwTitle.getPrefixedText() ).parseDom(), {
tag: 'watch-self'
} );
$( '#wpWatchthis' ).prop( 'checked', watchResponse.watched === true );
} )
.fail( function () {
- var cleanTitle, msg, link;
+ var msg, link;
// Reset link to non-loading mode
updateWatchLink( $link, action );
// Format error message
- cleanTitle = title.replace( /_/g, ' ' );
link = mw.html.element(
'a', {
href: mw.util.getUrl( title ),
- title: cleanTitle
- }, cleanTitle
+ title: mwTitle.getPrefixedText()
+ }, mwTitle.getPrefixedText()
);
msg = mw.message( 'watcherrortext', link );