Difference between revisions of "Module:Sandbox/28bytes/acm"
Jump to navigation
Jump to search
blackwiki>28bytes (module test) |
m (15 revisions imported) |
||
| (10 intermediate revisions by one other user not shown) | |||
| Line 3: | Line 3: | ||
p.gettitle = function( frame ) | p.gettitle = function( frame ) | ||
| − | local | + | local fmter = frame.args[1] |
| − | |||
local base = frame.args[2] | local base = frame.args[2] | ||
local disam = frame.args[3] | local disam = frame.args[3] | ||
| − | + | ||
| − | local | + | if fmter == nil then |
| − | + | fmter = "" --optional | |
| − | + | end | |
| + | if base == nil or base == "" then | ||
| + | error("Missing/empty parameter; see module documentation for usage") | ||
| + | return "" | ||
| + | end | ||
| + | if disam == nil then | ||
| + | disam = "" --optional | ||
| + | end | ||
| + | |||
| + | local c = "" | ||
| + | if mw.ustring.find(fmter,"q") ~= nil then | ||
c = "\"" | c = "\"" | ||
| − | elseif ( | + | elseif mw.ustring.find(fmter,"t") ~= nil then |
c = "''" | c = "''" | ||
end | end | ||
| − | if disam == | + | local title = "" |
| + | if disam == "" then | ||
title = c .. "[[" .. base .. "]]" .. c | title = c .. "[[" .. base .. "]]" .. c | ||
else | else | ||
| − | title = "[[" .. base .. " " .. disam .. "|" .. c .. base .. c .. " " .. disam .. "]]" | + | title = "[[" .. base .. " " .. disam .. "|" .. |
| + | c .. base .. c .. " " .. disam .. "]]" | ||
end | end | ||
| − | return title | + | local separator = " " |
| + | if mw.ustring.find(fmter,"o") ~= nil then | ||
| + | separator = separator .. "‹›" | ||
| + | end | ||
| + | if mw.ustring.find(fmter,"?") ~= nil then | ||
| + | separator = separator .. "[[File:Symbol question.svg|20px]]" | ||
| + | end | ||
| + | if mw.ustring.find(fmter,"G") ~= nil then | ||
| + | separator = separator .. "[[File:Symbol support vote.svg|20px]]" | ||
| + | end | ||
| + | |||
| + | return title .. separator .. " " | ||
end | end | ||
return p | return p | ||
Latest revision as of 09:13, 27 September 2020
gettitle
This function accepts an article title and formats it with quotes or italics as specified (useful for songs, albums and books.) It can also optionally add a "Did you know" indicator and/or Good Article indicator following the article title.
Arguments
- Formatting specifiers, in any order:
- Article title excluding the disamiguator (required)
- Disambiguator (optional)
Usage examples
For a song title with a parenthetical disambiguator that should not be in quotation marks:
{{#invoke:Sandbox/28bytes/acm|gettitle|?q|Cinema|(Yes song)}}- displays "Cinema" (Yes song)

For a song title with a parenthetical that should be in quotation marks, as it is part of the title:
{{#invoke:Sandbox/28bytes/acm|gettitle|?q|I.G.Y. (What a Beautiful World)}}- displays "I.G.Y. (What a Beautiful World)"

For an album title without a parenthetical disambiguator:
{{#invoke:Sandbox/28bytes/acm|gettitle|?Gt|Move Like This}}- displays Move Like This


local p = {}
p.gettitle = function( frame )
local fmter = frame.args[1]
local base = frame.args[2]
local disam = frame.args[3]
if fmter == nil then
fmter = "" --optional
end
if base == nil or base == "" then
error("Missing/empty parameter; see module documentation for usage")
return ""
end
if disam == nil then
disam = "" --optional
end
local c = ""
if mw.ustring.find(fmter,"q") ~= nil then
c = "\""
elseif mw.ustring.find(fmter,"t") ~= nil then
c = "''"
end
local title = ""
if disam == "" then
title = c .. "[[" .. base .. "]]" .. c
else
title = "[[" .. base .. " " .. disam .. "|" ..
c .. base .. c .. " " .. disam .. "]]"
end
local separator = " "
if mw.ustring.find(fmter,"o") ~= nil then
separator = separator .. "‹›"
end
if mw.ustring.find(fmter,"?") ~= nil then
separator = separator .. "[[File:Symbol question.svg|20px]]"
end
if mw.ustring.find(fmter,"G") ~= nil then
separator = separator .. "[[File:Symbol support vote.svg|20px]]"
end
return title .. separator .. " "
end
return p