Difference between revisions of "Module:Sandbox/28bytes/acm"

From blackwiki
Jump to navigation Jump to search
blackwiki>28bytes
(module test)
blackwiki>28bytes
(module test)
Line 1: Line 1:
local p = {};
+
local p = {}
  
 
p.gettitle = function( frame )
 
p.gettitle = function( frame )
 
 
local c = {};
+
local title = {}
local base = frame.args[2];
+
local c = {}
local disam = frame.args[3];
+
local base = frame.args[2]
 +
local disam = frame.args[3]
 +
local qfound = mw.ustring.find(frame.args[1],"q")
 +
local tfound = mw.ustring.find(frame.args[1],"t")
 
 
if mw.ustring.find(frame.args[1],"q") > 0 then
+
if (qfound ~= nil) and (qfound ~= 0) then
c = "\"";
+
c = "\""
elseif mw.ustring.find(frame.args[1],"t") > 0 then
+
elseif (tfound ~= nil) and (tfound ~= 0) then
c = "''";
+
c = "''"
 
end
 
end
 
 
 
if disam == {} then
 
if disam == {} then
return c .. "[[" .. base .. "]]" .. c;
+
title = c .. "[[" .. base .. "]]" .. c
 
else
 
else
return "[[" .. base .. " " .. disam .. "|" .. c .. base .. c ..  " " .. disam .. "]]";
+
title = "[[" .. base .. " " .. disam .. "|" .. c .. base .. c ..  " " .. disam .. "]]"
 
end
 
end
 +
 +
return title
 
 
 
end
 
end
  
 
return p
 
return p

Revision as of 08:04, 8 December 2018

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

  1. Formatting specifiers, in any order:
    • q to display the title excluding the disambiguator (if any) in quotes
    • t to display the title excluding the disambiguator (if any) in italics
    • ? to display this symbol after the article title: Symbol question.svg
    • G to display this symbol after the article title: Symbol support vote.svg
    • o to display ‹› after the article title
  2. Article title excluding the disamiguator (required)
  3. 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 Lua error at line 21: attempt to concatenate local 'disam' (a nil value).

For an album title without a parenthetical disambiguator:

{{#invoke:Sandbox/28bytes/acm|gettitle|?Gt|Move Like This}}
displays Lua error at line 21: attempt to concatenate local 'disam' (a nil value).

local p = {}

p.gettitle = function( frame )
	
	local title = {}
	local c = {}
	local base = frame.args[2]
	local disam = frame.args[3]
	local qfound = mw.ustring.find(frame.args[1],"q")
	local tfound = mw.ustring.find(frame.args[1],"t")
	
	if (qfound ~= nil) and (qfound ~= 0) then
		c = "\""
	elseif (tfound ~= nil) and (tfound ~= 0) then
		c = "''"
	end
	
	if disam == {} then
		title = c .. "[[" .. base .. "]]" .. c
	else
		title = "[[" .. base .. " " .. disam .. "|" .. c .. base .. c ..  " " .. disam .. "]]"
	end
	
	return title
		
end

return p