Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Arguments/doc/tr

From Mechsploit.me Wiki
Revision as of 22:50, 1 September 2025 by MechsploWikiSysop (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

{{#ifeq:tr|doc||{{#ifeq:tr |doc

    | 

{{#ifeq:show |show

|

        }}{{#if: |
         |   {{#ifexist:Module:Arguments/doc
                  | [[Category:{{#switch:Module |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]]
                  | 
                 }}
        }}
    | 
   }}}}{{#switch:

| =

Template:Shared Template Warning Template:Used in system Template:Module rating Template:Module rating

Bu modül, Template:Magic word üzerinden iletilen argümanların kolay işlenmesini sağlar. Diğer modüller tarafından kullanılması amaçlanan bir meta modüldür ve doğrudan Template:Tlc'tan çağrılmamalıdır. Özellikleri şunları içerir:

  • Bağımsız değişkenlerin kolay kırpılması ve boş argümanların kaldırılması.
  • Bağımsız değişkenler hem geçerli çerçeve hem de ana çerçeve tarafından aynı anda iletilebilir. (Daha fazla ayrıntı aşağıda.)
  • Bağımsız değişkenler doğrudan başka bir Lua modülünden veya hata ayıklama konsolundan aktarılabilir.
  • Bağımsız değişkenler gerektiği gibi getirilir ve bu, Template:Xtag etiketleriyle ilgili (bazı) sorunların önlenmesine yardımcı olabilir.
  • Çoğu özellik özelleştirilebilir.

Temel kullanım

İlk önce modülü yüklemeniz gerekir. getArgs adlı bir işlev içerir.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs </syntaxhighlight>

En temel senaryoda, ana işlevinizin içinde getArgs kullanabilirsiniz. args değişkeni, Template:Tlc üzerindeki bağımsız değişkenleri içeren bir tablodur. (Ayrıntılar için aşağıya bakın.)

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) -- Ana modül kodu buraya gelir. end

return p </syntaxhighlight>

Bununla birlikte, önerilen uygulama, bir işlevi yalnızca Template:Tlc üzerinden bağımsız değişkenleri işlemek için kullanmaktır. Bu, birisi modülünüzü başka bir Lua modülünden çağırırsa, kullanılabilir bir çerçeve nesnesine sahip olmanız gerekmediği anlamına gelir, bu da performansı artırır.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) return p._main(args) end

function p._main(args) -- Ana modül kodu buraya gelir. end

return p </syntaxhighlight>

Birden çok işlevin bağımsız değişkenleri kullanmasını istiyorsanız ve bunlara Template:Tlc üzerinden da erişilebilmesini istiyorsanız, bir sarmalayıcı işlevi kullanabilirsiniz.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs

local p = {}

local function makeInvokeFunc(funcName) return function (frame) local args = getArgs(frame) return p[funcName](args) end end

p.func1 = makeInvokeFunc('_func1')

function p._func1(args) -- İlk işlevin kodu buraya gelir. end

p.func2 = makeInvokeFunc('_func2')

function p._func2(args) -- İkinci işlevin kodu buraya gelir. end

return p </syntaxhighlight>

Seçenekler

Aşağıdaki seçenekler mevcuttur. Aşağıdaki bölümlerde açıklanmıştır.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { trim = false, removeBlanks = false, valueFunc = function (key, value) -- Bir bağımsız değişkeni işlemek için kod end, frameOnly = true, parentOnly = true, parentFirst = true, wrappers = { 'Template:A wrapper template', 'Template:Another wrapper template' }, readOnly = true, noOverwrite = true }) </syntaxhighlight>

Boşlukların kırpılması ve çıkarılması

Boş bağımsız değişkenler genellikle MediaWiki şablonlarını Lua'ya dönüştürmeye yeni başlayan kodlayıcıları tetikler. Şablon sözdiziminde, boş dizeler ve yalnızca boşluklardan oluşan dizeler false kabul edilir. Bununla birlikte, Lua'da boş dizeler ve boşluklardan oluşan dizeler true kabul edilir. Bu, Lua modüllerinizi yazarken bu tür bağımsız değişkenlere dikkat etmezseniz, aslında false olarak ele alınması gereken bir şeyi true olarak değerlendirebileceğiniz anlamına gelir. Bunu önlemek için, varsayılan olarak bu modül tüm boş argümanları kaldırır.

Benzer şekilde boşluk, konumsal argümanlarla uğraşırken sorunlara neden olabilir. Template:Tlc öğesinden gelen adlandırılmış bağımsız değişkenler için boşluklar kırpılsa da, konumsal bağımsız değişkenler için korunur. Çoğu zaman bu ek boşluk istenmez, bu nedenle bu modül varsayılan olarak onu keser.

Bununla birlikte, bazen girdi olarak boş bağımsız değişkenler kullanmak istersiniz ve bazen ek boşluklar tutmak istersiniz. Bu, bazı şablonları tam olarak yazıldıkları gibi dönüştürmek için gerekli olabilir. Bunu yapmak istiyorsanız, trim ve removeBlanks bağımsız değişkenlerini false olarak ayarlayabilirsiniz.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { trim = false, removeBlanks = false }) </syntaxhighlight>

Bağımsız değişkenlerin özel biçimlendirmesi

Bazen bazı boş bağımsız değişkenleri kaldırmak isterken diğerlerini değil, belki de tüm konumsal bağımsız değişkenleri küçük harfle yazmak isteyebilirsiniz. Bunun gibi şeyler yapmak için valueFunc seçeneğini kullanabilirsiniz. Bu seçeneğin girdisi, key ve value olmak üzere iki parametre alan ve tek bir değer döndüren bir işlev olmalıdır. Bu değer, args tablosundaki key alanına eriştiğinizde elde edeceğiniz değerdir.

Örnek 1: Bu işlev, ilk konumsal bağımsız değişken için boşluğu korur, ancak diğer tüm bağımsız değişkenleri kırpar ve diğer tüm boş bağımsız değişkenleri kaldırır.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if key == 1 then return value elseif value then value = mw.text.trim(value) if value ~= then return value end end return nil end }) </syntaxhighlight>

