モジュール:Message box/doc

英語版の Revision as of 09:03, 2 October 2017 まで取り込んだ時点で用意されていた、2019年初頭の文書の翻訳です。

このメタモジュールには、メッセージボックス・テンプレート({{mbox}}, {{ambox}}, {{cmbox}}, {{fmbox}}, {{imbox}}, {{ombox}}, and {{tmbox}})が実装されています。Luaモジュールから呼び出されることが想定され、ウィキのページから直接使用すべきではありません。もしこのモジュールの機能をウィキページで使いたいのであれば、代わりにそれぞれのメッセージボックス・テンプレートを使用してください。

使用法[編集]

このモジュールを他のLuaモジュールにて使うには、最初に読み込みが必要です。

local messageBox = require('Module:Message box')

メッセージボックスを作るには、main関数を使います。2つの引数があります: 1つ目はメッセージボックスの type (文字列) 2つ目はメッセージボックスの引数を含んだ連想配列です。

local box = messageBox.main( boxType, {
    param1 = param1,
    param2 = param2,
    -- More parameters...
})

7種類のメッセージボックスがあります:

Box type Template Purpose
mbox {{mbox}} 複数の名前空間 multiple
ambox {{ambox}} 記事 Article 名前空間
cmbox {{cmbox}} カテゴリ 名前空間
fmbox {{fmbox}} interface message boxes
imbox {{imbox}} 画像 image ファイル 名前空間
tmbox {{tmbox}} ノート talk page 名前空間
ombox {{ombox}} 他の other 名前空間

使用できる引数については、それぞれのテンプレートのページをご覧ください。

#invokeからの使用[編集]

このモジュールを #invoke で利用する場合は、ボックスの種類に応じて{{#invoke:Message box|mbox|...}}, {{#invoke:Message box|ambox|...}}などとしてください。

他のモジュールから当モジュールを使用する際もmboxamboxのような関数名は使用可能ですが、その場合は #invoke に渡された引数を処理するためのコードを利用するので、直接main関数を呼び出す場合と比べて効率が悪くなるでしょう。

専門的な詳細[編集]

このモジュールは、それぞれのテンプレートのために、以下のような同じ基礎となるコードを使っています。違いはModule:Message box/configurationのデータを使って設定されます。設定可能なオプションは以下です。

  • types - a table containing data used by the type parameter of the message box. The table keys are the values that can be passed to the type parameter, and the table values are tables containing the class and the image used by that type.
  • default - the type to use if no value was passed to the type parameter, or if an invalid value was specified.
  • showInvalidTypeError - whether to show an error if the value passed to the type parameter was invalid.
  • allowBlankParams - usually blank values are stripped from parameters passed to the module. However, whitespace is preserved for the parameters included in the allowBlankParams table.
  • allowSmall - whether a small version of the message box can be produced with "small=yes".
  • smallParam - a custom name for the small parameter. For example, if set to "left" you can produce a small message box using "small=left".
  • smallClass - the class to use for small message boxes.
  • substCheck - whether to perform a subst check or not.
  • classes - an array of classes to use with the message box.
  • imageEmptyCell - whether to use an empty <td>...</td> cell if there is no image set. This is used to preserve spacing for message boxes with a width of less than 100% of the screen.
  • imageEmptyCellStyle - whether empty image cells should be styled.
  • imageCheckBlank - whether "image=blank" results in no image being displayed.
  • imageSmallSize - usually, images used in small message boxes are set to 30x30px. This sets a custom size.
  • imageCellDiv - whether to enclose the image in a div enforcing a maximum image size.
  • useCollapsibleTextFields - whether to use text fields that can be collapsed, i.e. "issue", "fix", "talk", etc. Currently only used in ambox.
  • imageRightNone - whether imageright=none results in no image being displayed on the right-hand side of the message box.
  • sectionDefault - the default name for the "section" parameter. Depends on useCollapsibleTextFields.
  • allowMainspaceCategories - allow categorisation in the main namespace.
  • templateCategory - the name of a category to be placed on the template page.
  • templateCategoryRequireName - whether the name parameter is required to display the template category.
  • templateErrorCategory - the name of the error category to be used on the template page.
  • templateErrorParamsToCheck - an array of parameter names to check. If any are absent, the templateErrorCategory is applied to the template page.