Module:Sandbox/Gonnym/sometest3/1: Difference between revisions
imported>Gonnym No edit summary |
(No difference)
|
Latest revision as of 10:05, 8 July 2019
Documentation for this module may be created at Module:Sandbox/Gonnym/sometest3/1/doc
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- TODO: currently unused.
-- local GENERAL_CATEGORY_CHARACTER = "[[Category:{} character redirects]]"
local mainRedirect = true
local printworthy = true
local redirectTemplates = ""
--[[
Local function which handles the addition of redirect templates.
--]]
local function addRedirectTemplate(redirectTemplate)
redirectTemplates = redirectTemplates .. redirectTemplate
end
--[[ TODO: currently unused.
Local function which handles the addition of character redirects
that don't belong in the "to lists" category.
local function addToGeneralCharacterCategory(categories, series)
categories = categories .. GENERAL_CATEGORY_CHARACTER:gsub("{}", series)
return categories
end--]]
--[[
Local function which handles the R from fictional character/element/location redirect template
for multiple series tags for a single topic.
This is used for example on Arrowverse or Marvel Cinematic Universe topics.
--]]
local function addToRFromFictionalObjectMulti(objectType, frame, argsTable)
if (type(elem) == "table") then
argsTable["multi"] = "yes"
addRedirectTemplate(frame:expandTemplate{title = 'R from fictional ' .. objectType, args = argsTable})
else
error("|multi_series= can only be used in other modules", 0)
end
end
--[[
Local function which handles the R from fictional character/element/location redirect template
for a single series tag.
--]]
local function addToRFromFictionalObjectSingle(objectType, frame, series)
addRedirectTemplate(frame:expandTemplate{title = 'R from fictional ' .. objectType, args = {series}})
end
--[[
Local function which checks if the redirect is tagged with a single series or multiple series.
--]]
local function addToRFromFictionalObject(objectType, frame, args)
if (args.multi_series) then
addToRFromFictionalObjectMulti(objectType, frame, args.multi_series)
else
addToRFromFictionalObjectSingle(objectType, frame, args.series)
end
end
--[[
Local function which handles all the shared character, element and location redirect handling code.
--]]
local function sharedRedirects(objectType, frame, args)
if (args.alt_spelling) then
addRedirectTemplate(frame:expandTemplate{title = 'R from alternative spelling', args = {args.alt_spelling}})
printworthy = false
mainRedirect = false
end
if (args.anchor) then
addRedirectTemplate(frame:expandTemplate{title = 'R to anchor 2'})
elseif (args.list) then
addRedirectTemplate(frame:expandTemplate{title = 'R to list entry'})
elseif (args.not_list) then
-- Do nothing atm.
else
addRedirectTemplate(frame:expandTemplate{title = 'R to section'})
end
if (args.primary) then
addRedirectTemplate("\n" .. frame:expandTemplate{title = 'R avoided double redirect', args = {args.primary}})
mainRedirect = false
end
if (args.incorrect_name) then
addRedirectTemplate(frame:expandTemplate{title = 'R from incorrect name', args = {args.incorrect_name}})
mainRedirect = false
printworthy = false
end
if (args.unneeded_dab) then
addRedirectTemplate(frame:expandTemplate{title = 'R from unnecessary disambiguation'})
mainRedirect = false
printworthy = false
end
if (args.dab_exception) then
if (mainRedirect) then
addRedirectTemplate(frame:expandTemplate{title = 'R with possibilities'})
end
addRedirectTemplate(frame:expandTemplate{title = 'R printworthy'})
else
local match = require("Module:String")._match
local title = mw.title.getCurrentTitle().text
local disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "")
local correctDisambiguation = ""
if (args.correct_disambiguation) then
correctDisambiguation = args.correct_disambiguation
elseif (args.series) then
correctDisambiguation = string.gsub(args.series, "%(.*%)", "", 1)
correctDisambiguation = mw.text.trim(correctDisambiguation)
end
if (not disambiguation or disambiguation == "" or
disambiguation == correctDisambiguation or disambiguation == correctDisambiguation .. " " .. objectType) then
if (mainRedirect) then
addRedirectTemplate(frame:expandTemplate{title = 'R with possibilities'})
end
if (printworthy) then
addRedirectTemplate(frame:expandTemplate{title = 'R printworthy'})
else
addRedirectTemplate(frame:expandTemplate{title = 'R unprintworthy'})
end
else
addRedirectTemplate(frame:expandTemplate{title = 'R from incorrect disambiguation'})
addRedirectTemplate(frame:expandTemplate{title = 'R unprintworthy'})
end
end
return frame:expandTemplate{title = 'Redirect category shell', args = {redirectTemplates}}
end
--[[
Public function from other modules.
Function handles the unique character redirect code.
--]]
function p._character(frame, args)
addToRFromFictionalObject("character", frame, args)
if (args.alt_name) then
addRedirectTemplate(frame:expandTemplate{title = 'R comics from alternative name'})
mainRedirect = false
end
if (args.nickname) then
addRedirectTemplate(frame:expandTemplate{title = 'R from alternative name'})
mainRedirect = false
end
if (args.short_name) then
addRedirectTemplate(frame:expandTemplate{title = 'R from short name'})
mainRedirect = false
end
if (args.long_name) then
addRedirectTemplate(frame:expandTemplate{title = 'R from long name'})
mainRedirect = false
end
if (args.title_name) then
addRedirectTemplate(frame:expandTemplate{title = 'R from name with title'})
printworthy = false
mainRedirect = false
end
return sharedRedirects("character", frame, args)
end
--[[
Public function from other modules.
Function handles the unique element redirect code.
Do not merge with other sections to allow for future changes.
--]]
function p._element(frame, args)
addToRFromFictionalObject("element", frame, args)
return sharedRedirects("element", frame, args)
end
--[[
Public function from other modules.
Function handles the unique location redirect code.
Do not merge with other sections to allow for future changes.
--]]
function p._location(frame, args)
addToRFromFictionalObject("location", frame, args)
return sharedRedirects("location", frame, args)
end
--[[
Public function which is used to create a Redirect category shell
with relevant redirects for fictional character redirects.
Parameters:
-- |series= — required; The name of the series article, including disambiguation. Will set the value entered as series which this object belongs to.
-- |multi_series= — optional; Multiple series article names, including disambiguation. Will set the values entered as series which this object belongs to.
This parameter can only be used from other modules as it requires the parameters to be passed as an args table.
-- |alt_name= — optional; Only valid for characters; Any value will tag the redirect with: "R comics from alternative name".
-- |nickname= — optional; Only valid for characters; Any value will tag the redirect with: "R from alternative name".
-- |short_name= — optional; Only valid for characters; Any value will tag the redirect with: "R from short name".
-- |long_name= — optional; Only valid for characters; Any value will tag the redirect with: "R from long name".
-- |title_name= — optional; Only valid for characters; Any value will tag the redirect with: "R from name with title".
-- |alt_spelling= — optional; Will tag the redirect with: "R from alternative spelling" and set the value entered as the correct spelling to use.
-- |anchor= — optional; Any value will tag the redirect with: "R to anchor".
-- |list= — optional; Any value will tag the redirect with: "R to list entry".
-- |primary= — optional; Will tag the redirect with: "R avoided double redirect" and set the value entered as the primary redirect.
-- |incorrect_name= — optional; Will tag the redirect with: "R from incorrect name" and set the value entered as the correct name to use.
-- |unneeded_dab= — optional; Any value will tag the redirect with: "R from unnecessary disambiguation".
-- |dab_exception= — optional; Any value will tag the redirect with: "R with possibilities" and "R printworthy", regardless of other issues the redirect might have.
Using this parameter will ignore notes C, D and F below.
-- |not_list= — optional; Only valid for characters; Any value will disable the normal "R from fictional character" tagging
and place the redirect directly in a general "(series) character redirects" category.
-- |correct_disambiguation= — optional; Value will be used for disambiguation validation.
Should be used if the disambiguation is different than the series name, such as when using a franchise name.
Notes:
-- A: The redirect will automatically be tagged with "R from fictional character", "R from fictional element" or "R from fictional location",
depending on the function used.
-- B: Using the series parameter will place the redirect in a series-specific category: "(series) (object) redirects to lists".
-- C: If one of the following parameters is used — |alt_name=, |short_name=, |long_name=, |alt_spelling=, |primary= or |incorrect_name= —
the redirect will not be tagged with "R with possibilities".
-- D: If one of the following parameters is used — |alt_spelling= or |incorrect_name= —
the redirect will be tagged with "R unprintworthy", else it will be tagged with "R printworthy".
-- E: If the |anchor= or |list= parameters are not used, the redirect will be tagged with "R to section".
--]]
function p.character(frame)
local args = getArgs(frame)
return p._character(frame, args)
end
--[[
Public function which is used to create a Redirect category shell
with relevant redirects for fictional element redirects.
Parameters: See character() for documentation.
--]]
function p.element(frame)
local args = getArgs(frame)
return p._element(frame, args)
end
--[[
Public function which is used to create a Redirect category shell
with relevant redirects for fictional location redirects.
Parameters: See character() for documentation.
--]]
function p.location(frame)
local args = getArgs(frame)
return p._location(frame, args)
end
return p