Anonimo

Modulo:FunzioniGeneriche: differenze tra le versioni

Da Wikitrek.
m
nessun oggetto della modifica
Nessun oggetto della modifica
mNessun oggetto della modifica
 
(69 versioni intermedie di uno stesso utente non sono mostrate)
Riga 79: Riga 79:
Cell:node(List)
Cell:node(List)
else
else
Cell
if type(Field[1]) == "table" then
:wikitext(Field[1])
Cell
:wikitext(Field[1][1])
else
Cell
:wikitext(Field[1])
end
end
end
end
end
Riga 219: Riga 224:
return Match .. " - " .. string.upper(string.sub(Match, 1, 1))
return Match .. " - " .. string.upper(string.sub(Match, 1, 1))
end
end
--- Extarct the name of a ship from full designation
--- Extract the name of a ship from its full designation
--
--
-- @param frame The interface to the parameters passed to {{#invoke:}}
-- @param frame The interface to the parameters passed to {{#invoke:}}
-- @return Bare name
-- @return Bare name of the ship
function p.ShipName(frame)
function p.ShipName(frame)
local FullName = frame.args[1]
local FullName = frame.args[1]
local Prefixes = {"USS ", "IKS ", "ECS "}
return p.ShipNameCore(FullName)
end
--- Extract the name of a ship from its full designation
--
-- @param designation The full designation to process
-- @return Bare name of the ship
function p.ShipNameCore(designation)
local FullName = designation
local Prefixes = {"USS ", "IKS ", "ECS ", "''", "<i>", "</i>", " %(reboot%)", " %(Kelvin Timeline%)"}
-- Removes prefix
for _, Prefix in ipairs(Prefixes) do
for _, Prefix in ipairs(Prefixes) do
FullName = FullName:gsub((Prefix), "")
FullName = FullName:gsub((Prefix), "")
end
end
FullName = FullName:gsub("[^%s]+$", "A")
--Removes suffix year or number specification
FullName = FullName:gsub("%s%(%d+%)", "")
--Removes suffix registry number
FullName = FullName:gsub("%s[^%s]+$", "")
return FullName
return FullName
Riga 259: Riga 277:
local PropName
local PropName
local PropValue
local PropValue
local LIPattern
if frame.args[1] == nil then
if frame.args[1] == nil then
Riga 268: Riga 287:
         else
         else
         ParaString = frame.args[2]
         ParaString = frame.args[2]
         if string.find(ParaString, "<li>") ~= nil then
         if string.find(ParaString, "<li>") == nil then
         --Process UL or OL
         -- Add dummy tags to use a single process afterwards
         for Item in string.gmatch(ParaString, "<li>(.-)</li>") do
         ParaString = "<li>" .. ParaString .. "</li>"
        table.insert(FinalArray, Item)
        end
         end
       
         PropValue = table.concat(FinalArray, Separator) .. SepDeclaration
        if string.find(ParaString, "%[%[") == nil then
         -- There is no wikilink, plain text
         LIPattern = "<li>(.-)</li>"
         else
         else
         --No process, assign original value
         -- A wikilink is present, discard surrounding text
         PropValue = ParaString
         LIPattern = "<li>.-%[%[(.-)%]%].-</li>"
         end
         end
   
    -- Determine if property is Assignment, so process a string like:
    -- [[Timeline 2267|2267]] <i>[[USS Enterprise NCC-1701|USS Enterprise]]</i>
    if PropName == "Assegnazione" then
    -- then remove italic
    ParaString = string.gsub(ParaString, "<i>", "")
    ParaString = string.gsub(ParaString, "</i>", "")
    -- then remove Timeline
    ParaString = string.gsub(ParaString, "(%[%[Timeline.-%]%])", "")
    end
    --Process UL or OL
    for Item in string.gmatch(ParaString, LIPattern) do
    Item = string.gsub(Item, "(|.*)", "")
    table.insert(FinalArray, Item)
    end
    PropValue = table.concat(FinalArray, Separator) .. SepDeclaration
         end
         end
     end
     end
mw.smw.set(PropName .. " = " .. PropValue)
mw.smw.set(PropName .. " = " .. PropValue)
end
--- OLD simpler original version
-- Process the value assigned to "EpisodioPersonaggi" of the "old-style"
-- template (pre-DataTrek) to sanitize it and pass it as clean value to
-- SMW property using the #set function
--
-- @param frame The interface to the parameters passed to {{#invoke:}}
-- No return @return Sanitized string representing one or more property values
function p.PerformersToSemanticOriginal(frame)
local InputString
local Character
local Performer
local Pattern = "%*.-%[%[(.-)%]%].-:%s?%[%[(.-)%]%]"
--InputString = "* [[Vina]]: [[Melissa George]]* [[Spock]]: [[Ethan Peck]]* [[Leland]]: [[Alan van Sprang]]* [[Nhan]]: [[Rachael Ancheril]]* Un [[Talosiani|Talosiano]]: [[Dee Pelletier]]* Il ''Keeper'' [[Talosiani|Talosiano]]: [[Rob Brownstein]]* Lt. Cmdr. [[Airiam]]: [[Hannah Cheesman]]* Lt. [[Keyla Detmer]]: [[Emily Coutts]]* [[Talosiani|Talosiano]] n.3: [[Nicole Dickinson]]"
InputString = frame.args[1]
--_, _, Character, Performer = string.find(InputString, Pattern)
for Character, Performer in string.gmatch(InputString, Pattern) do 
Character = string.gsub(Character, "|.*","")
--print("Character: " .. Character, "Performer: " .. Performer)
mw.smw.set("Personaggio=" .. Character)
mw.smw.set("Interprete=" .. Performer)
mw.smw.set(Performer .. " = " .. Character)
end
end
--- NEW improved version
-- Process the values assigned to "EpisodioPersonaggi" parameter of the
-- "old-style" template (pre-DataTrek) to sanitize it and pass it
-- as clean value to SMW property using the #set function
--
-- @param frame The interface to the parameters passed to {{#invoke:}}
-- No return @return Sanitized string representing one or more property values
function p.PerformersToSemantic(frame)
local InputString
local Pattern
InputString = frame.args[1] .. "\n"
for FullRow in string.gmatch(InputString, "%*.-\n") do
local Character
local Performer
--Remove italic
FullRow = string.gsub(FullRow, "<i>", "")
    FullRow = string.gsub(FullRow, "</i>", "")
--print (FullRow)
local CountLiks = select(2, string.gsub(FullRow, "%[%[", ""))
--print (CountLiks)
if string.find(FullRow, ":") == nil then
--Character only, unknown performer
Pattern = "%*.-%[%[(.-)%]%].-"
_, _, Character = string.find(FullRow, Pattern)
Performer = "Interprete non accreditato"
else
if CountLiks == 2 then
--Two links in the string, process both
--print("Two links")
Pattern = "%*.-%[%[(.-)%]%].-:%s?%[%[(.-)%]%]"     
elseif CountLiks == 1 then
--Character is not a linked entity
--print("One link")
Pattern = "%*%s?(.-)%s?:%s?%[%[(.-)%]%]"
else
--error no links on either side
    Pattern = "%*%s?(.-)%s?:%s?(.-)%s?\n"
end
_, _, Character, Performer = string.find(FullRow, Pattern)
end
Character = string.gsub(Character, "|.*","")
--print("          Character: " .. Character, "Performer: " .. Performer)
--print(string.rep("-",100))
mw.smw.set("Personaggio=" .. Character)
mw.smw.set("Interprete=" .. Performer)
mw.smw.set(Performer .. " = " .. Character)
end
end
end
function p.ParameterToSemanticTest(frame)
function p.ParameterToSemanticTest(frame)
Riga 292: Riga 407:
end
end
return mw.text.nowiki(table.concat(FinalArray, Separator) .. SepDeclaration)
return mw.text.nowiki(table.concat(FinalArray, Separator) .. SepDeclaration)
end
--- Check if a file is SVG and validate it
--
-- @param frame The interface to the parameters passed to {{#invoke:}}
-- @return Processed string
function p.SVGValidate(frame)
local ValidateURI = "http://validator.w3.org/check?uri="
local FileTitle
local MediaURI
FileTitle =  mw.title.getCurrentTitle()
if string.lower(string.sub(FileTitle.fullText, -4)) == ".svg" then
--file is Scalable Vector Graphics
MediaURI = frame:callParserFunction('filepath:' .. string.sub(FileTitle.fullText, 6))
--return FileTitle.fullText .. "<br />" .. FileTitle:fullUrl() .. "<br />" .. FileTitle:localUrl() .. "<br />" .. FileTitle:canonicalUrl() .. "<br />" .. MediaURI
return "\n== Validazione ==\n" .. "[[File:Valid SVG 1.1.svg|88px|link=" ..  ValidateURI .. mw.uri.encode(MediaURI, "PATH") .. "]]"
else
return nil
end
end
end
return p
return p