From 6abefb274ff9cd86f75d5d13f713e1971e1b27ce Mon Sep 17 00:00:00 2001 From: umherirrender Date: Mon, 29 Sep 2014 19:23:19 +0200 Subject: [PATCH] Replace wfMsgReplaceArgs by RawMessage The replace of $n params can also be done using the Message class. In case there are no message keys, the RawMessage class is used. Deprecated wfMsgReplaceArgs, but added no warning, because it is used in some extensions and from deprecated functions Change-Id: I62091b09e4490e59ed7258566e0ddf2f8ee799d2 --- includes/GlobalFunctions.php | 1 + includes/api/ApiBase.php | 6 ++++-- includes/api/ApiMain.php | 3 ++- includes/db/DatabaseError.php | 6 ++++-- includes/exception/MWException.php | 6 ++++-- includes/page/WikiPage.php | 7 +++---- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3306acda3e..a2160fb478 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1602,6 +1602,7 @@ function wfMsgGetKey( $key, $useDB = true, $langCode = false, $transform = true * @param string $message * @param array $args * @return string + * @deprecated since 1.25 Use the RawMessage class * @private */ function wfMsgReplaceArgs( $message, $args ) { diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 7bc3f71f4f..c80d90351c 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -1791,9 +1791,11 @@ abstract class ApiBase extends ContextSource { } if ( isset( self::$messageMap[$key] ) ) { + $codeMsg = new RawMessage( self::$messageMap[$key]['code'] ); + $infoMsg = new RawMessage( self::$messageMap[$key]['info'] ); return array( - 'code' => wfMsgReplaceArgs( self::$messageMap[$key]['code'], $error ), - 'info' => wfMsgReplaceArgs( self::$messageMap[$key]['info'], $error ) + 'code' => $codeMsg->params( $error )->text(), + 'info' => $infoMsg->params( $error )->text() ); } diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index bd20b140f6..d5c1c475ad 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1306,7 +1306,8 @@ class ApiMain extends ApiBase { $msg .= "\n$astriks Permissions $astriks\n\n"; foreach ( self::$mRights as $right => $rightMsg ) { $groups = User::getGroupsWithPermission( $right ); - $msg .= "* " . $right . " *\n " . wfMsgReplaceArgs( $rightMsg['msg'], $rightMsg['params'] ) . + $rightRawMsg = new RawMessage( $rightMsg['msg'] ); + $msg .= "* " . $right . " *\n " . $rightRawMsg->params( $rightMsg['params'] )->text() . "\nGranted to:\n " . str_replace( '*', 'all', implode( ', ', $groups ) ) . "\n\n"; } diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index 2dfec41dd7..f48458a824 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -136,10 +136,12 @@ class DBConnectionError extends DBExpectedError { $args = array_slice( func_get_args(), 2 ); if ( $this->useMessageCache() ) { - return wfMessage( $key, $args )->useDatabase( false )->text(); + $msg = wfMessage( $key )->useDatabase( false ); } else { - return wfMsgReplaceArgs( $fallback, $args ); + $msg = new RawMessage( $fallback ); } + + return $msg->params( $args )->text(); } /** diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php index 074128f889..0528d69d44 100644 --- a/includes/exception/MWException.php +++ b/includes/exception/MWException.php @@ -117,10 +117,12 @@ class MWException extends Exception { $args = array_slice( func_get_args(), 2 ); if ( $this->useMessageCache() ) { - return wfMessage( $key, $args )->text(); + $msg = wfMessage( $key ); } else { - return wfMsgReplaceArgs( $fallback, $args ); + $msg = new RawMessage( $fallback ); } + + return $msg->params( $args )->text(); } /** diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 9ade16e5af..f27c27a47f 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -3090,11 +3090,10 @@ class WikiPage implements Page, IDBAccessObject { $wgContLang->timeanddate( wfTimestamp( TS_MW, $s->rev_timestamp ) ), $current->getId(), $wgContLang->timeanddate( $current->getTimestamp() ) ); - if ( $summary instanceof Message ) { - $summary = $summary->params( $args )->inContentLanguage()->text(); - } else { - $summary = wfMsgReplaceArgs( $summary, $args ); + if ( !$summary instanceof Message ) { + $summary = new RawMessage( $summary ); } + $summary = $summary->params( $args )->inContentLanguage()->text(); // Trim spaces on user supplied text $summary = trim( $summary ); -- 2.20.1