From 1f15d1d5828dfbc70d036a52da57460ea0e89175 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 8 Dec 2016 12:56:37 -0500 Subject: [PATCH] API: More i18n cleanup * 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 | 7 ++++--- includes/api/ApiLogin.php | 11 ++++++++--- includes/api/ApiRollback.php | 11 ----------- includes/api/ApiWatch.php | 10 ---------- resources/Resources.php | 6 ++++++ resources/src/mediawiki/api/watch.js | 1 - resources/src/mediawiki/page/watch.js | 16 +++++++++++++--- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29 index 986ecd891b..0cce190317 100644 --- a/RELEASE-NOTES-1.29 +++ b/RELEASE-NOTES-1.29 @@ -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 diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 723dc33c78..6cf1fad30c 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -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': diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index c802087231..9584f09be4 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -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 ); } diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php index d257e9005f..88aff4154e 100644 --- a/includes/api/ApiWatch.php +++ b/includes/api/ApiWatch.php @@ -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() ) { diff --git a/resources/Resources.php b/resources/Resources.php index a556b60ae4..3927a05045 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -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' => [ diff --git a/resources/src/mediawiki/api/watch.js b/resources/src/mediawiki/api/watch.js index 687b47514d..92722b55e0 100644 --- a/resources/src/mediawiki/api/watch.js +++ b/resources/src/mediawiki/api/watch.js @@ -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 diff --git a/resources/src/mediawiki/page/watch.js b/resources/src/mediawiki/page/watch.js index b860dbdbb8..0319c64550 100644 --- a/resources/src/mediawiki/page/watch.js +++ b/resources/src/mediawiki/page/watch.js @@ -132,9 +132,19 @@ 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' } ); -- 2.20.1