Erweiterung:UserMessageFunction
![]() | Diese Erweiterung speichert ihren Quellcode auf einer Wikiseite. Sei bewusst, das dieser Code nicht gesichtet oder böswillig verändert wurde. Diese können Sicherheitslöcher, veraltete Oberflächen, die nicht mehr kompatibel sind usw. enthalten. Hinweis: Keine Lokalisierungsaktualisierungen werden von translatewiki.net für diese Erweiterung angeboten. |
![]() | Diese Erweiterung wird derzeit nicht aktiv gepflegt! Obwohl sie möglicherweise immer noch funktioniert, werden Fehlerberichte oder Featureanfragen höchstwahrscheinlich ignoriert. |
![]() Freigabestatus: ohne Wartung |
|
---|---|
Einbindung | Parser-Funktion |
Beschreibung | Provides multilingual user messages |
Autor(en) | dick6809Diskussion |
MediaWiki | 1.16+ |
Lizenz | GNU General Public License 2.0 |
Herunterladen | Subversion |
The 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 {{int:}}
, but it is available not only for administrators but for users.
Verwendung
{{#message: keyword | dictionary | synonym id | anchor | format = lc | lcfirst | uc | ucfirst | lang = language code | xx = language specific synomym id }}
Usage | User lang. |
Message search path | Beschreibung | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{{#message:key}}
|
en |
1. Message:Msg/key/en |
It works in a manner similar to the magicword Please note that the keywords are case sensitive. | ||||||||||||
de |
1. Message:Msg/key/de | ||||||||||||||
{{#message:key|dict}}
|
xx |
1. Message:Dict/key/xx |
You may use two or more dictionaries. They can be arranged in a hierarchical page structure, e.g. | ||||||||||||
{{#message:key|alt:dict}}
|
xx |
1. Alt:Dict/key/xx |
You may assign dictionaries in any namespace. | ||||||||||||
{{#message:key||id}}
|
xx |
1. Message:Msg/key/id/xx |
Optional parameter
| ||||||||||||
|
en |
1. Message:Msg/key/de |
Optional parameter | ||||||||||||
|
en |
1. Message:Msg/key/en |
Optional parameter
| ||||||||||||
de |
1. Message:Msg/key/2/de | ||||||||||||||
fr |
1. Message:Msg/key/3/fr | ||||||||||||||
|
Optional parameter == {{#message:Chapter 1|anchor}} == would be displaied as
Click [[#Chapter 1|here]]. | ||||||||||||||
|
Optional parameter format can format message text. For example;
| ||||||||||||||
{{#message:key}}
|
simple | 1. Message:Msg/key
|
Language [[Message:Msg/key|key]] Honestly this feature is slightly tricky but useful. Please note that any links whiches contain Click [[MediaWiki|{{#message:here}}]]. → Click here. (in English) |
Installation
- Copy php code below to
$IP/extensions/UserMessageFunction/UserMessageFunction.php
. - 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.
Konfiguration
The table below explains UserMessageFunction settings and their default values.
Global variable | Standardwert | Beschreibung |
---|---|---|
$wgUMFEnableAnnotation | false | If it set to true and Semantic MediaWiki extension has been installed, UserMessageFunction produces semantic annotations for cross-reference between wiki pages and dictionaries. For example, the code below in each message key definition pages provides the list of all pages whiches consults this page.
{{ask: [[message link::{{FULLPAGENAME}}]] | format = ul }} |
$wgUMFLinkProperty | message link | You may configure this variable to change the semantic property name of semantic annotations above. |
$wgUMFDefaultNamespace | Message | You may configure this variable to change default namespace of user messages. |
$wgUMFDefaultDictionary | Msg | You may configure this variable to change default dictionary path. |
Voraussetzungen
The UserMessageFunction extension requires
- MediaWiki 1.16+
- Erweiterung:ParserFunctions
It should work on earlier versions of MediaWiki but they doesn't validated yet. Your feedback is appreciated.
Erweiterung: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
<?php
#
# $Id: UserMessageFunction.php 8 2011-09-05 18:06:10Z dick6809 $
#
$wgExtensionCredits['parserhook'][] = array(
'path' => __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",
);
$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 = "{{{$val}}}";
break;
}
}
# if message page doesn't exist
if ( empty( $output ) ) {
$output = $word;
}
# text format option
if ( !empty( $opts['format'] ) ) {
$output = "{{{$opts['format']}:$output}}";
}
# debug option
if ( $lang == '/simple' ) {
$output = "[[$dict$word|[$output]]]";
}
# anchor option
if ( !empty( $opts['anchor'] ) ) {
$output .= "<span id=\"{{anchorencode:{$word}}}\"></span>";
}
# add semantic annotation
if ( $wgUMFEnableAnnotations ) {
$output .= "{{#set:{$wgUMFLinkProperty}={$dict}{$word}}}";
}
return array( $output, 'noparse' => false );
}
Siehe auch
- Erweiterung:Semantic MediaWiki
- Semantic Forms
- LangSwitch - A template that this function is based on.