From d4133a3675263a8c3538435f4f7054b8b0070e39 Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Wed, 21 Nov 2012 22:17:29 +0100 Subject: [PATCH] Fix uselang parameter in ApiWatch It's now possible to use uselang with the watch API without it throwing a warning (cause the parameter wasn't defined). Idea and some code taken from ApiParse. Change-Id: I74b7c4286c0c2f44fabc337d5fb744560f71cf71 --- includes/api/ApiParse.php | 2 +- includes/api/ApiWatch.php | 15 +++++++++++++++ resources/mediawiki.api/mediawiki.api.watch.js | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 12c20fb596..08764a5b18 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -72,7 +72,7 @@ class ApiParse extends ApiBase { // TODO: Does this still need $wgTitle? global $wgParser, $wgTitle; - // Currently unnecessary, code to act as a safeguard against any change in current behaviour of uselang breaks + // Currently unnecessary, code to act as a safeguard against any change in current behaviour of uselang $oldLang = null; if ( isset( $params['uselang'] ) && $params['uselang'] != $this->getContext()->getLanguage()->getCode() ) { $oldLang = $this->getContext()->getLanguage(); // Backup language diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php index 0509f1f8f4..275275e21f 100644 --- a/includes/api/ApiWatch.php +++ b/includes/api/ApiWatch.php @@ -50,6 +50,14 @@ class ApiWatch extends ApiBase { $res = array( 'title' => $title->getPrefixedText() ); + // Currently unnecessary, code to act as a safeguard against any change in current behaviour of uselang + // Copy from ApiParse + $oldLang = null; + if ( isset( $params['uselang'] ) && $params['uselang'] != $this->getContext()->getLanguage()->getCode() ) { + $oldLang = $this->getContext()->getLanguage(); // Backup language + $this->getContext()->setLanguage( Language::factory( $params['uselang'] ) ); + } + if ( $params['unwatch'] ) { $res['unwatched'] = ''; $res['message'] = $this->msg( 'removedwatchtext', $title->getPrefixedText() )->title( $title )->parseAsBlock(); @@ -59,6 +67,11 @@ class ApiWatch extends ApiBase { $res['message'] = $this->msg( 'addedwatchtext', $title->getPrefixedText() )->title( $title )->parseAsBlock(); $success = WatchAction::doWatch( $title, $user ); } + + if ( !is_null( $oldLang ) ) { + $this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang + } + if ( !$success ) { $this->dieUsageMsg( 'hookaborted' ); } @@ -88,6 +101,7 @@ class ApiWatch extends ApiBase { ApiBase::PARAM_REQUIRED => true ), 'unwatch' => false, + 'uselang' => null, 'token' => array( ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true @@ -99,6 +113,7 @@ class ApiWatch extends ApiBase { return array( 'title' => 'The page to (un)watch', 'unwatch' => 'If set the page will be unwatched rather than watched', + 'uselang' => 'Language to show the message in', 'token' => 'A token previously acquired via prop=info', ); } diff --git a/resources/mediawiki.api/mediawiki.api.watch.js b/resources/mediawiki.api/mediawiki.api.watch.js index d32344212e..6cbccbfc39 100644 --- a/resources/mediawiki.api/mediawiki.api.watch.js +++ b/resources/mediawiki.api/mediawiki.api.watch.js @@ -25,7 +25,7 @@ $.extend( mw.Api.prototype, { /** - * Convinience method for 'action=watch'. + * Convenience method for 'action=watch'. * * @param page {String|mw.Title} Full page name or instance of mw.Title * @param success {Function} Callback to which the watch object will be passed. @@ -38,7 +38,7 @@ return doWatchInternal.call( this, page, success, err ); }, /** - * Convinience method for 'action=watch&unwatch=1'. + * Convenience method for 'action=watch&unwatch=1'. * * @param page {String|mw.Title} Full page name or instance of mw.Title * @param success {Function} Callback to which the watch object will be passed. -- 2.20.1