From 475a1daa03da8308f7356ebf01026fc1843d9b95 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Mon, 3 Sep 2012 10:03:42 +0200 Subject: [PATCH] Replace some occurrences of wfMsg* by alternatives. Undeprecated wfMsgReplaceArgs. * wfMsgReplaceArgs isn't really i18n related. It just replaces text parts. * Updated language.txt. Now refers to mediawiki.org. * Removed deprecated Block::formatExpiry(). Merge Id7d057a4 first. * Reformatted weirdly formatted array in ApiBase.php. * Removed wfMsg() in RandomTest.php. Change-Id: Ied5cfda8fa5d9283dfeebdcb0e1af8453d47e7a9 --- docs/language.txt | 20 ++--------------- includes/Block.php | 35 ----------------------------- includes/EditPage.php | 2 +- includes/GlobalFunctions.php | 2 -- includes/OutputPage.php | 2 +- includes/WikiPage.php | 10 ++++++--- includes/api/ApiBase.php | 7 +++--- includes/installer/WebInstaller.php | 6 ++--- includes/normal/RandomTest.php | 4 ---- 9 files changed, 17 insertions(+), 71 deletions(-) diff --git a/docs/language.txt b/docs/language.txt index 1df9881005..42a6027947 100644 --- a/docs/language.txt +++ b/docs/language.txt @@ -1,21 +1,5 @@ language.txt -The Language object handles all readable text produced by the software. The most -used function is getMessage(), usually called with the wrapper function wfMsg() -which calls that method on the global language object. It just returns a piece -of text given a text key. It is recommended that you use each key only -once--bits of text in different contexts that happen to be identical in English -may not be in other languages, so it's better to add new keys than to reuse them -a lot. Likewise, if there is text that gets combined with things like names and -titles, it is better to put markers like "$1" inside a piece of text and use -str_replace() than to compose such messages in code, because their order may -change in other languages too. +The Language object handles all readable text produced by the software. -While the system is running, there will be one global language object, which -will be a subtype of Language. The methods in these objects will return the -native text requested if available, otherwise they fall back to sending English -text (which is why the LanguageEn object has no code at all--it just inherits -the English defaults of the Language base class). - -The names of the namespaces are also contained in the language object, though -the numbers are fixed. +See http://www.mediawiki.org/wiki/Localisation#General_use_.28for_developers.29 diff --git a/includes/Block.php b/includes/Block.php index 6e8f9f372a..732699dce6 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -1002,41 +1002,6 @@ class Block { return wfGetDB( DB_SLAVE )->getInfinity(); } - /** - * Convert a DB-encoded expiry into a real string that humans can read. - * - * @param $encoded_expiry String: Database encoded expiry time - * @return Html-escaped String - * @deprecated since 1.18; use $wgLang->formatExpiry() instead - */ - public static function formatExpiry( $encoded_expiry ) { - wfDeprecated( __METHOD__, '1.18' ); - - global $wgContLang; - static $msg = null; - - if ( is_null( $msg ) ) { - $msg = array(); - $keys = array( 'infiniteblock', 'expiringblock' ); - - foreach ( $keys as $key ) { - $msg[$key] = wfMessage( $key )->escaped(); - } - } - - $expiry = $wgContLang->formatExpiry( $encoded_expiry, TS_MW ); - if ( $expiry == wfGetDB( DB_SLAVE )->getInfinity() ) { - $expirystr = $msg['infiniteblock']; - } else { - global $wgLang; - $expiredatestr = htmlspecialchars( $wgLang->date( $expiry, true ) ); - $expiretimestr = htmlspecialchars( $wgLang->time( $expiry, true ) ); - $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array( $expiredatestr, $expiretimestr ) ); - } - - return $expirystr; - } - /** * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute * ("24 May 2034"), into an absolute timestamp we can put into the database. diff --git a/includes/EditPage.php b/includes/EditPage.php index f9bba19040..48beb9a20e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2459,7 +2459,7 @@ HTML wfRunHooks( 'EditPageCopyrightWarning', array( $title, &$copywarnMsg ) ); return "
\n" . - call_user_func_array( "wfMsgNoTrans", $copywarnMsg ) . "\n
"; + call_user_func_array( 'wfMessage', $copywarnMsg )->plain() . "\n"; } protected function showStandardInputs( &$tabindex = 2 ) { diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 0a6051801a..22415456d5 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1539,8 +1539,6 @@ function wfMsgGetKey( $key, $useDB = true, $langCode = false, $transform = true /** * Replace message parameter keys on the given formatted output. * - * @deprecated since 1.18 - * * @param $message String * @param $args Array * @return string diff --git a/includes/OutputPage.php b/includes/OutputPage.php index bc9eaa9a0c..9e39d4763d 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -3548,7 +3548,7 @@ $templates * * Is equivalent to: * - * $wgOut->addWikiText( "
\n" . wfMsgNoTrans( 'some-error' ) . "\n
" ); + * $wgOut->addWikiText( "
\n" . wfMessage( 'some-error' )->plain() . "\n
" ); * * The newline after opening div is needed in some wikitext. See bug 19226. * diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 10217672a4..74772f27d6 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -2406,9 +2406,9 @@ class WikiPage extends Page implements IDBAccessObject { $target = Revision::newFromId( $s->rev_id ); if ( empty( $summary ) ) { if ( $from == '' ) { // no public user name - $summary = wfMessage( 'revertpage-nouser' )->inContentLanguage()->text(); + $summary = wfMessage( 'revertpage-nouser' ); } else { - $summary = wfMessage( 'revertpage' )->inContentLanguage()->text(); + $summary = wfMessage( 'revertpage' ); } } @@ -2418,7 +2418,11 @@ class WikiPage extends Page implements IDBAccessObject { $wgContLang->timeanddate( wfTimestamp( TS_MW, $s->rev_timestamp ) ), $current->getId(), $wgContLang->timeanddate( $current->getTimestamp() ) ); - $summary = wfMsgReplaceArgs( $summary, $args ); + if( $summary instanceof Message ) { + $summary = $summary->params( $args )->inContentLanguage()->text(); + } else { + $summary = wfMsgReplaceArgs( $summary, $args ); + } # Truncate for whole multibyte characters. $summary = $wgContLang->truncate( $summary, 255 ); diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 1e627663ee..875a381425 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -1401,10 +1401,9 @@ abstract class ApiBase extends ContextSource { } if ( isset( self::$messageMap[$key] ) ) { - return array( 'code' => - wfMsgReplaceArgs( self::$messageMap[$key]['code'], $error ), - 'info' => - wfMsgReplaceArgs( self::$messageMap[$key]['info'], $error ) + return array( + 'code' => wfMsgReplaceArgs( self::$messageMap[$key]['code'], $error ), + 'info' => wfMsgReplaceArgs( self::$messageMap[$key]['info'], $error ) ); } diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index 0d5ea576a6..2f46ff0bd2 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -376,7 +376,7 @@ class WebInstaller extends Installer { $args = func_get_args(); array_shift( $args ); $args = array_map( 'htmlspecialchars', $args ); - $msg = wfMsgReal( $msg, $args, false, false, false ); + $msg = wfMessage( $msg, $args )->useDatabase( false )->plain(); $this->output->addHTML( $this->getErrorBox( $msg ) ); } @@ -655,7 +655,7 @@ class WebInstaller extends Installer { $args = func_get_args(); array_shift( $args ); $args = array_map( 'htmlspecialchars', $args ); - $text = wfMsgReal( $msg, $args, false, false, false ); + $text = wfMessage( $msg, $args )->useDatabase( false )->plain(); $html = $this->parse( $text, true ); return "
\n" . @@ -685,7 +685,7 @@ class WebInstaller extends Installer { $args = func_get_args(); array_shift( $args ); $html = '
' . - $this->parse( wfMsgReal( $msg, $args, false, false, false ) ) . + $this->parse( wfMessage( $msg, $args )->useDatabase( false )->plain() ) . "
\n"; $this->output->addHTML( $html ); } diff --git a/includes/normal/RandomTest.php b/includes/normal/RandomTest.php index d96cb09a1c..23471e94e1 100644 --- a/includes/normal/RandomTest.php +++ b/includes/normal/RandomTest.php @@ -57,10 +57,6 @@ function donorm( $str ) { return rtrim( utf8_normalize( $str . "\x01", UtfNormal::UNORM_NFC ), "\x01" ); } -function wfMsg($x) { - return $x; -} - function showDiffs( $a, $b ) { $ota = explode( "\n", str_replace( "\r\n", "\n", $a ) ); $nta = explode( "\n", str_replace( "\r\n", "\n", $b ) ); -- 2.20.1