ماڊيول:Documentation
| هي Lua ماڊيول گھڻن صفحن تي استعمال ٿئي ٿو، تنهن ڪري ان ۾ تبديليون وڏي پيماني تي نظر اينديون۔ مهرباني ڪري ڪنهن به تبديلي کي ماڊيول جي /sandbox يا /testcases ذيلي صفحن۔ ۾ آزمائي ڏسومهرباني ڪري تبديليءَ بابت بحث ڳالهه ٻولهه واري صفحي تي ڪريو، پوءِ انهن کي لاڳو ڪريو۔ |
| هي سانچو لوا استعمال ڪري ٿو: |
| This module uses TemplateStyles: |
هي ماڊيول هڪ سائي خاني (green box) ۾ دستاويز ڏيکاري ٿو جيڪو سانچن، Lua ماڊيولن يا ٻين صفحن لاءِ استعمال ٿيندو آهي۔
{{documentation}} سانچو هن ماڊيول کي استعمال ڪري ٿو۔
عام استعمال
[سنواريو]گهڻن حالتن ۾ توهان کي {{documentation}} سانچو استعمال ڪرڻ گهرجي؛ ان جي استعمال جي هدايتن ۽ پيرا ميٽرن لاءِ مهرباني ڪري انهي سانچي جو صفحو ڏسو۔
ٻين ماڊيولن ۾ استعمال
[سنواريو]جيڪڏهن هن ماڊيول کي ڪنهن ٻئي Lua ماڊيول مان استعمال ڪرڻو هجي ته پهرين ان کي require ذريعي لوڊ ڪيو وڃي:
local documentation = require('Module:Documentation').main
ان کان پوءِ توهان ان کي سڌي طرح دليلن (arguments) جي ٽيبل سان سڏي سگهو ٿا:
documentation{content = 'ڪجهه دستاويز', ['link box'] = 'منهنجو خاص لنڪ باڪس'}
استعمال جي هدايتن ۽ پيرا ميٽرن جي فهرست لاءِ مهرباني ڪري سانچي جي دستاويز ڏسو۔
ٻين ماڊيولن ۾ استعمال
[سنواريو]جيڪڏهن هن ماڊيول کي ڪنهن ٻئي Lua ماڊيول مان استعمال ڪرڻو هجي ته پهرين ان کي require ذريعي لوڊ ڪيو وڃي:
local documentation = require('Module:Documentation').main
ان کان پوءِ توهان ان کي سڌي طرح دليلن جي ٽيبل سان سڏي سگهو ٿا:
documentation{content = 'ڪجهه دستاويز', ['link box'] = 'منهنجو خاص لنڪ باڪس'}
استعمال جي هدايتن ۽ پيرا ميٽرن جي فهرست لاءِ مهرباني ڪري سانچي جي دستاويز ڏسو۔
ٻين وڪين ڏانهن منتقل ڪرڻ
[سنواريو]هن ماڊيول وٽ هڪ ترتيب (configuration) فائيل آهي جيڪو ماڊيول:Documentation/config تي موجود آهي، جنهن جو مقصد ٻين وڪين تي آساني سان ترجمو ۽ منتقلي ممڪن بڻائڻ آهي۔ مهرباني ڪري ترتيب واري صفحي ۾ ڏنل ڪوڊ تبصرن (code comments) کي پڙهو۔
جيڪڏهن ترتيب جي متن ۾ وڪيپيڊيا جا لنڪ هجن، مثال طور:
[[Wikipedia:Template documentation|documentation]]
ته اهي ڪنهن ٻي وڪي تي موجود نه به ٿي سگهن ٿا۔ ان ڪري يا ته انهن کي تبديل ڪيو، هٽايو، يا انٽر وڪي اڳوڻو لاحقو شامل ڪريو، مثال طور:
[[w:Wikipedia:Template documentation|documentation]]
جيڪڏهن توهان وٽ ڪو سوال هجي يا ڪا اهڙي خاصيت گهربل هجي جيڪا هن وقت لاڳو نه هجي ته مهرباني ڪري هيٺ ڏنل صفحي تي پيغام ڇڏيو:
اهي پيغام جيڪي ماڊيول صفحن جي مٿان دستاويزي سانچو ڏيکارڻ لاءِ ترتيب ڏيڻا پوندا آهن:
-- هي ماڊيول {{documentation}} کي لاڳو ڪري ٿو۔
-- گهربل ماڊيول حاصل ڪريو۔
local getArgs = require('Module:Arguments').getArgs
-- config ٽيبل حاصل ڪريو۔
local cfg = mw.loadData('Module:Documentation/config')
local p = {}
-- گهڻو استعمال ٿيندڙ فنڪشن
local ugsub = mw.ustring.gsub
local format = mw.ustring.format
----------------------------------------------------------------------------
-- مددگار فنڪشن
--
-- اهي local functions طور بيان ڪيون ويون آهن، پر جاچ جي مقصدن لاءِ
-- p ٽيبل ۾ به موجود آهن۔
----------------------------------------------------------------------------
local function message(cfgKey, valArray, expectType)
--[[
-- cfg ٽيبل مان پيغام حاصل ڪري ٿو ۽ ضرورت هجي ته ان کي فارميٽ ڪري ٿو۔
-- جيڪڏهن cfg ٽيبل مان حاصل ڪيل قدر جو قسم expectType سان نه ملي،
-- ته فنڪشن غلطي پيدا ڪري ٿو۔ expectType جي ڊفالٽ قيمت 'string' آهي۔
-- جيڪڏهن valArray ٽيبل موجود هجي، ته پيغام ۾ موجود $1، $2 وغيره
-- valArray جي [1]، [2] وغيره مان مليل قدرن سان تبديل ڪيا ويندا۔
-- مثال طور، جيڪڏهن "foo-message" جو قدر 'Foo $2 bar $1.' هجي،
-- ته message('foo-message', {'baz', 'qux'}) واپس ڪندو:
-- "Foo qux bar baz."
--]]
local msg = cfg[cfgKey]
expectType = expectType or 'string'
if type(msg) ~= expectType then
error('message: message cfg.' .. cfgKey .. ' ۾ قسم جي غلطي (' .. expectType .. ' گهربل، پر ' .. type(msg) .. ' مليو)', 2)
end
if not valArray then
return msg
end
local function getMessageVal(match)
match = tonumber(match)
return valArray[match] or error('message: message cfg.' .. cfgKey .. ' ۾ key $' .. match .. ' لاءِ ڪا قدر نه ملي', 4)
end
return ugsub(msg, '$([1-9][0-9]*)', getMessageVal)
end
p.message = message
local function makeWikilink(page, display)
if display then
return format('[[%s|%s]]', page, display)
else
return format('[[%s]]', page)
end
end
p.makeWikilink = makeWikilink
local function makeCategoryLink(cat, sort)
local catns = mw.site.namespaces[14].name
return makeWikilink(catns .. ':' .. cat, sort)
end
p.makeCategoryLink = makeCategoryLink
local function makeUrlLink(url, display)
return format('[%s %s]', url, display)
end
p.makeUrlLink = makeUrlLink
local function makeToolbar(...)
local ret = {}
local lim = select('#', ...)
if lim < 1 then
return nil
end
for i = 1, lim do
ret[#ret + 1] = select(i, ...)
end
-- 'documentation-toolbar'
return format(
'<span class="%s">(%s)</span>',
message('toolbar-class'),
table.concat(ret, ' | ')
)
end
p.makeToolbar = makeToolbar
----------------------------------------------------------------------------
-- دليلن جي پروسيسنگ
----------------------------------------------------------------------------
local function makeInvokeFunc(funcName)
return function (frame)
local args = getArgs(frame, {
valueFunc = function (key, value)
if type(value) == 'string' then
value = value:match('^%s*(.-)%s*$') -- خالي جڳهون هٽايو۔
if key == 'heading' or value ~= '' then
return value
else
return nil
end
else
return value
end
end
})
return p[funcName](args)
end
end
----------------------------------------------------------------------------
-- داخلا جا نقطا
----------------------------------------------------------------------------
function p.nonexistent(frame)
if mw.title.getCurrentTitle().subpageText == 'testcases' then
return frame:expandTemplate{title = 'module test cases notice'}
else
return p.main(frame)
end
end
p.main = makeInvokeFunc('_main')
function p._main(args)
--[[
-- هي فنڪشن ماڊيول جي منطقي وهڪري کي بيان ڪري ٿو۔
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي جدول
--]]
local env = p.getEnvironment(args)
local root = mw.html.create()
root
:wikitext(p._getModuleWikitext(args, env))
:wikitext(p.protectionTemplate(env))
:wikitext(p.sandboxNotice(args, env))
:tag('div')
-- 'documentation-container'
:addClass(message('container'))
:attr('role', 'complementary')
:attr('aria-labelledby', args.heading ~= '' and 'documentation-heading' or nil)
:attr('aria-label', args.heading == '' and 'Documentation' or nil)
:newline()
:tag('div')
-- 'documentation'
:addClass(message('main-div-classes'))
:newline()
:wikitext(p._startBox(args, env))
:wikitext(p._content(args, env))
:tag('div')
-- 'documentation-clear'
:addClass(message('clear'))
:done()
:newline()
:done()
:wikitext(p._endBox(args, env))
:done()
:wikitext(p.addTrackingCategories(env))
-- 'Module:Documentation/styles.css'
return mw.getCurrentFrame():extensionTag (
'templatestyles', '', {src=cfg['templatestyles']
}) .. tostring(root)
end
----------------------------------------------------------------------------
-- ماحول جون ترتيبون
----------------------------------------------------------------------------
function p.getEnvironment(args)
--[[
-- ماحول بابت ڄاڻ رکندڙ جدول واپس ڪري ٿو، جنهن ۾ title objects
-- ۽ ٻيا namespace يا path سان لاڳاپيل ڊيٽا شامل آهن۔
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي جدول
--
-- Title objects ۾ شامل آهن:
-- env.title - اهو صفحو جنهن لاءِ اسان دستاويز ٺاهي رهيا آهيون، عام طور موجوده title
-- env.templateTitle - سانچو، يا ماڊيول، فائل وغيره
-- env.docTitle - /doc ذيلي صفحو
-- env.sandboxTitle - /sandbox ذيلي صفحو
-- env.testcasesTitle - /testcases ذيلي صفحو
--
-- Data ۾ شامل آهن:
-- env.protectionLevels - title object جي protection levels جدول
-- env.subjectSpace - title جي subject namespace جو نمبر
-- env.docSpace - ان namespace جو نمبر جنهن ۾ title پنهنجي documentation رکي ٿو
-- env.docpageBase - /doc، /sandbox ۽ /testcases صفحن جي base page جو متن، namespace سميت
-- env.compareUrl - Special:ComparePages صفحي جو URL، جيڪو sandbox کي template سان ڀيٽي ٿو
--
-- سڀئي table lookups pcall مان گذاريا وڃن ٿا ته جيئن غلطيون پڪڙجي سگهن.
-- جيڪڏهن ڪا غلطي ٿئي، ته واپس ٿيندڙ قدر nil هوندي.
--]]
local env, envFuncs = {}, {}
-- metatable مقرر ڪريو. جيڪڏهن trigger ٿئي ته اسان envFuncs ٽيبل ۾ موجود لاڳاپيل
-- فنڪشن سڏيون ٿا. ان فنڪشن طرفان واپس ڪيل قدر env ٽيبل ۾ memoize ڪئي وڃي ٿي،
-- ته جيئن اسان ڪنهن به فنڪشن کي هڪ کان وڌيڪ ڀيرا نه سڏيون. (nil قدر memoize نه ٿيندا.)
setmetatable(env, {
__index = function (t, key)
local envFunc = envFuncs[key]
if envFunc then
local success, val = pcall(envFunc)
if success then
env[key] = val -- قدر کي memoise ڪريو.
return val
end
end
return nil
end
})
function envFuncs.title()
-- موجوده صفحي جو title object، يا args.page سان موڪليل test page.
local title
local titleArg = args.page
if titleArg then
title = mw.title.new(titleArg)
else
title = mw.title.getCurrentTitle()
end
return title
end
function envFuncs.templateTitle()
--[[
-- سانچي، يا ماڊيول وغيره جو title object.
-- Messages:
-- 'sandbox-subpage' --> 'sandbox'
-- 'testcases-subpage' --> 'testcases'
--]]
local subjectSpace = env.subjectSpace
local title = env.title
local subpage = title.subpageText
if subpage == message('sandbox-subpage') or subpage == message('testcases-subpage') or (subpage == message('doc-subpage') and mw.title.getCurrentTitle().namespace == env.docSpace) then
return mw.title.makeTitle(subjectSpace, title.baseText)
else
return mw.title.makeTitle(subjectSpace, title.text)
end
end
function envFuncs.docTitle()
--[[
-- /doc ذيلي صفحي جو title object.
-- Messages:
-- 'doc-subpage' --> 'doc'
--]]
local title = env.title
local docname = args[1] -- استعمال ڪندڙ طرفان مقرر ڪيل doc page.
local docpage
if docname then
docpage = docname
else
docpage = env.docpageBase .. '/' .. message('doc-subpage')
end
return mw.title.new(docpage)
end
function envFuncs.sandboxTitle()
--[[
-- /sandbox ذيلي صفحي لاءِ title object.
-- Messages:
-- 'sandbox-subpage' --> 'sandbox'
--]]
return mw.title.new(env.docpageBase .. '/' .. message('sandbox-subpage'))
end
function envFuncs.testcasesTitle()
--[[
-- /testcases ذيلي صفحي لاءِ title object.
-- Messages:
-- 'testcases-subpage' --> 'testcases'
--]]
return mw.title.new(env.docpageBase .. '/' .. message('testcases-subpage'))
end
function envFuncs.protectionLevels()
-- title object جي protection levels جدول.
return env.title.protectionLevels
end
function envFuncs.subjectSpace()
-- subject namespace نمبر.
return mw.site.namespaces[env.title.namespace].subject.id
end
function envFuncs.docSpace()
-- documentation namespace نمبر. گهڻن namespaces لاءِ اهو subject namespace
-- جهڙو ئي هوندو آهي. پر Article، File، MediaWiki يا Category namespaces
-- ۾ صفحن جا /doc، /sandbox ۽ /testcases صفحا talk space ۾ هجڻ گهرجن.
local subjectSpace = env.subjectSpace
if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then
return subjectSpace + 1
else
return subjectSpace
end
end
function envFuncs.docpageBase()
-- /doc، /sandbox ۽ /testcases ذيلي صفحن جو base page.
-- ڪجهه namespaces لاءِ اهو template page بدران talk page هوندو آهي.
local templateTitle = env.templateTitle
local docSpace = env.docSpace
local docSpaceText = mw.site.namespaces[docSpace].name
-- لنڪ گڏ ڪريو. docSpace ڪڏهن به main namespace نه هوندو، تنهنڪري colon hardcode ڪري سگهجي ٿو.
return docSpaceText .. ':' .. templateTitle.text
end
function envFuncs.compareUrl()
-- [[Special:ComparePages]] استعمال ڪندي sandbox ۽ main template جي وچ ۾ diff link.
local templateTitle = env.templateTitle
local sandboxTitle = env.sandboxTitle
if templateTitle.exists and sandboxTitle.exists then
local compareUrl = mw.uri.canonicalUrl(
'Special:ComparePages',
{ page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText}
)
return tostring(compareUrl)
else
return nil
end
end
return env
end
----------------------------------------------------------------------------
-- معاون سانچا
----------------------------------------------------------------------------
p.getModuleWikitext = makeInvokeFunc('_getModuleWikitext')
function p._getModuleWikitext(args, env)
local currentTitle = mw.title.getCurrentTitle()
if currentTitle.contentModel ~= 'Scribunto' then return end
pcall(require, currentTitle.prefixedText) -- جيڪڏهن ناڪام ٿئي ته اسان کي پرواهه ناهي
local moduleWikitext = package.loaded["Module:Module wikitext"]
if moduleWikitext then
return moduleWikitext.main()
end
end
function p.sandboxNotice(args, env)
--[=[
-- sandbox صفحن جي مٿان ڏيکارڻ لاءِ sandbox notice پيدا ڪري ٿو.
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي ٽيبل
-- @env - environment ٽيبل جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
--
-- Messages:
-- 'sandbox-notice-image' --> '[[File:Sandbox.svg|50px|alt=|link=]]'
-- 'sandbox-notice-blurb' --> 'This is the $1 for $2.'
-- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).'
-- 'sandbox-notice-pagetype-template' --> '[[Wikipedia:Template test cases|template sandbox]] page'
-- 'sandbox-notice-pagetype-module' --> '[[Wikipedia:Template test cases|module sandbox]] page'
-- 'sandbox-notice-pagetype-other' --> 'sandbox page'
-- 'sandbox-notice-compare-link-display' --> 'diff'
-- 'sandbox-notice-testcases-blurb' --> 'See also the companion subpage for $1.'
-- 'sandbox-notice-testcases-link-display' --> 'test cases'
-- 'sandbox-category' --> 'Template sandboxes'
-- 'module-sandbox-category' --> 'Module sandboxes'
-- 'other-sandbox-category' --> 'Sandboxes outside of template or module namespace'
--]=]
local title = env.title
local sandboxTitle = env.sandboxTitle
local templateTitle = env.templateTitle
local subjectSpace = env.subjectSpace
if not (subjectSpace and title and sandboxTitle and templateTitle
and mw.title.equals(title, sandboxTitle)) then
return nil
end
-- {{ombox}} ڏانهن موڪلڻ لاءِ دليلن جي ٽيبل ٺاهيو. اسان کي صرف ٻه fields گهرجن: "image" ۽ "text".
local omargs = {}
omargs.image = message('sandbox-notice-image')
-- متن حاصل ڪريو. اسان شروعاتي عبارت سان شروع ڪريون ٿا، جيڪا ڪجهه هن طرح هوندي:
-- "This is the template sandbox for [[Template:Foo]] (diff)."
local text = '__EXPECTUNUSEDTEMPLATE__'
local pagetype, sandboxCat
if subjectSpace == 10 then
pagetype = message('sandbox-notice-pagetype-template')
sandboxCat = message('sandbox-category')
elseif subjectSpace == 828 then
pagetype = message('sandbox-notice-pagetype-module')
sandboxCat = message('module-sandbox-category')
else
pagetype = message('sandbox-notice-pagetype-other')
sandboxCat = message('other-sandbox-category')
end
local templateLink = makeWikilink(templateTitle.prefixedText)
local compareUrl = env.compareUrl
if compareUrl then
local compareDisplay = message('sandbox-notice-compare-link-display')
local compareLink = makeUrlLink(compareUrl, compareDisplay)
text = text .. message('sandbox-notice-diff-blurb', {pagetype, templateLink, compareLink})
else
text = text .. message('sandbox-notice-blurb', {pagetype, templateLink})
end
-- جيڪڏهن test cases صفحو موجود هجي ته ان جي عبارت حاصل ڪريو. اها ڪجهه هن طرح هوندي:
-- "See also the companion subpage for [[Template:Foo/testcases|test cases]]."
local testcasesTitle = env.testcasesTitle
if testcasesTitle and testcasesTitle.exists then
if testcasesTitle.contentModel == "Scribunto" then
local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display')
local testcasesRunLinkDisplay = message('sandbox-notice-testcases-run-link-display')
local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay)
local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay)
text = text .. '<br />' .. message('sandbox-notice-testcases-run-blurb', {testcasesLink, testcasesRunLink})
else
local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display')
local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay)
text = text .. '<br />' .. message('sandbox-notice-testcases-blurb', {testcasesLink})
end
end
-- sandbox کي sandbox category ۾ شامل ڪريو.
omargs.text = text .. makeCategoryLink(sandboxCat)
-- 'documentation-clear'
return '<div class="' .. message('clear') .. '"></div>'
.. require('Module:Message box').main('ombox', omargs)
end
function p.protectionTemplate(env)
-- مٿي ساڄي پاسي padlock icon پيدا ڪري ٿو.
-- @env - environment ٽيبل جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
-- Messages:
-- 'protection-template' --> 'pp-template'
-- 'protection-template-args' --> {docusage = 'yes'}
local protectionLevels = env.protectionLevels
if not protectionLevels then
return nil
end
local editProt = protectionLevels.edit and protectionLevels.edit[1]
local moveProt = protectionLevels.move and protectionLevels.move[1]
if editProt then
-- صفحو edit-protected آهي.
return require('Module:Protection banner')._main{
message('protection-reason-edit'), small = true
}
elseif moveProt and moveProt ~= 'autoconfirmed' then
-- صفحو move-protected آهي، پر edit-protected نه آهي. "autoconfirmed"
-- level واري move protection کي شامل نه ڪريو، ڇو ته اها اصل ۾
-- move protection نه هجڻ جي برابر آهي.
return require('Module:Protection banner')._main{
action = 'move', small = true
}
else
return nil
end
end
----------------------------------------------------------------------------
-- Start box
----------------------------------------------------------------------------
p.startBox = makeInvokeFunc('_startBox')
function p._startBox(args, env)
--[[
-- هي فنڪشن start box پيدا ڪري ٿو.
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي ٽيبل
-- @env - environment ٽيبل جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
--
-- اصل ڪم p.makeStartBoxLinksData ۽ p.renderStartBoxLinks ڪن ٿا، جيڪي
-- [view] [edit] [history] [purge] لنڪون ٺاهين ٿا؛ ۽ p.makeStartBoxData
-- ۽ p.renderStartBox ڪن ٿا، جيڪي box HTML پيدا ڪن ٿا.
--]]
env = env or p.getEnvironment(args)
local links
local content = args.content
if not content or args[1] then
-- جيڪڏهن documentation خود template page تي هجي ته links شامل ڪرڻ جي ضرورت ناهي.
local linksData = p.makeStartBoxLinksData(args, env)
if linksData then
links = p.renderStartBoxLinks(linksData)
end
end
-- start box html پيدا ڪريو.
local data = p.makeStartBoxData(args, env, links)
if data then
return p.renderStartBox(data)
else
-- استعمال ڪندڙ heading نه رکڻ جو چيو آهي.
return nil
end
end
function p.makeStartBoxLinksData(args, env)
--[[
-- [view] [edit] [history] [purge] لنڪون ٺاهڻ لاءِ data جي شروعاتي processing ڪري ٿو.
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي ٽيبل
-- @env - environment ٽيبل جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
--
-- Messages:
-- 'view-link-display' --> 'view'
-- 'edit-link-display' --> 'edit'
-- 'history-link-display' --> 'history'
-- 'purge-link-display' --> 'purge'
-- 'module-preload' --> 'Template:Documentation/preload-module-doc'
-- 'docpage-preload' --> 'Template:Documentation/preload'
-- 'create-link-display' --> 'create'
--]]
local subjectSpace = env.subjectSpace
local title = env.title
local docTitle = env.docTitle
if not title or not docTitle then
return nil
end
if docTitle.isRedirect then
docTitle = docTitle.redirectTarget
end
-- جيڪڏهن /doc موجود نه هجي ته create link ٺاهيو.
local preload = args.preload
if not preload then
if subjectSpace == 828 then -- Module namespace
preload = message('module-preload')
else
preload = message('docpage-preload')
end
end
return {
title = title,
docTitle = docTitle,
-- جيڪڏهن /doc موجود هجي ته view، display، edit ۽ purge لنڪون.
viewLinkDisplay = message('view-link-display'),
editLinkDisplay = message('edit-link-display'),
historyLinkDisplay = message('history-link-display'),
purgeLinkDisplay = message('purge-link-display'),
preload = preload,
createLinkDisplay = message('create-link-display')
}
end
function p.renderStartBoxLinks(data)
--[[
-- data جدول مان [view][edit][history][purge] يا [create][purge] لنڪون پيدا ڪري ٿو.
-- @data - p.makeStartBoxLinksData طرفان پيدا ڪيل data جي جدول
--]]
local docTitle = data.docTitle
-- ها، اسان واقعي ان template page کي purge ڪرڻ چاهيون ٿا، جنهن تي documentation ظاهر ٿئي ٿي
local purgeLink = makeWikilink("Special:Purge/" .. data.title.prefixedText, data.purgeLinkDisplay)
if docTitle.exists then
local viewLink = makeWikilink(docTitle.prefixedText, data.viewLinkDisplay)
local editLink = makeWikilink("Special:EditPage/" .. docTitle.prefixedText, data.editLinkDisplay)
local historyLink = makeWikilink("Special:PageHistory/" .. docTitle.prefixedText, data.historyLinkDisplay)
return "[" .. viewLink .. "] [" .. editLink .. "] [" .. historyLink .. "] [" .. purgeLink .. "]"
else
local createLink = makeUrlLink(docTitle:canonicalUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay)
return "[" .. createLink .. "] [" .. purgeLink .. "]"
end
return ret
end
function p.makeStartBoxData(args, env, links)
--[=[
-- start-box render function، p.renderStartBox، ڏانهن موڪلڻ لاءِ data جي شروعاتي processing ڪري ٿو.
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي ٽيبل
-- @env - environment جدول جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
-- @links - اها string جنهن ۾ [view][edit][history][purge] لنڪون آهن؛ جيڪڏهن غلطي هجي ته nil ٿي سگهي ٿي.
--
-- Messages:
-- 'documentation-icon-wikitext' --> '[[File:Test Template Info-Icon - Version (2).svg|50px|link=|alt=]]'
-- 'template-namespace-heading' --> 'Template documentation'
-- 'module-namespace-heading' --> 'Module documentation'
-- 'file-namespace-heading' --> 'Summary'
-- 'other-namespaces-heading' --> 'Documentation'
-- 'testcases-create-link-display' --> 'create'
--]=]
local subjectSpace = env.subjectSpace
if not subjectSpace then
-- "other namespaces" namespace کي default طور استعمال ڪريو، ته جيئن
-- جيڪڏهن غلطي ٿئي ته به گهٽ ۾ گهٽ ڪجهه output ملي.
subjectSpace = 2
end
local data = {}
-- Heading
local heading = args.heading -- خالي قدرون نه هٽايون ويون آهن.
if heading == '' then
-- جيڪڏهن heading arg بيان ٿيل پر خالي هجي، ته start box نه ڏيکاريو.
return nil
end
if heading then
data.heading = heading
elseif subjectSpace == 10 then -- Template namespace
data.heading = message('documentation-icon-wikitext') .. ' ' .. message('template-namespace-heading')
elseif subjectSpace == 828 then -- Module namespace
data.heading = message('documentation-icon-wikitext') .. ' ' .. message('module-namespace-heading')
elseif subjectSpace == 6 then -- File namespace
data.heading = message('file-namespace-heading')
else
data.heading = message('other-namespaces-heading')
end
-- Heading CSS
local headingStyle = args['heading-style']
if headingStyle then
data.headingStyleText = headingStyle
else
-- 'documentation-heading'
data.headingClass = message('main-div-heading-class')
end
-- [view][edit][history][purge] يا [create] لنڪن لاءِ data.
if links then
-- 'mw-editsection-like plainlinks'
data.linksClass = message('start-box-link-classes')
data.links = links
end
return data
end
function p.renderStartBox(data)
-- start box html render ڪري ٿو.
-- @data - p.makeStartBoxData طرفان پيدا ڪيل data جي جدول.
local sbox = mw.html.create('div')
sbox
-- 'documentation-startbox'
:addClass(message('start-box-class'))
:newline()
:tag('span')
:addClass(data.headingClass)
:attr('id', 'documentation-heading')
:cssText(data.headingStyleText)
:wikitext(data.heading)
local links = data.links
if links then
sbox:tag('span')
:addClass(data.linksClass)
:attr('id', data.linksId)
:wikitext(links)
end
return tostring(sbox)
end
----------------------------------------------------------------------------
-- دستاويزي مواد
----------------------------------------------------------------------------
p.content = makeInvokeFunc('_content')
function p._content(args, env)
-- documentation جو مواد ڏيکاري ٿو
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي ٽيبل
-- @env - environment ٽيبل جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
env = env or p.getEnvironment(args)
local docTitle = env.docTitle
local content = args.content
if not content and docTitle and docTitle.exists then
content = args._content or mw.getCurrentFrame():expandTemplate{title = docTitle.prefixedText}
end
-- هيٺ ڏنل line breaks ضروري آهن ته جيئن docs جي شروع ۽ آخر ۾ موجود
-- "=== Headings ===" صحيح نموني سمجهيا وڃن.
return '\n' .. (content or '') .. '\n'
end
p.contentTitle = makeInvokeFunc('_contentTitle')
function p._contentTitle(args, env)
env = env or p.getEnvironment(args)
local docTitle = env.docTitle
if not args.content and docTitle and docTitle.exists then
return docTitle.prefixedText
else
return ''
end
end
----------------------------------------------------------------------------
-- End box
----------------------------------------------------------------------------
p.endBox = makeInvokeFunc('_endBox')
function p._endBox(args, env)
--[=[
-- هي فنڪشن end box پيدا ڪري ٿو، جنهن کي link box پڻ چيو وڃي ٿو.
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي ٽيبل
-- @env - environment ٽيبل جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
--
--]=]
-- environment data حاصل ڪريو.
env = env or p.getEnvironment(args)
local subjectSpace = env.subjectSpace
local docTitle = env.docTitle
if not subjectSpace or not docTitle then
return nil
end
-- چيڪ ڪريو ته end box اصل ۾ ڏيکارڻ گهرجي يا نه. ڊفالٽ طور end
-- box شامل ڪريو جيڪڏهن documentation موجود هجي يا اسان user، module يا template namespaces ۾ هجون.
local linkBox = args['link box']
if linkBox == 'off'
or not (
docTitle.exists
or subjectSpace == 2
or subjectSpace == 828
or subjectSpace == 10
)
then
return nil
end
-- link box گڏ ڪريو.
local text = ''
if linkBox then
text = text .. linkBox
else
text = text .. (p.makeDocPageBlurb(args, env) or '') -- "This documentation is transcluded from [[Foo]]."
if subjectSpace == 2 or subjectSpace == 10 or subjectSpace == 828 then
-- اسان user، template يا module namespaces ۾ آهيون.
-- sandbox ۽ testcases لنڪون شامل ڪريو.
-- "Editors can experiment in this template's sandbox and testcases pages."
text = text .. (p.makeExperimentBlurb(args, env) or '') .. '<br />'
if not args.content and not args[1] then
-- "Please add categories to the /doc subpage."
-- inline docs يا واضح طور مقرر ڪيل doc page سان هي پيغام نه ڏيکاريو،
-- ڇو ته پوءِ واضح ناهي ته زمرا ڪٿي شامل ڪيا وڃن.
text = text .. (p.makeCategoriesBlurb(args, env) or '')
end
text = text .. ' ' .. (p.makeSubpagesBlurb(args, env) or '') --"Subpages of this template"
end
end
local box = mw.html.create('div')
-- 'documentation-metadata'
box:attr('role', 'note')
:addClass(message('end-box-class'))
-- 'plainlinks'
:addClass(message('end-box-plainlinks'))
:wikitext(text)
:done()
return '\n' .. tostring(box)
end
function p.makeDocPageBlurb(args, env)
--[=[
-- اها عبارت ٺاهي ٿو: "This documentation is transcluded from [[Template:Foo]] (edit, history)".
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي ٽيبل
-- @env - environment ٽيبل جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
--
-- Messages:
-- 'edit-link-display' --> 'edit'
-- 'history-link-display' --> 'history'
-- 'transcluded-from-blurb' -->
-- 'The above [[Wikipedia:Template documentation|documentation]]
-- is [[Help:Transclusion|transcluded]] from $1.'
-- 'module-preload' --> 'Template:Documentation/preload-module-doc'
-- 'create-link-display' --> 'create'
-- 'create-module-doc-blurb' -->
-- 'You might want to $1 a documentation page for this [[Wikipedia:Lua|Scribunto module]].'
--]=]
local docTitle = env.docTitle
if not docTitle then
return nil
end
if docTitle.exists then
-- /doc موجود آهي؛ ان ڏانهن لنڪ ڏيو.
local docLink = makeWikilink(docTitle.prefixedText)
local editDisplay = message('edit-link-display')
local editLink = makeWikilink("Special:EditPage/" .. docTitle.prefixedText, editDisplay)
local historyDisplay = message('history-link-display')
local historyLink = makeWikilink("Special:PageHistory/" .. docTitle.prefixedText, historyDisplay)
return message('transcluded-from-blurb', {docLink})
.. ' '
.. makeToolbar(editLink, historyLink)
.. '<br />'
elseif env.subjectSpace == 828 then
-- /doc موجود نه آهي؛ ان کي ٺاهڻ لاءِ چئو.
local createUrl = docTitle:canonicalUrl{action = 'edit', preload = message('module-preload')}
local createDisplay = message('create-link-display')
local createLink = makeUrlLink(createUrl, createDisplay)
return message('create-module-doc-blurb', {createLink})
.. '<br />'
end
end
function p.makeExperimentBlurb(args, env)
--[[
-- هي متن render ڪري ٿو: "Editors can experiment in this template's sandbox (edit | diff) and testcases (edit) pages."
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي جدول
-- @env - environment ٽيبل جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
--
-- Messages:
-- 'sandbox-link-display' --> 'sandbox'
-- 'sandbox-edit-link-display' --> 'edit'
-- 'compare-link-display' --> 'diff'
-- 'module-sandbox-preload' --> 'Template:Documentation/preload-module-sandbox'
-- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox'
-- 'sandbox-create-link-display' --> 'create'
-- 'mirror-edit-summary' --> 'Create sandbox version of $1'
-- 'mirror-link-display' --> 'mirror'
-- 'mirror-link-preload' --> 'Template:Documentation/mirror'
-- 'sandbox-link-display' --> 'sandbox'
-- 'testcases-link-display' --> 'testcases'
-- 'testcases-edit-link-display'--> 'edit'
-- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox'
-- 'testcases-create-link-display' --> 'create'
-- 'testcases-link-display' --> 'testcases'
-- 'testcases-edit-link-display' --> 'edit'
-- 'module-testcases-preload' --> 'Template:Documentation/preload-module-testcases'
-- 'template-testcases-preload' --> 'Template:Documentation/preload-testcases'
-- 'experiment-blurb-module' --> 'Editors can experiment in this module's $1 and $2 pages.'
-- 'experiment-blurb-template' --> 'Editors can experiment in this template's $1 and $2 pages.'
--]]
local subjectSpace = env.subjectSpace
local templateTitle = env.templateTitle
local sandboxTitle = env.sandboxTitle
local testcasesTitle = env.testcasesTitle
local templatePage = templateTitle.prefixedText
if not subjectSpace or not templateTitle or not sandboxTitle or not testcasesTitle then
return nil
end
-- لنڪون ٺاهيو.
local sandboxLinks, testcasesLinks
if sandboxTitle.exists then
local sandboxPage = sandboxTitle.prefixedText
local sandboxDisplay = message('sandbox-link-display')
local sandboxLink = makeWikilink(sandboxPage, sandboxDisplay)
local sandboxEditDisplay = message('sandbox-edit-link-display')
local sandboxEditLink = makeWikilink("Special:EditPage/" .. sandboxPage, sandboxEditDisplay)
local compareUrl = env.compareUrl
local compareLink
if compareUrl then
local compareDisplay = message('compare-link-display')
compareLink = makeUrlLink(compareUrl, compareDisplay)
end
sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink)
else
local sandboxPreload
if subjectSpace == 828 then
sandboxPreload = message('module-sandbox-preload')
else
sandboxPreload = message('template-sandbox-preload')
end
local sandboxCreateUrl = sandboxTitle:canonicalUrl{action = 'edit', preload = sandboxPreload}
local sandboxCreateDisplay = message('sandbox-create-link-display')
local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay)
local mirrorSummary = message('mirror-edit-summary', {makeWikilink(templatePage)})
local mirrorPreload = message('mirror-link-preload')
local mirrorUrl = sandboxTitle:canonicalUrl{action = 'edit', preload = mirrorPreload, summary = mirrorSummary}
if subjectSpace == 828 then
mirrorUrl = sandboxTitle:canonicalUrl{action = 'edit', preload = templateTitle.prefixedText, summary = mirrorSummary}
end
local mirrorDisplay = message('mirror-link-display')
local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay)
sandboxLinks = message('sandbox-link-display') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
end
if testcasesTitle.exists then
local testcasesPage = testcasesTitle.prefixedText
local testcasesDisplay = message('testcases-link-display')
local testcasesLink = makeWikilink(testcasesPage, testcasesDisplay)
local testcasesEditUrl = testcasesTitle:canonicalUrl{action = 'edit'}
local testcasesEditDisplay = message('testcases-edit-link-display')
local testcasesEditLink = makeWikilink("Special:EditPage/" .. testcasesPage, testcasesEditDisplay)
-- Modules لاءِ، جيڪڏهن testcases run link موجود هجي ته اهو شامل ڪريو
if testcasesTitle.contentModel == "Scribunto" and testcasesTitle.talkPageTitle and testcasesTitle.talkPageTitle.exists then
local testcasesRunLinkDisplay = message('testcases-run-link-display')
local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay)
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink, testcasesRunLink)
else
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
end
else
local testcasesPreload
if subjectSpace == 828 then
testcasesPreload = message('module-testcases-preload')
else
testcasesPreload = message('template-testcases-preload')
end
local testcasesCreateUrl = testcasesTitle:canonicalUrl{action = 'edit', preload = testcasesPreload}
local testcasesCreateDisplay = message('testcases-create-link-display')
local testcasesCreateLink = makeUrlLink(testcasesCreateUrl, testcasesCreateDisplay)
testcasesLinks = message('testcases-link-display') .. ' ' .. makeToolbar(testcasesCreateLink)
end
local messageName
if subjectSpace == 828 then
messageName = 'experiment-blurb-module'
else
messageName = 'experiment-blurb-template'
end
return message(messageName, {sandboxLinks, testcasesLinks})
end
function p.makeCategoriesBlurb(args, env)
--[[
-- هي متن پيدا ڪري ٿو: "Please add categories to the /doc subpage."
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي ٽيبل
-- @env - environment جدول جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
-- Messages:
-- 'doc-link-display' --> '/doc'
-- 'add-categories-blurb' --> 'Please add categories to the $1 subpage.'
--]]
local docTitle = env.docTitle
if not docTitle then
return nil
end
local docPathLink = makeWikilink(docTitle.prefixedText, message('doc-link-display'))
return message('add-categories-blurb', {docPathLink})
end
function p.makeSubpagesBlurb(args, env)
--[[
-- "Subpages of this template" لنڪ پيدا ڪري ٿو.
-- @args - استعمال ڪندڙ طرفان موڪليل دليلن جي ٽيبل
-- @env - environment ٽيبل جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
-- Messages:
-- 'template-pagetype' --> 'template'
-- 'module-pagetype' --> 'module'
-- 'default-pagetype' --> 'page'
-- 'subpages-link-display' --> 'Subpages of this $1'
--]]
local subjectSpace = env.subjectSpace
local templateTitle = env.templateTitle
if not subjectSpace or not templateTitle then
return nil
end
local pagetype
if subjectSpace == 10 then
pagetype = message('template-pagetype')
elseif subjectSpace == 828 then
pagetype = message('module-pagetype')
else
pagetype = message('default-pagetype')
end
local subpagesLink = makeWikilink(
'Special:PrefixIndex/' .. templateTitle.prefixedText .. '/',
message('subpages-link-display', {pagetype})
)
return message('subpages-blurb', {subpagesLink})
end
----------------------------------------------------------------------------
-- ٽريڪنگ زمرا
----------------------------------------------------------------------------
function p.addTrackingCategories(env)
--[[
-- چيڪ ڪري ٿو ته {{documentation}} ڪنهن /doc يا /testcases صفحي تي transclude ٿيل آهي يا نه.
-- @env - environment ٽيبل جنهن ۾ title objects وغيره شامل آهن، جيڪا p.getEnvironment سان ٺهي ٿي
-- Messages:
-- 'display-strange-usage-category' --> true
-- 'doc-subpage' --> 'doc'
-- 'testcases-subpage' --> 'testcases'
-- 'strange-usage-category' --> 'Wikipedia pages with strange ((documentation)) usage'
--
-- module namespace ۾ /testcases صفحن کي categorize نه ڪيو ويو آهي، ڇو ته انهن ۾
-- {{documentation}} خودڪار طور transclude ٿيل ٿي سگهي ٿو.
--]]
local title = env.title
local subjectSpace = env.subjectSpace
if not title or not subjectSpace then
return nil
end
local subpage = title.subpageText
if message('display-strange-usage-category', nil, 'boolean')
and (
subpage == message('doc-subpage')
or subjectSpace ~= 828 and subpage == message('testcases-subpage')
)
then
return makeCategoryLink(message('strange-usage-category'))
end
return ''
end
return p