پرش به محتوا

پودمان:Format link: تفاوت میان نسخه‌ها

Avoid Lua erroring when we run out of expensive parser function calls
جز (۱ نسخه واردشده)
(Avoid Lua erroring when we run out of expensive parser function calls)
خط ۲۹: خط ۲۹:
local function removeInitialColon(s)
local function removeInitialColon(s)
-- Removes the initial colon from a string, if present.
-- Removes the initial colon from a string, if present.
return mw.ustring.match(s, '^:?(.*)')
return s:match('^:?(.*)')
end
end


خط ۵۲: خط ۵۲:
-- Find whether a faux display value has been added with the {{!}} magic
-- Find whether a faux display value has been added with the {{!}} magic
-- word.
-- word.
local prePipe, display = mw.ustring.match(link, '^(.-)|(.*)$')
local prePipe, display = link:match('^(.-)|(.*)$')
link = prePipe or link
link = prePipe or link


-- Find the page, if it exists.
-- Find the page, if it exists.
-- For links like [[#Bar]], the page will be nil.
-- For links like [[#Bar]], the page will be nil.
local preHash, postHash = mw.ustring.match(link, '^(.-)#(.*)$')
local preHash, postHash = link:match('^(.-)#(.*)$')
local page
local page
if not preHash then
if not preHash then
خط ۹۹: خط ۹۹:
mError = require('Module:Error')
mError = require('Module:Error')
return mError.error{message =
return mError.error{message =
'خطا:پیوند یا هدف مشخص نشده‌است! ([[' .. target .. '#خطاها|راهنما]])'
'Error: no link or target specified! ([[' .. target .. '#Errors|help]])'
}
}
end
end
خط ۱۱۱: خط ۱۱۱:
yesno = require('Module:Yesno')
yesno = require('Module:Yesno')
local args = getArgs(frame)
local args = getArgs(frame)
local link = args[1] or args.link or args['پیوند']
local link = args[1] or args.link
local target = args[3] or args.target or args['هدف']
local target = args[3] or args.target
if not (link or target) then
if not (link or target) then
return missingArgError('الگو:قالب‌بندی پیوند')
return missingArgError('Template:Format link')
end
end


return p._formatLink{
return p._formatLink{
link = link,
link = link,
display = args[2] or args.display or args['نمایش'],
display = args[2] or args.display,
target = target,
target = target,
italicizePage = yesno(args.italicizepage or args['صفحه ایتالیک']),
italicizePage = yesno(args.italicizepage),
italicizeSection = yesno(args.italicizesection or args['بخش ایتالیک']),
italicizeSection = yesno(args.italicizesection),
categorizeMissing = args.categorizemissing or args['رده‌بندی ناموجودها']
categorizeMissing = args.categorizemissing
}
}
end
end
خط ۱۴۶: خط ۱۴۶:
if options.target == '' then options.target = nil end
if options.target == '' then options.target = nil end
if not (options.link or options.target) then
if not (options.link or options.target) then
return missingArgError('پودمان:Format link')
return missingArgError('Module:Format link')
end
end


خط ۱۶۸: خط ۱۶۸:
local title = nil
local title = nil
if parsed.page then title = mw.title.new(parsed.page) end
if parsed.page then title = mw.title.new(parsed.page) end
if title and (not title.isExternal) and (not title.exists) then
if title and (not title.isExternal) then
category = mw.ustring.format('[[رده:%s]]', catMissing)
local success, exists = pcall(function() return title.exists end)
if success and not exists then
category = mw.ustring.format('[[Category:%s]]', catMissing)
end
end
end
end
end
کاربر ناشناس