ویکی‌پدیا:لوآ

ویکی‌پدیادان، آچیق بیلیک‌لیک‌دن
(ویکی‌پدیا:Lua-دن يوْل‌لاندیریلمیش)
ویکی پدیا معلومات قورولوشو
Subject namespaces Talk namespaces
0 (مقاله) دانیشیق 1
2 ایشلدن ایشلدن دانیشیغی 3
4 ویکی‌پدیا ویکی‌پدیا دانیشیغی 5
6 فایل فایل دانیشیغی 7
8 مدیاویکی مدیاویکی دانیشیغی 9
10 شابلون شابلون دانیشیغی 11
12 کؤمک کؤمک دانیشیغی 13
14 بؤلمه بؤلمه دانیشیغی 15
100 پوْرتال پوْرتال دانیشیغی 101
118 [[Wikipedia:Drafts|]] 119
710 TimedText TimedText talk 711
828 ماژول ماژول دانیشیغی 829
Deprecated
2300 [[Wikipedia:Gadget|]] 2301
2302 [[Wikipedia:Gadget|]] 2303
-1 اؤزل
-2 مدیا

لوآ اینگیلیس ویکی‌پدیاسیندا مدیاویکی-نین اسکریبونتو اکستنشین-ی واسیطه‌سیله مؤوجود اولان پروقراملاشدیرما دیلیدیر. ۲۰۱۳-جو فوریه آییندان لوآ کودو اسکریبونتو-نون «{{#invoke:}}» تابع-سیندن ایستیفاده ائتمک ایله ویکی شابلونلارینا داخیل ادیله بیلر. بو اکستنشین بو تاریخدن: اوْکتوبر ۲۰۲۲ لوا ۵.۱-ی دستکلییر.

لوا-نین سورس کودو ماژول آدلانان صفحه‌لرده ساخلانیر (میثال: لوآ:Example). بو فردی ماژوللار داها سونرا چاغیریلیر ({{#invoke:<Module name>|<Function name>|(optional) param1 | param2...}} کودو ایله). میثال:

ویکی‌تکست نتیجه‌سی
{{#invoke:Example|hello}} Hello World!

بیر ماژولون ایجراسی[دَییشدیر]

ماژوللار تحلیل ائدن تابع‌سی (اینگیلیسجه: parser function) ایله #invoke-دان ایستیفاده ائتمکله نورمال ویکی صفحه‌لرینده ایشلدیلیر. #invoke سینتکسی شابلون سینتکسینه بنزییر، اما بعضی فرقلرله. لاپ موهوم فرق اوندان عیبارتدیر کی، سیز تابع آدینی قئید ائتمه‌لیسینیز. بیر تابع گیریش دَیَرلرینی قبول ائدن، اونلاری عمل ائدن و چیخیش دیرینی قایتاران تعلیماتلار توپلوسودور.[۱] بو، شابلونون ائتدییینه بنزییر: اونا آرقومنتلر وئریرسن، اونلاری عمل ائدیر و نتیجه آلیرسان . بونلا بئله، لوآ مازولوندا بیر چوخ تابع موعیین ائده بیلرسینیز، حالبوکی بیر صفحه‌ده تکجه بیر شابلون تعیین ائده بیلرسینیز.

بوندان علاوه، سیز ساده‌جه لوآ ماژولونو بیرباشا (فارسجا: مستقیم) ایشه سالا بیلمه‌سینیز - ماژولون تلبعلریندن تکجه بیرینی ایشلده بیلرسینیز. ماژول ساده‌جه تابعلر اوچون کانتینر (اینگیلیسجه: container) دیر و اؤزو هئچ نه ائتمیر. بئله‌لیکله، تابع آدینی داخیل ائتمه‌ییمیزین ایکی سببی وار: بیز ماژولو اؤزباشینا ایشلده بیلمریک و تابع آدینی گؤسترمه‌دن لوآ اونون هانسی تابعنی ایشلتمک ایستدیییمیزی بیلمه‌یه‌جک.

ویکی صفحه‌سینده ماژولو ایشه سالماغین لاپ ساده یولو بئلدیر:

{{#invoke:module name|function name}}

مثلا، «hello» آدلی تابعسی اولان ماژول:Example-ی بو شکیلده ایشلده بیلریک.

  • {{#invoke:Example|hello}} → Hello World!

آرقومنتلرین ایستیفاده‌سی[دَییشدیر]

آرقومنتلر شابلونلارا اؤتورولدوکلری کیمی کاژوللارا دا اؤتورولور. بونونلا بئله دیقّت ائدین کی، بیرینجی بورو سیمبولوندان سونراکی متن همیشه تابعنین آدیدیر؛ بیرینجی مؤوجود آرقومنتی ایکینجی بورودان سونراکی متندیر.

{{#invoke:module name|function name|first positional argument|second positional argument|named argument = value}}

ماژول:Example-ده، «hello_to» تابع‌سی بیرینجی مؤوجود آرقومنتیندن آسیلی اولاراق موختلیف اینسانلاری سلاملاییر. بو بئله ایشلییر:

  • {{#invoke:Example|hello_to|کئیت}} ← Hello, کئیت!
  • {{#invoke:Example|hello_to|فرئد}} ← Hello, فرئد!

ماژول:Example-ده «count_fruit» آدلی اوچونجو تابع الیمیزده اولان موزلار و آلمالارین سایینی حسابلاماق اوچون موز و آلما آدلی آرقومنتلردن ایستیفاده ائدیر. بو بئله ایشلدیله بیلر:

  • {{#invoke:Example|count_fruit|آلمالار=3|موزلار=4}} ← I have 4 bananas and 3 apples
  • {{#invoke:Example|count_fruit|موزلار=5|آلمالار=2}} ← I have 5 bananas and 2 apples

اکثر ماژوللاردا هانسی آرقومنتلرین ایستیفاده اولونا بیله‌جه‌یینی و اونلارین تاثیرلرینین نه اولاجاغینی توضیح ائدن بلگه‌له‌مه صفحه‌سی وار.

بیر ایسکریپت طلب ائتمک[دَییشدیر]

ویکی‌پدیادا و یا باشقا ویکی‌مدیا فوندونون پروژه‌سینده خصوصی تاپیشیریغی یئرینه یئتیرمک اوچون اوا اسکریپتینین یازیلماسیندا کؤمک ایستمک اوچون ویکی‌پدیا دانیشیغی:لوآ-یه مواجیعت ائدین.

تاریخ[دَییشدیر]

پیس تاریخ. {{qif}}، ParserFunctions، لوآ اکستنشین ویکی اسکریپت دیلی موذاکیره ائدیلن (جاوااسکریپت-ه قارشی ا. لوآ)، mw:Extension:WikiScripts، تیم لوا اوچون ایلکین دستک ایله اسکریبونتو یازیر.

ایللر بویو موذاکیره ائدیلن لوآ ۲۰۱۲-جی ایلده test2.wikipedia.org سایتیندا سیناقدان کئچیرمک اوچون گوراشدیریلیب و بوتون دییشدیریجیلری لوآ ماژوللارینین یارادیلماسی ایله سیناقدان کئچیرمه‌یه آچیق دعوت ائدیب. لوآ ۲۰۱۳-جو ایلین فوریه‌سینده mediawiki.org و ویکی‌مدیا تست ویکیلرینده سیناقدان کئچیریلدیکدن سونرا اینگیلیس ویکی‌پدیاسیندا گوراشدیریلیب.

لوآ باره‌سینده[دَییشدیر]

See also Brad Jorsch's short presentation for a basic example of how to convert a wikitext template into a Lua module.

لوآ، تابعلردن و یا آبجکت-اورینتد پروقرمینق-دن ایستیفاده ائدرک معلوماتلاری تحلیل ائتمک، ایفاده‌لری حسابلاماق و نتیجه‌لری فورمتلشدیرماق اوچون ایستیفاده ائدیله بیلن بیر اسکریپت دیلیدیر. Although some Lua scripts can be kept simple, for easy understanding, Lua allows complex structures including tables, dynamic functions, and associative arrays where index subscripts can be words as well as index numbers. Lua also supports recursion of re-nested functions, so care should be taken to avoid excessive complexity where other users would not understand how to maintain a Lua module. The following is the source code of the module used for the examples above.

local p = {};     --All Lua modules on Wikipedia must begin by defining a variable 
                    --that will hold their externally accessible functions.
                    --Such variables can have whatever name you want and may 
                    --also contain various data as well as functions.
p.hello = function( frame )     --Add a function to "p".  
                                        --Such functions are callable in Wikipedia
                                        --via the #invoke command.
                                        --"frame" will contain the data that Wikipedia
                                        --sends this function when it runs. 
                                 -- 'Hello' is a name of your choice. The same name needs to be referred to when the module is used.
    
    local str = "Hello World!"  --Declare a local variable and set it equal to
                                --"Hello World!".  
    
    return str    --This tells us to quit this function and send the information in
                  --"str" back to Wikipedia.
    
end  -- end of the function "hello"
function p.hello_to(frame)		-- Add another function
	local name = frame.args[1]  -- To access arguments passed to a module, use `frame.args`
							    -- `frame.args[1]` refers to the first unnamed parameter
							    -- given to the module
	return "Hello, " .. name .. "!"  -- `..` concatenates strings. This will return a customized
									 -- greeting depending on the name given, such as "Hello, Fred!"
end
function p.count_fruit(frame)
	local num_bananas = frame.args.bananas -- Named arguments ({{#invoke:Example|count_fruit|foo=bar}}) are likewise 
	local num_apples = frame.args.apples   -- accessed by indexing `frame.args` by name (`frame.args["bananas"]`, or)
										   -- equivalently `frame.args.bananas`.
	return 'I have ' .. num_bananas .. ' bananas and ' .. num_apples .. ' apples'
										   -- Like above, concatenate a bunch of strings together to produce
										   -- a sentence based on the arguments given.
end

return p    --All modules end by returning the variable containing their functions to Wikipedia.
-- Now we can use this module by calling {{#invoke: Example | hello }},
-- {{#invoke: Example | hello_to | foo }}, or {{#invoke:Example|count_fruit|bananas=5|apples=6}}
-- Note that the first part of the invoke is the name of the Module's wikipage,
-- and the second part is the name of one of the functions attached to the 
-- variable that you returned.

-- The "print" function is not allowed in Wikipedia.  All output is accomplished
-- via strings "returned" to Wikipedia.

A sample of Lua is highlighted by tag "<syntaxhighlight lang="lua">...</syntaxhighlight>" placed around the Lua source code. To view some more complex examples of Lua, see article: "Lua (programming language)".

For instructions on how to use Lua within MediaWiki (and hence Wikipedia), see mw:Extension:Scribunto/Lua reference manual.

Unit testing[دَییشدیر]

A few unit testing frameworks are available for Lua scripts on Wikipedia. These allow an editor to execute the module with a given set of inputs and verify that the expected outputs are produced. They are useful for rapidly detecting software regressions, where modifications to a script introduce new (or identify old) problems.

By convention, unit tests for a module like ماژول:Example are placed in Module:Example/testcases, and are executed on Module talk:Example/testcases.

Module:ScribuntoUnit and ماژول:UnitTests are widely used test frameworks. Category:Modules for test tools has a few other to review which may be interesting.

MediaWiki-specific features[دَییشدیر]

Overall: Lua can only get input as text strings passed to the {{#invoke:}} and what can be fetched via mw.title.new(...):getContent() and frame:expandTemplate(). Lua output will not be preprocessed unless frame:preprocess() is explicitly called, meaning that template calls, parser functions, etc. in the output will not work correctly. Also, all Lua in the page is limited to 10 seconds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). And relative to standard Lua, Scribunto's Lua lacks all sorts of functions (see mw:Extension:Scribunto/Lua reference manual § Differences from standard Lua).

Lua input limitations[دَییشدیر]

Lua code in Scribunto is only run when the page is being parsed. Therefore, the only user input that Lua can receive is by page editing – it cannot create a box that calculates the square root of a number you type in, or recalculate a piece of the Mandelbrot set depending on which part of the parent set you click on. The input Lua can receive includes any transcludeable text page on Wikipedia. This does not include graphics files (not even .SVG files, although they are actually text, unless you cut and paste it onto a Wiki text page), the list of pages listed in a category, nor the contents of non-transcludeable special pages.

ویکی‌متن[دَییشدیر]

Transcluded Wikipedia headers frequently contain a hidden code such as "UNIQ5ae8f2aa414ff233-h-3--QINU" which may need to be stripped out in order for them to be parsed effectively.

Wikilinks using the pipe trick [[کؤمک:ایچینده‌کیلر| ]] won't work if returned as output – they need to be written explicitly as [[کؤمک:ایچینده‌کیلر|Help]]. Other pre-save transforms, such as replacing ~~~~ with signatures, will also fail to be processed. Template transclusions, parser function calls, and variable substitutions (i.e. anything with a {{...}}) will not be processed, nor will tags such as <ref> or <nowiki>. Use frame:extensionTag to add tags like <ref> or <syntaxhighlight> to output.

Labeling converted templates[دَییشدیر]

Please place the {{lua}} template on the documentation subpage of all templates that use Lua. It will help to better communicate Lua usage and template conversions.

نوتلار[دَییشدیر]

  1. ^ سیز همچینین بیر نئچه چیخیش دیرلرینه صاحیب اولا بیلرسینیز، اما بونو ائدن تابعلر عادتن ویکی صفحه‌لریندن داخیل اولماق اوچون نظرده توتولمور .