mediawiki.page.watch.ajax: Use title with spaces instead of _
authorFomafix <fomafix@googlemail.com>
Wed, 4 Jan 2017 17:45:57 +0000 (18:45 +0100)
committerFomafix <fomafix@googlemail.com>
Wed, 4 Jan 2017 19:03:08 +0000 (20:03 +0100)
Since 1f15d1d5828dfbc70d036a52da57460ea0e89175 titles with spaces get shown
with _ instead of spaces in the success notification message.

Change-Id: I80bd1d2440ce8b815abb1fe19f4bd080bcc00fcc

resources/src/mediawiki/page/watch.js

index 5dda7e0..7cfe058 100644 (file)
                $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 );