API: More i18n cleanup
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 8 Dec 2016 17:56:37 +0000 (12:56 -0500)
committerAnomie <bjorsch@wikimedia.org>
Thu, 8 Dec 2016 21:25:38 +0000 (21:25 +0000)
* Use errorformat for action=login Failed responses in non-BC mode.
* We removed 'messageHtml' from action=rollback's response on error, but
  left it for success. Remove it there too, it's even less useful.
* We changed action=watch's reporting of errors, but left the
  mostly-pointless reporting of "success" UI messages. These should be
  handled on the client side.

Change-Id: Ia6c402a4254fbacf4c2c3f125ce8bf0bcc71e509

RELEASE-NOTES-1.29
includes/api/ApiLogin.php
includes/api/ApiRollback.php
includes/api/ApiWatch.php
resources/Resources.php
resources/src/mediawiki/api/watch.js
resources/src/mediawiki/page/watch.js

index 986ecd8..0cce190 100644 (file)
@@ -58,11 +58,12 @@ production.
 * action=revisiondelete no longer includes a "rendered" property on warnings
   and errors for each item. Use errorformat=wikitext if you're wanting parsed
   output.
-* action=rollback no longer returns a "messageHtml" property on errors. Use
-  errorformat=html if you're wanting HTML formatting of messages.
+* action=rollback no longer returns a "messageHtml" property. Use
+  errorformat=html if you're wanting HTML formatting of error messages.
 * action=upload now reports optional stash failures as an array under key
   'stasherrors' rather than a 'stashfailed' text string.
-* action=watch reports 'errors' and 'warnings' instead of a single 'error'.
+* action=watch reports 'errors' and 'warnings' instead of a single 'error', and
+  no longer returns a 'message' on success.
 
 === Action API internal changes in 1.29 ===
 * New methods were added to ApiBase to handle errors and warnings using i18n
index 723dc33..6cf1fad 100644 (file)
@@ -197,9 +197,14 @@ class ApiLogin extends ApiBase {
                                break;
 
                        case 'Failed':
-                               $result['reason'] = ApiErrorFormatter::stripMarkup(
-                                       $message->useDatabase( false )->inLanguage( 'en' )->text()
-                               );
+                               $errorFormatter = $this->getErrorFormatter();
+                               if ( $errorFormatter instanceof ApiErrorFormatter_BackCompat ) {
+                                       $result['reason'] = ApiErrorFormatter::stripMarkup(
+                                               $message->useDatabase( false )->inLanguage( 'en' )->text()
+                                       );
+                               } else {
+                                       $result['reason'] = $errorFormatter->formatMessage( $message );
+                               }
                                break;
 
                        case 'Aborted':
index c802087..9584f09 100644 (file)
@@ -92,17 +92,6 @@ class ApiRollback extends ApiBase {
                        'last_revid' => intval( $details['target']->getID() )
                ];
 
-               $oldUser = $details['current']->getUserText( Revision::FOR_THIS_USER );
-               $lastUser = $details['target']->getUserText( Revision::FOR_THIS_USER );
-               $diffUrl = $titleObj->getFullURL( [
-                       'diff' => $info['revid'],
-                       'oldid' => $info['old_revid'],
-                       'diffonly' => '1'
-               ] );
-               $info['messageHtml'] = $this->msg( 'rollback-success-notify' )
-                       ->params( $oldUser, $lastUser, $diffUrl )
-                       ->parseAsBlock();
-
                $this->getResult()->addValue( null, $this->getModuleName(), $info );
        }
 
index d257e90..88aff41 100644 (file)
@@ -110,19 +110,9 @@ class ApiWatch extends ApiBase {
                if ( $params['unwatch'] ) {
                        $status = UnwatchAction::doUnwatch( $title, $user );
                        $res['unwatched'] = $status->isOK();
-                       if ( $status->isOK() ) {
-                               $msgKey = $title->isTalkPage() ? 'removedwatchtext-talk' : 'removedwatchtext';
-                               $res['message'] = $this->msg( $msgKey, $title->getPrefixedText() )
-                                       ->title( $title )->parseAsBlock();
-                       }
                } else {
                        $status = WatchAction::doWatch( $title, $user );
                        $res['watched'] = $status->isOK();
-                       if ( $status->isOK() ) {
-                               $msgKey = $title->isTalkPage() ? 'addedwatchtext-talk' : 'addedwatchtext';
-                               $res['message'] = $this->msg( $msgKey, $title->getPrefixedText() )
-                                       ->title( $title )->parseAsBlock();
-                       }
                }
 
                if ( !$status->isOK() ) {
index a556b60..3927a05 100644 (file)
@@ -1738,6 +1738,8 @@ return [
                        'mediawiki.api.watch',
                        'mediawiki.notify',
                        'mediawiki.util',
+                       'mediawiki.Title',
+                       'mediawiki.jqueryMsg',
                        'jquery.accessKeyLabel',
                        'mediawiki.RegExp',
                ],
@@ -1749,6 +1751,10 @@ return [
                        'tooltip-ca-watch',
                        'tooltip-ca-unwatch',
                        'watcherrortext',
+                       'addedwatchtext',
+                       'addedwatchtext-talk',
+                       'removedwatchtext',
+                       'removedwatchtext-talk',
                ],
        ],
        'mediawiki.page.rollback' => [
index 687b475..92722b5 100644 (file)
@@ -19,7 +19,6 @@
         *  parameter)
         * @return {string} return.done.watch.title Full pagename
         * @return {boolean} return.done.watch.watched Whether the page is now watched or unwatched
-        * @return {string} return.done.watch.message Parsed HTML of the confirmational interface message
         */
        function doWatchInternal( pages, addParams ) {
                // XXX: Parameter addParams is undocumented because we inherit this
index b860dbd..0319c64 100644 (file)
 
                        api[ action ]( title )
                                .done( function ( watchResponse ) {
-                                       var otherAction = action === 'watch' ? 'unwatch' : 'watch';
-
-                                       mw.notify( $.parseHTML( watchResponse.message ), {
+                                       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';
+                                       }
+
+                                       mw.notify( mw.message( message, title ).parseDom(), {
                                                tag: 'watch-self'
                                        } );