Module:ugly hacks
- The following documentation is located at Module:ugly hacks/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module provides templates with functions which cannot be accessed any other way. When a function is not used, it should be removed.
Avoid using this module. If you find yourself writing a template which needs it, consider re-writing the template in Lua.
This module tracks templates in which its functions are used, using the tracking template mechanism; the tracking templates' names are of the form Wiktionary:tracking/ugly hacks/function_name
and Wiktionary:tracking/ugly hacks/function_name/from template_name
. To prevent it from becoming ineffective, wrappers around functions in this module should not be created; the {{#invoke:}}
should be put directly where it is needed.
To further discourage their use, functions in this module are intentionally undocumented. To discover their usage purpose and syntax, please refer to mw:Extension:Scribunto/Lua reference manual.
Questions about this module and its possible replacements may be raised at Wiktionary:Grease pit.
local export = {}
function export.explode(frame)
local args = frame.args
local wanted_index, i = tonumber(args[3]), 1
for item in require("Module:string utilities").gsplit(args[1], args[2], true) do
if i == wanted_index then
return item
end
i = i + 1
end
return ""
end
function export.substr(frame)
local args = frame.args
return require("Module:string utilities").sub(args[1] or "", tonumber(args[2]) or 1, tonumber(args[3]) or -1)
end
function export.find(frame)
local args = frame.args
return require("Module:string utilities").find(args[1] or "", args[2] or "", 1, true) or ""
end
function export.find_pattern(frame)
local args = frame.args
return require("Module:string utilities").find(args[1] or "", args[2] or "", 1, false) or ""
end
function export.replace(frame)
local args = frame.args
return (require("Module:string utilities").gsub(args[1] or "", args[2] or "", args[3] or ""))
end
function export.match(frame)
local args = frame.args
return (require("Module:string utilities").match(args[1] or "", args[2] or ""))
end
function export.is_valid_page_name(frame)
return require("Module:pages").is_valid_page_name(frame.args[1]) and "valid" or ""
end
local mt = {}
function mt:__index(k)
local track = require("Module:debug/track")
local parent = mw.getCurrentFrame():getParent()
track("ugly hacks/" .. k)
if parent then
track("ugly hacks/" .. k .. "/from " .. parent:getTitle())
end
return export[k]
end
return setmetatable({}, mt)