Extension:UserFunctions

From mediawiki.org
This page is a translated version of the page Extension:UserFunctions and the translation is 54% complete.
MediaWiki 拡張機能マニュアル
UserFunctions
リリースの状態: 安定
実装 パーサー関数
説明 現在の利用者で発動するパーサー関数のセットを提供する
作者
最新バージョン 2.8.1 (2022-07-20)
MediaWiki 1.35+
PHP 7.2+
データベースの変更 いいえ
Composer mediawiki/user-functions
ライセンス GNU 一般公衆利用許諾書 2.0 以降
ダウンロード
sandbox.semantic-mediawiki.org

  • $wgUFEnabledPersonalDataFunctions
  • $wgUFAllowedNamespaces
  • $wgUFEnableSpecialContexts
Quarterly downloads 30 (Ranked 115th)
translatewiki.net で翻訳を利用できる場合は、UserFunctions 拡張機能の翻訳にご協力ください

UserFunctions拡張機能は、現在の利用者で発動する一連の動的パーサー関数を提供します。

使用法

既定では、関数は NS_MEDIAWIKI 名前空間でのみ有効です。他の名前空間で有効にするには下記の例を参照してください。
これらの機能をウィキのサイドバー内で使用する場合、$wgEnableSidebarCache = true; は設定できません。

以下の4つの機能は常時使用可能です。

  • {{#ifanon:then|else}}
現在の利用者が匿名かどうかを確認する。
  • {{#ifblocked:then|else}}
現在の利用者がブロックされているかどうかを確認する。
  • {{#ifsysop:then|else}}
現在の利用者がsysopであるかどうかを確認する。
  • {{#ifingroup:group|then|else}}
現在の利用者が"group"グループのメンバーであるかどうかを確認する。 複数のグループにもチェックを入れることができます。
{{#ifingroup:group1, group2, group3|then|else}}

以下の5つの個人データ関数は、デフォルトで無効になっています(有効にする方法は、#インストールを参照してください)。

以下に説明する機能を個人データ関数と呼びます。 メールアドレスや本名など、利用者の個人情報の一部が流出する可能性があります。


よく分からない場合は、これを使用しないでください
  • {{#realname:alt}}
現在の利用者の本名を返します。 利用者がログインしていない場合、この関数は与えられた代替テキストを返し、代替テキストが設定されていない場合は利用者IPを返します。
  • {{#username:alt}}
現在の利用者名を返します。 利用者がログインしていない場合、この関数は与えられた代替テキストを返し、代替テキストが設定されていない場合は利用者IPを返します。
  • {{#useremail:alt}}
現在の利用者のメールアドレスを返します。 利用者がログインしていない場合、この関数は与えられた代替テキストを返し、代替テキストが設定されていない場合は利用者IPを返します。
  • {{#nickname:alt}}
現在の利用者のニックネームを返します。 利用者にニックネームがない場合は、利用者名を返します。 利用者がログインしていない場合、この関数は与えられた代替テキストを返し、代替テキストが設定されていない場合は利用者IPを返します。
  • {{#ip:}}
現在の利用者のIPアドレスを返します。

インストール

  • ダウンロードして、ファイルをextensions/フォルダー内のUserFunctionsという名前のディレクトリ内に配置します。
    開発者とコード寄稿者は、上記の代わりに以下を使用してGitからインストールします:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/UserFunctions
  • 以下のコードを LocalSettings.php ファイルの末尾に追加します:
    wfLoadExtension( 'UserFunctions' );
    
  • もし、#realname, #username, #useremail, #nickname, #ip のいずれかの関数を使いたい場合は、その行のすぐ後に以下を追加してください。
    $wgUFEnabledPersonalDataFunctions = [
    	'ip',
    	'nickname',
    	'realname',
    	'useremail',
    	'username',
    ];
    
If you are using an older version of the extension, the functions were included in bulk via: $wgUFEnablePersonalDataFunctions = true;
  • If you want to enable functions in other namespaces apart from NS_MEDIAWIKI (default), follow the model of some of the examples below.
  • Yes 完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。

MediaWiki 1.35以前を稼働させている利用者へ:

上記の手順では、wfLoadExtension()を使用してこの拡張機能をインストールする新しい方法を記載しています。 この拡張機能をこれらの過去のバージョン (MediaWiki 1.35以前) にインストールする必要がある場合は、wfLoadExtension( 'UserFunctions' );の代わりに以下を使用する必要があります:

require_once "$IP/extensions/UserFunctions/UserFunctions.php";

名前空間の許可

デフォルトでは、ユーザー関数は NS_MEDIAWIKI 名前空間でのみ動作します。

以下に、他の名前空間での関数の動作を許可または禁止する例を示します。 この構文は、$wgNamespacesWithSubpagesをベースにしています。

// 名前空間 "Main "でユーザー関数を追加で使用できるようにする。
// Adds values to the existing array
$wgUFAllowedNamespaces[NS_MAIN] = true;
// Enable user functions in namespaces "Main" and "User", but not in namespace "MediaWiki"
// Replaces values in the existing array
$wgUFAllowedNamespaces = [
        NS_MAIN => true,
        NS_USER => true
];
// Enable user functions in namespaces with the indexes from 0 to 200
// Replaces values in the existing array
$wgUFAllowedNamespaces = array_fill( 0, 200, true );

More info on namespace numbering.

In other contexts (recognized as NS -1, but not always a Special Page), such as in Page Forms pages, check you have the following parameter enabled:

$wgUFEnableSpecialContexts = true;

上記のパラメータは既定で有効になっています。

If you experience any problem with bots or maintenance scripts, turn it to false and report it to this talk page.

バージョン履歴

Authors: Algorithm and others

  • Version 2.8.1 () Allow disabling/enabling specific personal data functions - Universal Omega
Prior to this, the $wgUFEnabledPersonalDataFunctions configuration variable was named $wgUFEnablePersonalDataFunctions, and setting it to true would enable all personal data functions, and was only able to enable/disable all of them or none of them.
  • Version 2.8.0 () Convert to ExtensionRegistry and other code cleanups - Universal Omega
  • Version 2.7.0 () Removed PHP i18n shim - Kghbln
  • Version 2.6.1 () Provided syntax changes - Kghbln, Umherirrender
  • Version 2.6.0 () Composer-compatible extension - Toniher
  • Version 2.5.0 () Migrated to JSON i18n - Siebrand
  • Version 2.4.3 () Accumulated fixes and code cleaning - Chad Uckelman
  • Version 2.4.2 () Some code cleaning - Reedy
  • Version 2.4.1 () Fixed problems with Sidebar (report Kghbln). Cleared PHP warnings in functions - Toniher
  • Version 2.4 () Cleaned using current ParserFunctions models. Fix when editing Semantic Forms - Toniher
  • Version 2.3 () fixed problems when using scripts and allowed multiple groups to be checked against in ifingroup. - Toniher
  • Version 2.2 () added $wgUFAllowedNamespaces parameter. Users need to define in which allowed NS functions will work. - Toniher
  • Version 2.1 () added $wgUFEnablePersonalDataFunctions parameter. Migrated $wgUser to ParserOptions equivalent - Toniher
  • Version 2.0 () added i18n and compatibility with other parser function extensions - Toniher
  • Version 1.5 () added ip - Kghbln
  • Version 1.4 () added realname - Kghbln
  • Version 1.3 () added useremail - Wikinaut
  • Version 1.2 () added ifingroup - Louperivois
  • Version 1.1 () added nickname - Lexw
  • Version 1.0 () アルゴリズム

Issues and feature requests

関連項目