Örnek 2: Bu işlev, boş bağımsız değişkenleri kaldırır ve tüm argümanları küçük harfe dönüştürür, ancak boşlukları konum parametrelerinden kırpmaz.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if not value then return nil end value = mw.ustring.lower(value) if mw.ustring.find(value, '%S') then return value end return nil end }) </syntaxhighlight>

Template:Note

{{#if: | }}
Tür denetimli Örnek 1 ve 2
{{#if:|{{{2}}}|<translate> The following is a closed debate.</translate> Template:Strong}}

Örnek 1: <syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if key == 1 then return value elseif type(value) == 'string' then value = mw.text.trim(value) if value ~= then return value else return nil end else return value end end }) </syntaxhighlight>

Örnek 2: <syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if type(value) == 'string' then value = mw.ustring.lower(value) if mw.ustring.find(value, '%S') then return value else return nil end else return value end end }) </syntaxhighlight>

Ayrıca, valueFunc işlevinin, args tablosundan bir bağımsız değişken istendiğinde aşağı yukarı çağrıldığını lütfen unutmayın. Bu nedenle performansı önemsiyorsanız, kodunuzla verimsiz bir şey yapmadığınızdan emin olmalısınız.

Çerçeveler ve üst çerçeveler

args tablosundaki bağımsız değişkenler, aynı anda geçerli çerçeveden veya onun üst çerçevesinden geçirilebilir. Bunun ne anlama geldiğini anlamak için bir örnek vermek en kolay yoldur. Diyelim ki Module:ExampleArgs adında bir modülümüz var. Bu modül, iletildiği ilk iki konumsal argümanı yazdırır.

