Merge "Implement static public Parser::getExternalLinkRel"
[lhc/web/wiklou.git] / includes / api / ApiWatch.php
index 0509f1f..275275e 100644 (file)
@@ -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',
                );
        }