Replace wfMsgReplaceArgs by RawMessage
authorumherirrender <umherirrender_de.wp@web.de>
Mon, 29 Sep 2014 17:23:19 +0000 (19:23 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Mon, 29 Sep 2014 17:23:19 +0000 (19:23 +0200)
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
includes/api/ApiBase.php
includes/api/ApiMain.php
includes/db/DatabaseError.php
includes/exception/MWException.php
includes/page/WikiPage.php

index 3306acd..a2160fb 100644 (file)
@@ -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 ) {
index 7bc3f71..c80d903 100644 (file)
@@ -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()
                        );
                }
 
index bd20b14..d5c1c47 100644 (file)
@@ -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";
                }
 
index 2dfec41..f48458a 100644 (file)
@@ -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();
        }
 
        /**
index 074128f..0528d69 100644 (file)
@@ -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();
        }
 
        /**
index 9ade16e..f27c27a 100644 (file)
@@ -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 );