Extension:UserMessageFunction
この拡張機能ウィキページは、拡張機能のソースコードを含んでいます。 このコードが未検証であったり不正に変更されていたりするおそれがあることにご注意ください。 セキュリティ ホール、もう互換性がなく古くなったインターフェイス、などを含んでいるおそれがあります。 注記: translatewiki.net は、この拡張機能の地域化 (ローカライズ) の更新を提供しません。 |
現在、この拡張機能は積極的な保守が行われていません! それでも機能する可能性はありますが、バグ報告や機能の要望は無視される可能性が高くなります。 |
![]() リリースの状態: 保守されていない |
|
---|---|
実装 | パーサー関数 |
説明 | Provides multilingual user messages |
作者 | dick6809トーク |
MediaWiki | 1.16+ |
ライセンス | GNU 一般公衆利用許諾書 2.0 |
ダウンロード | 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.
使用法
{{#message: キーワード | 辞書 | synonym id | anchor | format = lc | lcfirst | uc | ucfirst | lang = 言語コード | xx = language specific synomym id }}
Usage | 利用者言語 | メッセージ検索パス | 説明 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{{#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) |
インストール
- 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.
設定
The table below explains UserMessageFunction settings and their default values.
グローバル変数 | 既定値 | 説明 |
---|---|---|
$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. |
要件
The UserMessageFunction extension requires
- MediaWiki 1.16+
- Extension:ParserFunctions
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.
コード
<?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 );
}
関連項目
- Semantic MediaWiki
- Semantic Forms
- LangSwitch - A template that this function is based on.