mediawiki.page.watch: Avoid dynamic message keys
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 14 Dec 2016 13:17:58 +0000 (14:17 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Wed, 14 Dec 2016 13:20:25 +0000 (13:20 +0000)
Restructure the code to avoid constructing message names by adding
strings together. Makes it easier to find the usages.

Also, simplify a check for odd/even namespace numbers.

Change-Id: I0b6794cc07ed2a600499632d240b71898715c5b0

resources/src/mediawiki/page/watch.js

index 0319c64..f880e6a 100644 (file)
                                .done( function ( watchResponse ) {
                                        var mwTitle, message, otherAction = action === 'watch' ? 'unwatch' : 'watch';
 
-                                       message = action === 'watch' ? 'addedwatchtext' : 'removedwatchtext';
                                        mwTitle = mw.Title.newFromText( title );
-                                       if ( mwTitle && mwTitle.getNamespaceId() > 0 &&
-                                               /* eslint-disable no-bitwise */
-                                               ( mwTitle.getNamespaceId() & 1 ) === 1
-                                               /* eslint-enable no-bitwise */
-                                       ) {
-                                               message += '-talk';
+                                       if ( mwTitle && 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(), {