From edb12d7aacc06ec054eeb21c5ea496d73beb4f90 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Thu, 3 Feb 2011 17:30:14 +0000 Subject: [PATCH] * Use wfMessage() instead of wfMsgGetKey() * Don't play with $wgLang, pass the Language object to the Message object * Bug fix: when 'enableparser' is passed without 'args', $1 is no longer replaced by an empty string (the default value on line 92 of the file was null instead of array(), making wfMsgExt() think that this was the value of $1 and thus this was replaced) --- includes/api/ApiQueryAllmessages.php | 50 ++++++++++++---------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/includes/api/ApiQueryAllmessages.php b/includes/api/ApiQueryAllmessages.php index d242299b80..9799c2c325 100644 --- a/includes/api/ApiQueryAllmessages.php +++ b/includes/api/ApiQueryAllmessages.php @@ -43,12 +43,11 @@ class ApiQueryAllmessages extends ApiQueryBase { public function execute() { $params = $this->extractRequestParams(); - global $wgLang; - - $oldLang = null; - if ( !is_null( $params['lang'] ) ) { - $oldLang = $wgLang; // Keep $wgLang for restore later - $wgLang = Language::factory( $params['lang'] ); + if ( is_null( $params['lang'] ) ) { + global $wgLang; + $langObj = $wgLang; + } else { + $langObj = Language::factory( $params['lang'] ); } $prop = array_flip( (array)$params['prop'] ); @@ -90,32 +89,29 @@ class ApiQueryAllmessages extends ApiQueryBase { if ( !$skip ) { $a = array( 'name' => $message ); - $args = null; + $args = array(); if ( isset( $params['args'] ) && count( $params['args'] ) != 0 ) { $args = $params['args']; } - // Check if the parser is enabled: - if ( $params['enableparser'] ) { - $msg = wfMsgExt( $message, array( 'parsemag' ), $args ); - } elseif ( $args ) { - $msgString = wfMsgGetKey( $message, true, false, false ); - $msg = wfMsgReplaceArgs( $msgString, $args ); - } else { - $msg = wfMsgGetKey( $message, true, false, false ); - } - if ( wfEmptyMsg( $message, $msg ) ) { + $msg = wfMessage( $message, $args )->inLanguage( $langObj ); + + if ( !$msg->exists() ) { $a['missing'] = ''; } else { - ApiResult::setContent( $a, $msg ); + // Check if the parser is enabled: + if ( $params['enableparser'] ) { + $msgString = $msg->text(); + } else { + $msgString = $msg->plain(); + } + ApiResult::setContent( $a, $msgString ); if ( isset( $prop['default'] ) ) { - $default = wfMsgGetKey( $message, false, false, false ); - if ( $default !== $msg ) { - if ( wfEmptyMsg( $message, $default ) ) { - $a['defaultmissing'] = ''; - } else { - $a['default'] = $default; - } + $default = wfMessage( $message )->inLanguage( $langObj )->useDatabase( false ); + if ( !$default->exists() ) { + $a['defaultmissing'] = ''; + } elseif ( $default->plain() != $msgString ) { + $a['default'] = $default->plain(); } } } @@ -127,10 +123,6 @@ class ApiQueryAllmessages extends ApiQueryBase { } } $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'message' ); - - if ( !is_null( $oldLang ) ) { - $wgLang = $oldLang; // Restore $oldLang - } } public function getCacheMode( $params ) { -- 2.20.1