From: Niklas Laxström Date: Thu, 2 Sep 2010 17:12:56 +0000 (+0000) Subject: One step forward with the Message class. X-Git-Tag: 1.31.0-rc.0~35226 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=ab9595e30426e231f23bd90104634c1e7878b214;p=lhc%2Fweb%2Fwiklou.git One step forward with the Message class. wfMessage can be used now. Later the old wfMsg* function will be changed to just wrappers over the new class. --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index a3b9a42c30..c30b783d1a 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -598,6 +598,21 @@ function wfUILang() { return wfGetLangObj( !$wgBetterDirectionality ); } +/** + * This is the new function for getting translated interface messages. + * See the Message class for documentation how to use them. + * The intention is that this function replaces all old wfMsg* functions. + * @param $key \string Message key. + * Varargs: normal message parameters. + * @return \type{Message} + * @since 1.17 + */ +function wfMessage( $key /*...*/) { + $params = func_get_args(); + array_shift( $params ); + return new Message( $key, $params ); +} + /** * Get a message from anywhere, for the current user language. * diff --git a/includes/Message.php b/includes/Message.php index 0f6437a38c..f2ff88b364 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -1,7 +1,5 @@ text() ); + * $button = Xml::button( wfMessage( 'submit' )->text() ); * * Messages can have parameters: - * Message::key( 'welcome-to' )->params( $wgSitename )->text(); + * wfMessage( 'welcome-to' )->params( $wgSitename )->text(); * {{GRAMMAR}} and friends work correctly - * Message::key( 'are-friends', $user, $friend ); - * Message::key( 'bad-message' )->rawParams( '' )->escaped(); + * wfMessage( 'are-friends', $user, $friend ); + * wfMessage( 'bad-message' )->rawParams( '' )->escaped(); * * Sometimes the message text ends up in the database, so content language is needed. - * Message::key( 'file-log' )->params( $user, $filename )->inContentLanguage()->text() + * wfMessage( 'file-log', $user, $filename )->inContentLanguage()->text() * * Checking if message exists: - * Message::key( 'mysterious-message' )->exists() + * wfMessage( 'mysterious-message' )->exists() * * If you want to use a different language: - * Message::key( 'email-header' )->inLanguage( $user->getOption( 'language' ) )->plain() + * wfMessage( 'email-header' )->inLanguage( $user->getOption( 'language' ) )->plain() * Note that you cannot parse the text except in the content or interface * languages * @@ -35,27 +33,27 @@ * * Use full parsing. * wfMsgExt( 'key', array( 'parseinline' ), 'apple' ); - * === Message::key( 'key', 'apple' )->parse(); + * === wfMessage( 'key', 'apple' )->parse(); * * Parseinline is used because it is more useful when pre-building html. * In normal use it is better to use OutputPage::(add|wrap)WikiMsg. * * Places where html cannot be used. {{-transformation is done. * wfMsgExt( 'key', array( 'parsemag' ), 'apple', 'pear' ); - * === Message::key( 'key', 'apple', 'pear' )->text(); + * === wfMessage( 'key', 'apple', 'pear' )->text(); * * * Shortcut for escaping the message too, similar to wfMsgHTML, but * parameters are not replaced after escaping by default. - * $escaped = Message::key( 'key' )->rawParams( 'apple' )->escaped(); + * $escaped = wfMessage( 'key' )->rawParams( 'apple' )->escaped(); * * * TODO: * - test, can we have tests? * - sort out the details marked with fixme - * - should we have _m() or similar global wrapper? * * @since 1.17 + * @author Niklas Laxström */ class Message { /** @@ -115,7 +113,7 @@ class Message { * @param Varargs: parameters as Strings * @return Message: $this */ - public static function key( $key /*...*/ ) { + public static function newFromKey( $key /*...*/ ) { $params = func_get_args(); array_shift( $params ); return new self( $key, $params );