Module:Sandbox/Mant08/IMDb name
Appearance
< Module:Sandbox | Mant08
| This module is rated as alpha. It is ready for limited use and third-party feedback. It may be used on a small number of pages, but should be monitored closely. Suggestions for new features or adjustments to input and output are welcome. |
Usage
[edit]This module implements the legacy Template:IMDb name logic, using Lua.
It is supposed to be used through Template:X., by writing:
{{#invoke:Sandbox/Mant08/IMDb name|imdb_name}}
This module was created with the goal to improve the perfomance of the Template:IMDb name, by utilising the advantages of speed, Scrubinito Lua modules enable.
For an example on how can this module be used to power Template:IMDb name, see: Template: X.
Implementation details
[edit]This code has been already tested, in a slightly altered manner to confrom for language diffrencies, in the EL-GR Wikipedia, with stable results, with it being used to power the IMDb name Template, in the mainspace.
See: [[1]]
local p = {}
local getArgs = require('Module:Arguments').getArgs
function p.imdb_name(frame)
local args = getArgs(frame)
return p._imdb_name(args)
end
function p._imdb_name(args)
local config = args
local section = config["3"] or config[3] or config["section"] or nil
local name = config["2"] or config [2] or config["name"] or mw.title.getCurrentTitle().text or "John Doe"
local id = config["1"] or config[1] or config["id"] or nil
local current_page_id = mw.wikibase.getEntityIdForCurrentPage()
if (id == nil)
then
if (current_page_id ~= nil)
then
local p345_value_table = mw.wikibase.getBestStatements( current_page_id, 'P345' )
if (p345_value_table ~= nil)
then
if (p345_value_table[1] ~= nil)
then
id = p345_value_table[1].mainsnak.datavalue.value
end
end
end
else
if (tonumber(id) ~= nil)
then
id = "nm" .. id
else
id = id
end
end
local at_imdb_text = "at [[IMDb]]."
if (id == nil)
then
local encoded_name = mw.uri.encode(name)
return pronoun .. " " .. "[https://imdb.com/find/?q=" .. encoded_name .. "&s=nm" .. " " .. name .. "]" .. at_imdb_text
else
local base_link_object = "[https://imdb.com/name/" .. id .. "/"
if (section == nil)
then
return pronoun .. " " .. base_link_object .. " " .. name .. "]" .. at_imdb_text
elseif (section == "biography" or section == "bio")
then
return "The biography of " .. base_link_object .. "bio/ " .. name .. "]" .. at_imdb_text
elseif (section == "awards" or section == "award")
then
return "The awards of " .. base_link_object .. "awards/ " .. name .. "]" .. at_imdb_text
else
return '<span class="error">IMDb Name: Error: A non-valid "section" variable input was given.</span>'
end
end
end
return p