I have an app that depends on a particular system message that might not exist yet.
What is the correct way to accomplish the following logic in an extension?
if (!wfMsg('my-message')) { set 'my-message' to a default value } $wgOut->addWikiText(wfMsg('my-message'));
Thanks, DanB
--------------------- Confidentiality note The information in this email and any attachment may contain confidential and proprietary information of VistaPrint and/or its affiliates and may be privileged or otherwise protected from disclosure. If you are not the intended recipient, you are hereby notified that any review, reliance or distribution by others or forwarding without express permission is strictly prohibited and may cause liability. In case you have received this message due to an error in transmission, please notify the sender immediately and delete this email and any attachment from your system. ---------------------
On 27/06/07, Daniel Barrett danb@vistaprint.com wrote:
I have an app that depends on a particular system message that might not exist yet.
What is the correct way to accomplish the following logic in an extension?
Ordinarily, you would write code that populates the MessageCache such that it is safe to assume a message exists. There are a large number of extensions in Subversion which can provide examples for doing this.
In some cases, it might be desirable to alter the behaviour depending upon if the message does exist. The usual method for checking this is wfEmptyMsg(), e.g.
$text = wfMsg( 'blah' ); if( wfEmptyMsg( 'blah', $text ) ) { // ...
Rob Church
--- Daniel Barrett danb@VistaPrint.com wrote:
I have an app that depends on a particular system message that might not exist yet.
What is the correct way to accomplish the following logic in an extension?
if (!wfMsg('my-message')) { set 'my-message' to a default value } $wgOut->addWikiText(wfMsg('my-message'));
I did it like this (see http://www.mediawiki.org/wiki/Extension:UnitsFormatter). In the extension constructor:
private $messageList = array( 'en' => array( 'tog-preferinput' => 'Prefer the article's units', 'tog-prefermetric' => 'Prefer metric units', . . . ), );
/* * Construct the extension and install it as a parser hook. */ public function __construct() { global $wgMessageCache; foreach ($this->messageList as $lang => $messages) $wgMessageCache->addMessages($messages, $lang); }
This sets the default value for all your messages when the extension starts. They can still be customised in the wiki by editing MediaWiki:foo.
Ian
Ah, now I finally understand the purpose of the ".i18n.php" file used by Special pages. That's exactly the kind of array it defines. Thanks Ian.
DanB
-----Original Message----- Ian Smith wrote
private $messageList = array( 'en' => array( 'tog-preferinput' => 'Prefer the article's units', 'tog-prefermetric' => 'Prefer metric units', . . . ), );
--------------------- Confidentiality note The information in this email and any attachment may contain confidential and proprietary information of VistaPrint and/or its affiliates and may be privileged or otherwise protected from disclosure. If you are not the intended recipient, you are hereby notified that any review, reliance or distribution by others or forwarding without express permission is strictly prohibited and may cause liability. In case you have received this message due to an error in transmission, please notify the sender immediately and delete this email and any attachment from your system. ---------------------
mediawiki-l@lists.wikimedia.org