Module:FileName
From Neodyland Wiki
More actions
This documentation is transcluded from Module:FileName/doc.
-- Quick experiment with lua
-- Module for removing the extension from a file name (Should this or something like it be part of module:File?)
local p = {}
p.removeExtension = function(frame)
local page = frame.args[1] or frame.args["file"] or frame.args["title"] or mw.title.getCurrentTitle().text
local parts = mw.text.split( page , '.', true )
local upTo = #parts - 1
if (upTo) == 0 then
upTo = 1
end
return table.concat( parts, '.', 1, upTo )
end
-- I Probably shouldn't write this. This is a bad plan... I feel dirty...
-- Also probably unreliable, don't use it for anything important.
p.getYearFromInfo = function(frame)
local pattern = 'fileinfotpl_date.*<time[^>]*datetime="([^-"]*)'
local page = 'File:' .. (frame.args[1] or frame.args["file"] or frame.args["title"] or mw.title.getCurrentTitle().text)
return string.match( frame:expandTemplate{ title = page, args = {}}, pattern )
end
return p