Extension:UserMessageFunction

UserMessageFunction extension provides a method to present a string of text selected from a set of translation pages in the user language which is set in the user's preferences. It works in a manner similar to the magicword  , but it is available not only for administrators but for users.

Installation
  Copy php code below to .  Configure LocalSettings.php to add new namespace for user messages according to Manual:Using custom namespaces as below. define( 'NS_MESSAGE', 120 ); # set the appropriate namespace number for your wiki. $wgExtraNamespaces[NS_MESSAGE]  = 'Message'; $wgExtraNamespaces[NS_MESSAGE+1] = 'Message_talk'; $wgNamespacesWithSubpages[NS_MESSAGE] = true;   Add the following line to the bottom of LocalSetting.php.

If Semantic-MediaWiki extension has been installed: require_once( "$IP/extensions/UserMessageFunction/UserMessageFunction.php" ); $wgUMFEnableAnnotation = true; If Semantic-MediaWiki extension has not been installed: require_once( "$IP/extensions/UserMessageFunction/UserMessageFunction.php" );   Installation can now be verified through Special:Version of your wiki. 

Configuration
The table below explains UserMessageFunction settings and their default values.

Requirements
The UserMessageFunction extension requires
 * MediaWiki 1.16 or above
 * ParserFunctions extension

It should work on earlier versions of MediaWiki but they doesn't validated yet. Your feedback is appreciated.

Semantic MediaWiki and Semantic Forms extensions are not essential, but recommended strongly to manage messages. You can see a case study of dictionaries on our development site.

Code
 __FILE__,	'name'			=> "UserMessageFucntion",	'description'	=> "A parser function to handle purulilingual user messages",	'version'		=> 0.01,	'author'		=> "Kazuhiro Kawaguchi",	'url'			=> "http://www.mediawiki.org/w/index.php?title=Manual:Parser_functions", );
 * 1) $Id: UserMessageFunction.php 8 2011-09-05 18:06:10Z dick6809 $
 * 1) $Id: UserMessageFunction.php 8 2011-09-05 18:06:10Z dick6809 $

$wgUMFDefaultNamespace		= 'Message'; $wgUMFDefaultDictionary		= 'Msg'; $wgUMFLinkProperty			= 'Message link'; $wgUMFEnableAnnotations		= false;

$wgHooks['ParserFirstCallInit'][]	= 'efUserMessageParserFunction_Setup'; $wgHooks['LanguageGetMagic'][]		= 'efUserMessageParserFunction_Magic';

function efUserMessageParserFunction_Setup( &$parser ) { $parser->setFunctionHook( 'message', 'efUserMessageParserFunction_Render' ); return true; }

function efUserMessageParserFunction_Magic( &$magicWords, $langCode ) { $magicWords['message'] = array( 1, 'message' ); return true; }

function efUserMessageParserFunction_Render( &$parser ) { global $wgRequest, 	$wgLang; global $wgUMFDefaultNamespace; global $wgUMFDefaultDictionary; global $wgUMFLinkProperty; global $wgUMFEnableAnnotations;

$args = func_get_args; $opts = array;

array_shift( $args ); $word = array_shift( $args );

# parse option parameters foreach( $args as $key => $val ) { $parts = array_map( 'trim', explode( '=', $val, 2 ) ); if ( count( $parts ) == 2 ) { $opts[$parts[0]] = $parts[1]; unset( $args[$key] ); }		elseif ( $val == 'anchor' ) { $opts['anchor'] = true; unset( $args[$key] ); }	}

# parse dictionary $dict = array_shift( $args ); if ( empty( $dict ) ) { $dict = $wgUMFDefaultDictionary; }	if ( strpos( $dict, ':' ) === false ) { $dict = "$wgUMFDefaultNamespace:$dict"; }

# parse language if ( empty( $opts['lang'] ) ) { $opts['lang'] = $wgRequest->wasPosted( 'uselang' ) ? $wgRequest->getText( 'uselang' ) : $lang = $wgLang->getCode; }	$lang = $opts['lang'];

# parse synonym id	$syno = array_shift( $args ); if ( !empty( $opts[$lang] ) ) { $syno = $opts[$lang]; }

# add subpage delimiters if ( strpos( $dict, ':' ) + 1 != strlen( $dict) ) { $dict .= '/'; }	if ( !empty( $syno ) ) { $syno = "/$syno"; }	if ( !empty( $lang ) ) { $lang = "/$lang"; }

# search message pages foreach( array( "$dict$word$syno$lang", "$dict$word$lang", "$dict$word$syno", "$dict$word" ) as $val ) { if ( Title::newFromText( $val )->exists ) { $output = ""; break; }	}

# if message page doesn't exist if ( empty( $output ) ) { $output = $word; }

# text format option if ( !empty( $opts['format'] ) ) { $output = ""; }

# debug option if ( $lang == '/simple' ) { $output = "&#91;$output&#93;"; }

# anchor option if ( !empty( $opts['anchor'] ) ) { $output .= " "; }

# add semantic annotation if ( $wgUMFEnableAnnotations ) { $output .= ""; }

return array( $output, 'noparse' => false ); }