[Mediawiki-l] The opposite of wfMsg()?

Ian Smith johantheghost at yahoo.com
Wed Jun 27 15:24:52 UTC 2007


--- Daniel Barrett <danb at 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





More information about the MediaWiki-l mailing list