Diff: Module:Purge
Comparing revision #1 (2017-11-13 16:20:48) with revision #2 (2023-02-04 10:26:41).
| Old | New |
|---|---|
-- This module implements [[Template:Purge]]. |
-- This module implements [[Template:Purge]]. |
local p = {} |
local p = {} |
local function makeUrlLink(url, display) |
local function makeUrlLink(url, display) |
return string.format('[%s %s]', url, display) |
return string.format('[%s %s]', url, display) |
end |
end |
function p._main(args) |
function p._main(args) |
-- Make the URL |
-- Make the URL |
local url |
local url |
do |
do |
local title |
local title |
if args.page then |
if args.page then |
title = mw.title.new(args.page) |
title = mw.title.new(args.page) |
if not title then |
if not title then |
error(string.format( |
error(string.format( |
"'%s' is not a valid page name", |
"'%s' is not a valid page name", |
args.page |
args.page |
), 2) |
), 2) |
end |
end |
else |
else |
title = mw.title.getCurrentTitle() |
title = mw.title.getCurrentTitle() |
end |
end |
if args.anchor then |
if args.anchor then |
title.fragment = args.anchor |
title.fragment = args.anchor |
end |
end |
url = title:fullUrl{action = 'purge'} |
url = title:fullUrl{action = 'purge'} |
end |
end |
-- Make the display |
-- Make the display |
local display |
local display |
if args.page then |
if args.page then |
display = args[1] or 'Purge' |
display = args[1] or 'Purge' |
else |
else |
display = mw.html.create('span') |
display = mw.html.create('span') |
display |
display |
:attr('title', 'Purge this page') |
:attr('title', 'Purge this page') |
:wikitext(args[1] or 'Purge') |
:wikitext(args[1] or 'Purge') |
display = tostring(display) |
display = tostring(display) |
end |
end |
-- Output the HTML |
-- Output the HTML |
local root = mw.html.create('span') |
local root = mw.html.create('span') |
root |
root |
:addClass('noprint') |
:addClass('noprint') |
:addClass('plainlinks') |
:addClass('plainlinks') |
:addClass('purgelink') |
:addClass('purgelink') |
:wikitext(makeUrlLink(url, display)) |
:wikitext(makeUrlLink(url, display)) |
return tostring(root) |
return tostring(root) |
end |
end |
function p.main(frame) |
function p.main(frame) |
local args = frame:getParent().args |
local args = frame:getParent().args |
return p._main(args) |
return p._main(args) |
end |
end |
return p |
return p |