پودمان:Redirect template: تفاوت میان نسخه‌ها

۱٬۶۳۶ بایت اضافه‌شده ،  ‏۳ آوریل ۲۰۲۲
جز
۱ نسخه واردشده
جز (۱ نسخه واردشده)
جز (۱ نسخه واردشده)
 
(یک نسخهٔ میانی ویرایش شده توسط یک کاربر دیگر نشان داده نشد)
خط ۸: خط ۸:
local namespaceCategories = {
local namespaceCategories = {
all = { function() return true end },
all = { function() return true end },
['همه'] = { function() return true end },
main = { 0, '[[ویکی‌پدیا:مقاله چیست؟|اصلی]]' },
main = { 0, '[[ویکی‌پدیا:مقاله چیست؟|اصلی]]' },
['اصلی'] = { 0, '[[ویکی‌پدیا:مقاله چیست؟|اصلی]]' },
help = { 12, '[[ویکی‌پدیا:فضای نام راهنما|راهنما]]' },
help = { 12, '[[ویکی‌پدیا:فضای نام راهنما|راهنما]]' },
['راهنما'] = { 12, '[[ویکی‌پدیا:فضای نام راهنما|راهنما]]' },
portal = { 100, '[[ویکی‌پدیا:درگاه|درگاه]]' },
portal = { 100, '[[ویکی‌پدیا:درگاه|درگاه]]' },
['درگاه'] = { 100, '[[ویکی‌پدیا:درگاه|درگاه]]' },
talk = { function(n) return n > 0 and n%2 == 1 end, '[[راهنما:صفحه بحث|بحث]]' },
talk = { function(n) return n > 0 and n%2 == 1 end, '[[راهنما:صفحه بحث|بحث]]' },
['بحث'] = { function(n) return n > 0 and n%2 == 1 end, '[[راهنما:صفحه بحث|بحث]]' },
template = { 10, '[[ویکی‌پدیا:فضای نام الگو|الگو]]' },
template = { 10, '[[ویکی‌پدیا:فضای نام الگو|الگو]]' },
['الگو'] = { 10, '[[ویکی‌پدیا:فضای نام الگو|الگو]]' },
wikipedia = { 4, '[[ویکی‌پدیا:فضای نام ویکی‌پدیا|پروژه ویکی‌پدیا]]' },
wikipedia = { 4, '[[ویکی‌پدیا:فضای نام ویکی‌پدیا|پروژه ویکی‌پدیا]]' },
['ویکی‌پدیا'] = { 4, '[[ویکی‌پدیا:فضای نام ویکی‌پدیا|پروژه ویکی‌پدیا]]' },
category = { 14, '[[ویکی‌پدیا:رده‌بندی|رده]]' },
category = { 14, '[[ویکی‌پدیا:رده‌بندی|رده]]' },
['رده'] = { 14, '[[ویکی‌پدیا:رده‌بندی|رده]]' },
user = { 2, '[[ویکی‌پدیا:صفحه‌های کاربری|کاربر]]' },
user = { 2, '[[ویکی‌پدیا:صفحه‌های کاربری|کاربر]]' },
['کاربر'] = { 2, '[[ویکی‌پدیا:صفحه‌های کاربری|کاربر]]' },
}
}


