Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Gonnym/sometest3/1
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
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
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Gonnym/sometest3/1/doc
(
edit
)