r110060 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110059‎ | r110060 | r110061 >
Date:14:55, 26 January 2012
Author:hashar
Status:ok
Tags:
Comment:
update Message class doc

Ping r110054
Modified paths:
  • /trunk/phase3/includes/Message.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Message.php
@@ -1,78 +1,133 @@
22 <?php
33 /**
4 - * This class provides methods for fetching interface messages and
5 - * processing them into variety of formats that are needed in MediaWiki.
 4+ * The Message class provides methods which fullfil two basic services:
 5+ * - fetching interface messages
 6+ * - processing messages into a variety of formats
67 *
7 - * It is intented to replace the old wfMsg* functions that over time grew
8 - * unusable.
9 - * @see https://www.mediawiki.org/wiki/New_messages_API for
10 - * equivalence between old and new functions.
 8+ * First implemented with MediaWiki 1.17, the Message class is intented to
 9+ * replace the old wfMsg* functions that over time grew unusable.
 10+ * @see https://www.mediawiki.org/wiki/New_messages_API for equivalences
 11+ * between old and new functions.
1112 *
12 - * Below, you will find several examples of wfMessage() usage.
 13+ * You should use the wfMessage() global function which acts as a wrapper for
 14+ * the Message class. The wrapper let you pass parameters as arguments.
1315 *
 16+ * The most basic usage cases would be:
1417 *
15 - * Fetching a message text for interface message
1618 * @code
17 - * $button = Xml::button( wfMessage( 'submit' )->text() );
 19+ * // Initialize a Message object using the 'some_key' message key
 20+ * $message = wfMessage( 'some_key' );
 21+ *
 22+ * // Using two parameters those values are strings 'value1' and 'value2':
 23+ * $message = wfMessage( 'some_key',
 24+ * 'value1', 'value2'
 25+ * );
1826 * @endcode
1927 *
20 - * Messages can have parameters:
 28+ * @section message_global_fn Global function wrapper:
2129 *
 30+ * Since wfMessage() returns a Message instance, you can chain its call with
 31+ * a method. Some of them return a Message instance too so you can chain them.
 32+ * You will find below several examples of wfMessage() usage.
 33+ *
 34+ * Fetching a message text for interface message:
 35+ *
2236 * @code
23 - * wfMessage( 'welcome-to' )->params( $wgSitename )->text();
 37+ * $button = Xml::button(
 38+ * wfMessage( 'submit' )->text()
 39+ * );
2440 * @endcode
2541 *
26 - * {{GRAMMAR}} and friends work correctly
 42+ * A Message instance can be passed parameters after it has been constructed,
 43+ * use the params() method to do so:
 44+ *
2745 * @code
28 - * wfMessage( 'are-friends', $user, $friend );
29 - * wfMessage( 'bad-message' )->rawParams( '<script>...</script>' )->escaped();
 46+ * wfMessage( 'welcome-to' )
 47+ * ->params( $wgSitename )
 48+ * ->text();
3049 * @endcode
3150 *
32 - * Sometimes the message text ends up in the database, so content language is needed.
 51+ * {{GRAMMAR}} and friends work correctly:
 52+ *
3353 * @code
34 - * wfMessage( 'file-log', $user, $filename )->inContentLanguage()->text()
35 - * </pre>
 54+ * wfMessage( 'are-friends',
 55+ * $user, $friend
 56+ * );
 57+ * wfMessage( 'bad-message' )
 58+ * ->rawParams( '<script>...</script>' )
 59+ * ->escaped();
3660 * @endcode
3761 *
 62+ * @section message_language Changing language:
 63+ *
 64+ * Messages can be requested in a different language or in whatever current
 65+ * content language is being used. The methods are:
 66+ * - Message->inContentLanguage()
 67+ * - Message->inLanguage()
 68+ *
 69+ * Sometimes the message text ends up in the database, so content language is
 70+ * needed:
 71+ *
 72+ * @code
 73+ * wfMessage( 'file-log',
 74+ * $user, $filename
 75+ * )->inContentLanguage()->text();
 76+ * @endcode
 77+ *
3878 * Checking whether a message exists:
 79+ *
3980 * @code
4081 * wfMessage( 'mysterious-message' )->exists()
 82+ * // returns a boolean whether the 'mysterious-message' key exist.
4183 * @endcode
4284 *
4385 * If you want to use a different language:
 86+ *
4487 * @code
45 - * wfMessage( 'email-header' )->inLanguage( $user->getOption( 'language' ) )->plain()
 88+ * $userLanguage = $user->getOption( 'language' );
 89+ * wfMessage( 'email-header' )
 90+ * ->inLanguage( $userLanguage )
 91+ * ->plain();
4692 * @endcode
4793 *
4894 * @note You cannot parse the text except in the content or interface
4995 * @note languages
5096 *
51 - * Comparison with old wfMsg* functions:
 97+ * @section message_compare_old Comparison with old wfMsg* functions:
5298 *
53 - * Use full parsing.
 99+ * Use full parsing:
54100 *
55101 * @code
 102+ * // old style:
56103 * wfMsgExt( 'key', array( 'parseinline' ), 'apple' );
57 - * === wfMessage( 'key', 'apple' )->parse();
 104+ * // new style:
 105+ * wfMessage( 'key', 'apple' )->parse();
58106 * @endcode
59107 *
60 - * Parseinline is used because it is more useful when pre-building html.
 108+ * Parseinline is used because it is more useful when pre-building HTML.
61109 * In normal use it is better to use OutputPage::(add|wrap)WikiMsg.
62110 *
63 - * Places where html cannot be used. {{-transformation is done.
 111+ * Places where HTML cannot be used. {{-transformation is done.
64112 * @code
 113+ * // old style:
65114 * wfMsgExt( 'key', array( 'parsemag' ), 'apple', 'pear' );
66 - * === wfMessage( 'key', 'apple', 'pear' )->text();
 115+ * // new style:
 116+ * wfMessage( 'key', 'apple', 'pear' )->text();
67117 * @endcode
68118 *
69 - * Shortcut for escaping the message too, similar to wfMsgHTML, but
 119+ * Shortcut for escaping the message too, similar to wfMsgHTML(), but
70120 * parameters are not replaced after escaping by default.
71121 * @code
72 - * $escaped = wfMessage( 'key' )->rawParams( 'apple' )->escaped();
 122+ * $escaped = wfMessage( 'key' )
 123+ * ->rawParams( 'apple' )
 124+ * ->escaped();
73125 * @endcode
74126 *
 127+ * @section message_appendix Appendix:
 128+ *
75129 * @todo
76130 * - test, can we have tests?
 131+ * - this documentation needs to be extended
77132 *
78133 * @see https://www.mediawiki.org/wiki/WfMessage()
79134 * @see https://www.mediawiki.org/wiki/New_messages_API

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r110054enhance doxygen generation for Message classhashar11:34, 26 January 2012

Status & tagging log