{{#if: | }}
Module:ExampleArgs kodu
{{#if:|{{{2}}}|<translate> The following is a closed debate.</translate> Template:Strong}}

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) return p._main(args) end

function p._main(args) local first = args[1] or local second = args[2] or return first .. ' ' .. second end

return p </syntaxhighlight>

Module:ExampleArgs daha sonra {{#invoke:ExampleArgs|main|firstInvokeArg}} kodunu içeren Template:ExampleArgs tarafından çağrılır. Bu, "firstInvokeArg" sonucunu üretir.

Şimdi Template:ExampleArgs ile çağırsaydık, aşağıdakiler olurdu:

Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Kod ! style="width: 40%;" | Sonuç |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstInvokeArg secondTemplateArg Template:!)

Bu davranışı değiştirmek için ayarlayabileceğiniz üç seçenek vardır: frameOnly, parentOnly ve parentFirst. frameOnly öğesini ayarlarsanız, yalnızca geçerli çerçeveden iletilen bağımsız değişkenler kabul edilecektir; parentOnly öğesini ayarlarsanız, yalnızca üst çerçeveden iletilen bağımsız değişkenler kabul edilir; ve parentFirst öğesini ayarlarsanız, bağımsız değişkenler hem geçerli hem de üst çerçevelerden iletilecektir, ancak ana çerçevenin geçerli çerçeveye göre önceliği olacaktır. Template:ExampleArgs açısından sonuçlar:

frameOnly
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Kod ! style="width: 40%;" | Sonuç |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstInvokeArg Template:!)
parentOnly
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Kod ! style="width: 40%;" | Sonuç |- | {{ExampleArgs}} | |- | {{ExampleArgs|firstTemplateArg}} | firstTemplateArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstTemplateArg secondTemplateArg Template:!)
parentFirst
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Kod ! style="width: 40%;" | Sonuç |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstTemplateArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstTemplateArg secondTemplateArg Template:!)

Template:Note

Sarmalayıcılar

wrappers seçeneği, sınırlı sayıda şablonu sarmalayıcı şablonlar, yani tek amacı bir modülü çağırmak olan şablonlar olarak belirtmek için kullanılır. Modül, bir sarmalayıcı şablonundan çağrıldığını algılarsa, yalnızca üst çerçevedeki argümanları kontrol eder; aksi takdirde, yalnızca getArgs ile iletilen çerçevedeki bağımsız değişkenleri kontrol eder. Bu, modüllerin her bağımsız değişken araması için hem çerçeveyi hem de ana çerçeveyi kontrol etme zorunluluğuyla ilişkili performans kaybı olmadan Template:Tlc veya bir sarmalayıcı şablonu aracılığıyla çağrılmasına olanak tanır.

Örneğin, {{Navbox}} tek içeriğin (Template:Tag etiketlerindeki içerik hariç) {{#invoke:Navbox|navbox}} modülüdür. Bu şablon için doğrudan Template:Tlc ifadesine iletilen argümanları kontrol etmenin bir anlamı yoktur, çünkü orada hiçbir bağımsız değişken belirtilmeyecektir. parentOnly seçeneğini kullanarak Template:Tlc ile iletilen argümanları kontrol etmekten kaçınabiliriz, ancak bunu yaparsak Template:Tlc diğer sayfalardan da çalışmayacaktır. Durum böyle olsaydı, Template:Tmpl kodundaki Template:Tmpl hangi sayfadan kullanılmış olursa olsun tamamen göz ardı edilebilir. Template:Navbox şablonu sarmalayıcı olarak belirtmek için wrappers seçeneğini kullanarak, Template:Tmpl çoğu sayfadan çalıştırabiliriz, ancak yine de modülün Template:Navbox sayfasındaki bağımsız değişkenleri kontrol etmesini gerektirmeyiz.

Sarmalayıcılar bir dize olarak veya bir dizeler dizisi olarak belirtilebilir.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { wrappers = 'Template:Wrapper template' }) </syntaxhighlight>

<syntaxhighlight lang="lua"> local args = getArgs(frame, { wrappers = { 'Template:Wrapper 1', 'Template:Wrapper 2', -- Buraya herhangi bir sayıda sarmalayıcı şablonu eklenebilir. } }) </syntaxhighlight>

Template:Note

args tablosuna yazmak

Bazen args tablosuna yeni değerler yazmak faydalı olabilir. Bu, bu modülün varsayılan ayarlarıyla mümkündür. (Bununla birlikte, yeni değerlerinizle yeni bir tablo oluşturmanın ve gerektiğinde args tablosundan bağımsız değişkenleri kopyalamanın genellikle daha iyi bir kodlama stili olduğunu unutmayın.)

<syntaxhighlight lang="lua"> args.foo = 'bazı değer' </syntaxhighlight>

Bu davranışı readOnly ve noOverwrite seçenekleriyle değiştirmek mümkündür. readOnly ayarlanırsa, args tablosuna herhangi bir değer yazmak mümkün değildir. noOverwrite ayarlanırsa, tabloya yeni değerler eklemek mümkündür, ancak Template:Tlc üzerinden iletilen herhangi bir bağımsız değişkenin üzerine yazılacaksa bir değer eklemek mümkün değildir.

Ref etikletleri

Bu modül, Template:Tlc üzerinden bağımsız değişkenler almak için meta tablolar kullanır. Bu, pairs() işlevini kullanmadan hem çerçeve bağımsız değişkenlerine hem de üst çerçeve bağımsız değişkenlerine erişim sağlar. Bu, modülünüzün giriş olarak Template:Xtag etiketleri geçirilebilmesi durumunda yardımcı olabilir.

Template:Xtag etiketlerine Lua'dan erişilir erişilmez, bunlar MediaWiki yazılımı tarafından işlenir ve kaynakça, maddenin altındaki kaynakça listesinde görünecektir. Modülünüz kaynak etiketini çıktıdan çıkarmaya devam ederse, sonunda bir hayali referans elde edersiniz. Bu, modüller mevcut her bağımsız değişkeni otomatik olarak işlediğinden, çerçeveden mi yoksa üst çerçeveden mi bağımsız değişkenlerin kullanılacağını saptamak için pairs() kullanan modüllerde bir sorun olmuştur.

Bu modül, hem çerçeve hem de üst çerçeve argümanlarına erişime izin vererek bu sorunu çözerken, yine de yalnızca gerekli olduğunda bu argümanları getirir. Bununla birlikte, modülünüzün başka bir yerinde pairs(args) kullanırsanız sorun yine de ortaya çıkacaktır.

Bilinen sınırlamalar

Meta tablo kullanımının dezavantajları da vardır. Normal Lua tablo araçlarının çoğu, # işlemi, next() işlevi ve table kitaplığındaki işlevler dahil olmak üzere args tablosunda düzgün çalışmaz. Bunları kullanmak modülünüz için önemliyse, bu modül yerine kendi argüman işleme fonksiyonunuzu kullanmalısınız.

Denemeler

Template:ModuleQuality

| #default=

 {{#switch:

| = Template:Languages Template:Shared Template Warning Template:Used in system Template:Module rating Template:Module rating

This module provides easy processing of arguments passed from Template:Magic word. It is a meta-module, meant for use by other modules, and should not be called from Template:Tlc directly. Its features include:

  • Easy trimming of arguments and removal of blank arguments.
  • Arguments can be passed by both the current frame and by the parent frame at the same time. (More details below.)
  • Arguments can be passed in directly from another Lua module or from the debug console.
  • Arguments are fetched as needed, which can help avoid (some) problems with Template:Xtag tags.
  • Most features can be customized.

Basic use

First, you need to load the module. It contains one function, named getArgs.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs </syntaxhighlight>

In the most basic scenario, you can use getArgs inside your main function. The variable args is a table containing the arguments from Template:Tlc. (See below for details.)

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) -- Main module code goes here. end

return p </syntaxhighlight>

However, the recommended practice is to use a function just for processing arguments from Template:Tlc. This means that if someone calls your module from another Lua module you don't have to have a frame object available, which improves performance.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) return p._main(args) end

function p._main(args) -- Main module code goes here. end

return p </syntaxhighlight>

If you want multiple functions to use the arguments, and you also want them to be accessible from Template:Tlc, you can use a wrapper function.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs

local p = {}

local function makeInvokeFunc(funcName) return function (frame) local args = getArgs(frame) return p[funcName](args) end end

p.func1 = makeInvokeFunc('_func1')

function p._func1(args) -- Code for the first function goes here. end

p.func2 = makeInvokeFunc('_func2')

function p._func2(args) -- Code for the second function goes here. end

return p </syntaxhighlight>

Options

The following options are available. They are explained in the sections below.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { trim = false, removeBlanks = false, valueFunc = function (key, value) -- Code for processing one argument end, frameOnly = true, parentOnly = true, parentFirst = true, wrappers = { 'Template:A wrapper template', 'Template:Another wrapper template' }, readOnly = true, noOverwrite = true }) </syntaxhighlight>

Trimming and removing blanks

Blank arguments often trip up coders new to converting MediaWiki templates to Lua. In template syntax, blank strings and strings consisting only of whitespace are considered false. However, in Lua, blank strings and strings consisting of whitespace are considered true. This means that if you don't pay attention to such arguments when you write your Lua modules, you might treat something as true that should actually be treated as false. To avoid this, by default this module removes all blank arguments.

Similarly, whitespace can cause problems when dealing with positional arguments. Although whitespace is trimmed for named arguments coming from Template:Tlc, it is preserved for positional arguments. Most of the time this additional whitespace is not desired, so this module trims it off by default.

However, sometimes you want to use blank arguments as input, and sometimes you want to keep additional whitespace. This can be necessary to convert some templates exactly as they were written. If you want to do this, you can set the trim and removeBlanks arguments to false.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { trim = false, removeBlanks = false }) </syntaxhighlight>

Custom formatting of arguments

Sometimes you want to remove some blank arguments but not others, or perhaps you might want to put all of the positional arguments in lower case. To do things like this you can use the valueFunc option. The input to this option must be a function that takes two parameters, key and value, and returns a single value. This value is what you will get when you access the field key in the args table.

Example 1: This function preserves whitespace for the first positional argument, but trims all other arguments and removes all other blank arguments.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if key == 1 then return value elseif value then value = mw.text.trim(value) if value ~= then return value end end return nil end }) </syntaxhighlight>

