پودمان:Redirect template/تمرین
آخرین ویرایش :
۶ آذر ۱۴۰۰
توضیحات این پودمان میتواند در پودمان:Redirect template/تمرین/توضیحات قرار گیرد.
require('Module:No globals')
local p = {}
-- key is beginning of arg name. value is table with namespace number and link
-- alternatively, a function taking the namespace number and returning a validity
-- can be used
local namespaceCategories = {
all = { function() return true end },
['همه'] = { function() return true end },
main = { 0, '[[ویکیپدیا:مقاله چیست؟|اصلی]]' },
['اصلی'] = { 0, '[[ویکیپدیا:مقاله چیست؟|اصلی]]' },
help = { 12, '[[ویکیپدیا:فضای نام راهنما|راهنما]]' },
['راهنما'] = { 12, '[[ویکیپدیا:فضای نام راهنما|راهنما]]' },
portal = { 100, '[[ویکیپدیا:درگاه|درگاه]]' },
['درگاه'] = { 100, '[[ویکیپدیا:درگاه|درگاه]]' },
talk = { function(n) return n > 0 and n%2 == 1 end, '[[راهنما:صفحه بحث|بحث]]' },
['بحث'] = { function(n) return n > 0 and n%2 == 1 end, '[[راهنما:صفحه بحث|بحث]]' },
template = { 10, '[[ویکیپدیا:فضای نام الگو|الگو]]' },
['الگو'] = { 10, '[[ویکیپدیا:فضای نام الگو|الگو]]' },
wikipedia = { 4, '[[ویکیپدیا:فضای نام ویکیپدیا|پروژه ویکیپدیا]]' },
['ویکیپدیا'] = { 4, '[[ویکیپدیا:فضای نام ویکیپدیا|پروژه ویکیپدیا]]' },
category = { 14, '[[ویکیپدیا:ردهبندی|رده]]' },
['رده'] = { 14, '[[ویکیپدیا:ردهبندی|رده]]' },
user = { 2, '[[ویکیپدیا:صفحههای کاربری|کاربر]]' },
['کاربر'] = { 2, '[[ویکیپدیا:صفحههای کاربری|کاربر]]' },
}
-- remove whitespaces from beginning and end of args
local function valueFunc(key, val)
if type(val) == 'string' then
val = mw.ustring.match(val, '^%s*(.-)%s*$')
if val == '' then
return nil
end
end
return val
end
local function getPrettyName(args)
for k in pairs(namespaceCategories) do
if args[k .. ' category'] or args['رده ' .. k] then
return mw.ustring.format("'''[[:رده:%s|%s]]''': ", args[k .. ' category'] or args['رده ' .. k], args.name or args['نام'])
end
end
return mw.ustring.format("'''%s''': ", args.name or args['نام'])
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'الگو:الگوی تغییرمسیر', valueFunc = valueFunc})
local namespace = mw.title.getCurrentTitle().namespace
--- XXX: this is a HORRIBLE HACK. kill it with fire as soon as https://bugzilla.wikimedia.org/show_bug.cgi?id=12974 is fixed
local beCompatibleWithBug12974 = (args['اطلاعات'] or args.info) and (mw.ustring.find(args.info or args['اطلاعات'], '^[:;#*]', 1) == 1 or mw.ustring.find(args.info or args['اطلاعات'], '{|', 1, true) == 1) and '\n' or ' '
local content = mw.ustring.format('\n<div class="rcat %s">\n*%sاین یک تغییرمسیر است%s%s.%s%s\n</div>',
(args.id or args['شناسه']) and ('rcat-' .. mw.ustring.gsub(args.id or args['شناسه'], ' ', '_')) or '',
(args.name or args['نام']) and getPrettyName(args) or '',
(args.from or args['از']) and (' از ' .. args.from or args['از']) or '',
(args.to or args['به']) and (' به ' .. args.to or args['به']) or '',
(args.info or args['اطلاعات']) and beCompatibleWithBug12974 or '',
args.info or args['اطلاعات'] or ''
)
for k,v in pairs(namespaceCategories) do
if args[k .. ' category'] or args['رده ' .. k] then
if type(v[1]) == 'function' and v[1](namespace) or v[1] == namespace then
content = content .. mw.ustring.format('[[رده:%s]]', args[k .. ' category'] or args['رده ' .. k])
elseif args['other category'] or args['رده دیگر'] then
content = content .. mw.ustring.format('[[رده:%s]]', args['other category'] or args['رده دیگر'])
else
content = content .. frame:expandTemplate{title = 'الگوی تغییرمسیر نادرست', args = {v[2]}}
end
end
end
if namespace == 0 then
local yesno = require('Module:Yesno')
if yesno(args.printworthy) == true or yesno(args['قابل چاپ']) == true then
return content .. '[[رده:تغییرمسیرهای قابل چاپ]]'
elseif yesno(args.printworthy) == false or yesno(args['قابل چاپ']) == false then
return content .. '[[رده:تغییرمسیرهای فاقد ارزش چاپ]]'
end
end
return content
end
return p