خط ۲۱: خط ۳۰:
local function valueFunc(key, val)
local function valueFunc(key, val)
if type(val) == 'string' then
if type(val) == 'string' then
val = val:match('^%s*(.-)%s*$')
val = mw.ustring.match(val, '^%s*(.-)%s*$')
if val == '' and key ~= 'category' and key ~= 'embed' then
if val == '' and key ~= 'category' and key ~= 'رده' and key ~= 'embed' and key ~= 'تعبیه' then
return nil
return nil
end
end
خط ۳۱: خط ۴۰:
local function getPrettyName(args)
local function getPrettyName(args)
for k in pairs(namespaceCategories) do
for k in pairs(namespaceCategories) do
if args[k .. ' category'] then
if args[k .. ' category'] or args['رده ' .. k] then
return  "'''[[:رده:" .. args[k .. ' category'] .. "|" .. args.name .. "]]''': "
return  "'''[[:رده:" .. (args[k .. ' category'] or args['رده ' .. k]) .. "|" .. args.name .. "]]''': "
end
end
end
end
خط ۴۱: خط ۵۰:
if not args then
if not args then
args = require('Module:Arguments').getArgs(frame, {wrappers = 'الگو:الگوی تغییرمسیر/هسته', valueFunc = valueFunc})
args = require('Module:Arguments').getArgs(frame, {wrappers = 'الگو:الگوی تغییرمسیر/هسته', valueFunc = valueFunc})
if args['تعبیه'] then args.embed = args['تعبیه'] end
if args['اطلاعات'] then args.info = args['اطلاعات'] end
if args['نام'] then args.name = args['نام'] end
if args['از'] then args.from = args['از'] end
if args['به'] then args.to = args['به'] end
end
end
local namespace = mw.title.getCurrentTitle().namespace
local namespace = mw.title.getCurrentTitle().namespace
local otherCategory = args['other category'] and (args.category or string.format('[[رده:%s]]', args['other category']))
local otherCategory = (args['other category'] or args['رده دیگر']) and (args.category or args['رده'] or mw.ustring.format('[[رده:%s]]', args['other category'] or args['رده دیگر']))
local embedPossible = args.embed == nil or args.embed == 'yes'
local embedPossible = args.embed == nil or args.embed == 'yes' or args.embed == 'بله'


--- XXX: this is a HORRIBLE HACK. kill it with fire as soon as https://bugzilla.wikimedia.org/show_bug.cgi?id=12974 is fixed
--- 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.info and (args.info:find('^[:;#*]', 1) == 1 or args.info:find('{|', 1, true) == 1) and '\n' or ' '
local beCompatibleWithBug12974 = args.info and (mw.ustring.find(args.info, '^[:;#*]', 1) == 1 or mw.ustring.find(args.info, '{|', 1, true) == 1) and '\n' or ' '
local retval = string.format('*%sاین یک تغییرمسیر است%s%s.%s%s\n',
local retval = mw.ustring.format('*%sاین یک تغییرمسیر است%s%s.%s%s\n',
embedPossible and args.name and getPrettyName(args) or '',
embedPossible and args.name and getPrettyName(args) or '',
args.from and (' از ' .. args.from) or '',
args.from and (' از ' .. args.from) or '',
خط ۵۶: خط ۷۰:
args.info or ''
args.info or ''
)
)
for k,v in pairs(namespaceCategories) do
for k, v in pairs(namespaceCategories) do
if args[k .. ' category'] then
if args[k .. ' category'] or args['رده ' .. k] then
if type(v[1]) == 'function' and v[1](namespace) or v[1] == namespace then
if type(v[1]) == 'function' and v[1](namespace) or v[1] == namespace then
retval = retval .. (args.category or string.format('[[رده:%s]]', args[k .. ' category']))
retval = retval .. (args.category or mw.ustring.format('[[رده:%s]]', args[k .. ' category'] or args['رده ' .. k]))
elseif args['other category'] then
elseif args['other category'] or args['رده دیگر'] then
retval = retval .. otherCategory
retval = retval .. otherCategory
else
else
خط ۷۲: خط ۸۶:
function p.main(frame)
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'الگو:الگوی تغییرمسیر', valueFunc = valueFunc})
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'الگو:الگوی تغییرمسیر', valueFunc = valueFunc})
-- Local arguments
if args['شناسه'] then args.id = args['شناسه'] end
if args['نام'] then args.name = args['نام'] end
if args['از'] then args.from = args['از'] end
if args['به'] then args.to = args['به'] end
local retval = p.core(frame, args)
local retval = p.core(frame, args)
if mw.title.getCurrentTitle().namespace == 0 then
if mw.title.getCurrentTitle().namespace == 0 then