کاربر ناشناس
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 | 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 = | 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 = | 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 = | ||
' | '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 | local link = args[1] or args.link | ||
local target = args[3] or args.target | 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 | display = args[2] or args.display, | ||
target = target, | target = target, | ||
italicizePage = yesno(args.italicizepage | italicizePage = yesno(args.italicizepage), | ||
italicizeSection = yesno(args.italicizesection | italicizeSection = yesno(args.italicizesection), | ||
categorizeMissing = args.categorizemissing | 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(' | 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) | if title and (not title.isExternal) then | ||
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 | ||