Module:Filter
Appearance
Summary
[edit]Lua support routines for simple textual filters.
Entry Points
[edit]CleanParentDirectories
: (partially) canonicalise passed page name by closing up ".." level references.
- e.g. [[Reference/Sub-page/../Sub-Page 2/Page Name]] is transformed into [[Reference/Sub-Page 2/Page Name]].
- This is useful because standard parser function {{#titleparts}} will not work with page names containing embedded "/../" sequences.
- e.g. {{#titleparts:Reference/Sub-page/../Sub-Page 2/Page Name|1|1}} yields: "Reference/Sub-page/../Sub-Page 2/Page Name",
- whereas {{#titleparts:Reference/Sub-Page 2/Page Name|1|1}} yields "Reference".
Utilisation
[edit]Currently used by these templates:
- {{TOC link}}: Create link internal to a given work; appropriate to current namespace (Page:/Index: or main)
Filter = {};
--[[
CleanParentDirectories
Main entry point for Lua test function to strip redundant ../'s from page name.
Usage:
{{#invoke:Filter|CleanParentDirectories|PageName}}
]]
function Filter.CleanParentDirectories(frame)
local PageName = frame.args[1] or ""
local oldPageName = ''
while ( oldPageName ~= PageName ) do
oldPageName = PageName
PageName = mw.ustring.gsub( PageName, '/[^/]*/\.\./', '/' )..''
end
return PageName
end
return Filter