Example 2: This function removes blank arguments and converts all arguments to lower case, but doesn't trim whitespace from positional parameters.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if not value then return nil end value = mw.ustring.lower(value) if mw.ustring.find(value, '%S') then return value end return nil end }) </syntaxhighlight>

Template:Note

{{#if: | }}
Examples 1 and 2 with type checking
{{#if:|{{{2}}}|<translate> The following is a closed debate.</translate> Template:Strong}}

Example 1: <syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if key == 1 then return value elseif type(value) == 'string' then value = mw.text.trim(value) if value ~= then return value else return nil end else return value end end }) </syntaxhighlight>

Example 2: <syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if type(value) == 'string' then value = mw.ustring.lower(value) if mw.ustring.find(value, '%S') then return value else return nil end else return value end end }) </syntaxhighlight>

Also, please note that the valueFunc function is called more or less every time an argument is requested from the args table, so if you care about performance you should make sure you aren't doing anything inefficient with your code.

Frames and parent frames

Arguments in the args table can be passed from the current frame or from its parent frame at the same time. To understand what this means, it is easiest to give an example. Let's say that we have a module called Module:ExampleArgs. This module prints the first two positional arguments that it is passed.

{{#if: | }}
Module:ExampleArgs code
{{#if:|{{{2}}}|<translate> The following is a closed debate.</translate> Template:Strong}}

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) return p._main(args) end

function p._main(args) local first = args[1] or local second = args[2] or return first .. ' ' .. second end

return p </syntaxhighlight>

Module:ExampleArgs is then called by Template:ExampleArgs, which contains the code {{#invoke:ExampleArgs|main|firstInvokeArg}}. This produces the result "firstInvokeArg".

Now if we were to call Template:ExampleArgs, the following would happen:

Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstInvokeArg secondTemplateArg Template:!)

There are three options you can set to change this behaviour: frameOnly, parentOnly and parentFirst. If you set frameOnly then only arguments passed from the current frame will be accepted; if you set parentOnly then only arguments passed from the parent frame will be accepted; and if you set parentFirst then arguments will be passed from both the current and parent frames, but the parent frame will have priority over the current frame. Here are the results in terms of Template:ExampleArgs:

frameOnly
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstInvokeArg Template:!)
parentOnly
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | {{ExampleArgs}} | |- | {{ExampleArgs|firstTemplateArg}} | firstTemplateArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstTemplateArg secondTemplateArg Template:!)
parentFirst
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstTemplateArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstTemplateArg secondTemplateArg Template:!)

Template:Note

Wrappers

The wrappers option is used to specify a limited number of templates as wrapper templates, that is, templates whose only purpose is to call a module. If the module detects that it is being called from a wrapper template, it will only check for arguments in the parent frame; otherwise it will only check for arguments in the frame passed to getArgs. This allows modules to be called by either Template:Tlc or through a wrapper template without the loss of performance associated with having to check both the frame and the parent frame for each argument lookup.

For example, the only content of {{Navbox}} (excluding content in Template:Tag tags) is {{#invoke:Navbox|navbox}}. There is no point in checking the arguments passed directly to the Template:Tlc statement for this template, as no arguments will ever be specified there. We can avoid checking arguments passed to Template:Tlc by using the parentOnly option, but if we do this then Template:Tlc will not work from other pages either. If this were the case, then Template:Tmpl in the code Template:Tmpl would be ignored completely, no matter what page it was used from. By using the wrappers option to specify Template:Navbox as a wrapper, we can make Template:Tmpl work from most pages, while still not requiring that the module check for arguments on the Template:Navbox page itself.

Wrappers can be specified either as a string, or as an array of strings.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { wrappers = 'Template:Wrapper template' }) </syntaxhighlight>

<syntaxhighlight lang="lua"> local args = getArgs(frame, { wrappers = { 'Template:Wrapper 1', 'Template:Wrapper 2', -- Any number of wrapper templates can be added here. } }) </syntaxhighlight>

Template:Note

Writing to the args table

Sometimes it can be useful to write new values to the args table. This is possible with the default settings of this module. (However, bear in mind that it is usually better coding style to create a new table with your new values and copy arguments from the args table as needed.)

<syntaxhighlight lang="lua"> args.foo = 'some value' </syntaxhighlight>

It is possible to alter this behaviour with the readOnly and noOverwrite options. If readOnly is set then it is not possible to write any values to the args table at all. If noOverwrite is set, then it is possible to add new values to the table, but it is not possible to add a value if it would overwrite any arguments that are passed from Template:Tlc.

Ref tags

This module uses metatables to fetch arguments from Template:Tlc. This allows access to both the frame arguments and the parent frame arguments without using the pairs() function. This can help if your module might be passed Template:Xtag tags as input.

As soon as Template:Xtag tags are accessed from Lua, they are processed by the MediaWiki software and the reference will appear in the reference list at the bottom of the article. If your module proceeds to omit the reference tag from the output, you will end up with a phantom reference - a reference that appears in the reference list, but no number that links to it. This has been a problem with modules that use pairs() to detect whether to use the arguments from the frame or the parent frame, as those modules automatically process every available argument.

This module solves this problem by allowing access to both frame and parent frame arguments, while still only fetching those arguments when it is necessary. The problem will still occur if you use pairs(args) elsewhere in your module, however.

Known limitations

The use of metatables also has its downsides. Most of the normal Lua table tools won't work properly on the args table, including the # operator, the next() function, and the functions in the table library. If using these is important for your module, you should use your own argument processing function instead of this module.

Tests

Template:ModuleQuality {{safesubst:#if:{{safesubst:#ifeq:tr|sandbox|1}}{{safesubst:#ifeq:tr|doc|1}}|| }} | #default=

 Lua error: expandTemplate: template loop detected.

}} }}