Module:TAFI article

MyWikiBiz, Author Your Legacy — Friday November 22, 2024
Revision as of 07:31, 16 July 2021 by Zoran (talk | contribs) (Pywikibot 6.4.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Template:Lua This module retrieves the page name from the (year)/(week)/1 subpages of WP:TAFI. If the page is a redirect, the redirect target is retrieved instead.

Usage

To retrieve the current article, use

{{#invoke:TAFI article|main}}

To retrieve the article for a specific year and week, use

{{#invoke:TAFI article|main|YYYY=|WW=}}

Examples

Current article (
This box: [[Template:{{{1}}}|view]]  [[Template talk:{{{1}}}|talk]]  [{{fullurl:Template:{{{1}}}|action=edit}} edit]
to update)
{{#invoke:TAFI article|main}}Lua error: expandTemplate: template "Wikipedia:Today's articles for improvement/2024/47/1" does not exist.
Article from 2015 week 32
{{#invoke:TAFI article|main|YYYY=2015|WW=32}}Lua error: expandTemplate: template "Wikipedia:Today's articles for improvement/2015/32/1" does not exist.
Resolving a redirect
{{Wikipedia:Today's articles for improvement/9999/2/1}}Template:Wikipedia:Today's articles for improvement/9999/2/1
[[{{#invoke:TAFI article|main|YYYY=9999|WW=2}}]] → [[Lua error: expandTemplate: template "Wikipedia:Today's articles for improvement/9999/2/1" does not exist.]]

Template:Sandbox other


local p = {}

local redirModule = require "Module:Redirect"
local redir = redirModule.luaMain


-- Named arguments (optional) |YYYY= and |WW= used, like: {{#invoke:TAFI article|main|YYYY=2016|WW=06}}
function p.main(frame)
	local year = frame.args.YYYY or os.date( "%G" )        -- Specified year, or else the current year
	local week = frame.args.WW or os.date( "%V" )          -- Specified week, or else the current week
        week = tonumber(week)                                  -- Remove zero-padding, if present
	local title = frame:expandTemplate{ title = 'Wikipedia:Today\'s articles for improvement/' .. year .. '/' .. week .. '/1' } -- transclude page to get article title
        article = redir(title) or title                      -- Get target if title is a redirect
        return article

end

return p