Module:Cite source

local util_vars = require('Module:VarsUtil') local util_link = require('Module:LinkUtil') local concat local dump local print local p = {} --p stands for package

function p.getInfo( frame ) local queryResult = mw.smw.ask( frame.args.stories .. [=[	if queryResult == nil then       return "No data: " .. frame["args"]["stories"]    end    if type( queryResult ) == "table" then    	for queryResultsCounter = 1, #queryResult do    		local current = queryResult[queryResultsCounter]    		local outputText = ""	    	local data = {["Anthology"] = "", ["Writer"] = "", ["Publisher"] = "", ["Adapted from"] = ""}	    	for key, val in pairs(data) do	    		if type( current[key] ) == "string" then	    			data[key] = "" .. util_link.stripSMW(util_link.stripDab(current[key])) .. ""	    		elseif type( current[key] ) == "table" then					data[key] = ""					for i = 1, #current[key] do						data[key] = data[key] .. "" .. util_link.stripSMW(util_link.stripDab(current[key][i])) ..""		    			if i == #current[key]-1 then data[key] = data[key] .. " and " elseif i == #current[key] then data[key] = data[key] else data[key] = data[key] .. ", "		   			end end end end if current["Issues"] then data["Issues"] = current["Issues"] else data["Issues"] = "" end -- making series text if current["Citation series"] then data["Series"] = current["Citation series"] elseif current["Range"] then data["Series"] = "\'\'" .. util_link.stripSMW(util_link.stripDab(current["Range"])) .. "\'\'" elseif current["Series"] then if current["Series"] == "Doctor Who television stories" then data["Series"] = "\'\'Doctor Who\'\'" else data["Series"] = current["Series"] end if current["Season"] then data["Series"] = data["Series"] .. " " .. "" .. util_link.stripSMW(util_link.stripDab(current["Season"])) .. "" end else data["Series"] = "" end -- making release year text if current["Release date"] then local releaseYear = (current["Release date"]):sub(1,4) local releaseEndYear = (current["Release end date"]):sub(1,4) if releaseEndYear ~= releaseYear then if (tonumber(releaseEndYear) - tonumber(releaseYear)) == 1 then data["Release year"] = "in" else data["Release year"] = "between" end data["Release year"] = data["Release year"] .. " the years " .. releaseYear .." and " .. releaseEndYear .. "" else data["Release year"] = "in the year " .. releaseYear .."" end else data["Release year"] = "" end -- making outputText local outputText = " " if data["Adapted from"] ~= "" then outputText = outputText .. "Adapted from ''" .. data["Adapted from"] .. "''"	   		if data["Writer"] ~= "" then outputText = outputText .. ", written by " .. data["Writer"] if data["Publisher"] ~= "" then outputText = outputText .. " and released by " .. data["Publisher"] end elseif data["Publisher"] ~= "" then outputText = outputText .. " and released by " .. data["Publisher"] end elseif data["Writer"] ~= "" then outputText = outputText .. "Written by " .. data["Writer"] if data["Publisher"] ~= "" then outputText = outputText .. " and released by " .. data["Publisher"] end elseif data["Publisher"] ~= "" then outputText = outputText .. " Released by " .. data["Publisher"] else outputText = outputText .. "Released " end if data["Anthology"] ~= "" then outputText = outputText .. " as part of ''" .. data["Anthology"] .. "''"	   			if data["Series"] ~= "" then if current["Season"] then outputText = outputText .. " from " .. data["Series"] else outputText = outputText .. " from the series " .. data["Series"] end end elseif data["Series"] ~= "" then if current["Season"] then outputText = outputText .. " as part of " .. data["Series"] else outputText = outputText .. " as part of the series " .. data["Series"] end end if data["Release year"] ~= "" then if (data["Publisher"] ~= "") or (data["Writer"] == "") then outputText = outputText .. " " .. data["Release year"] else outputText = outputText .. " and released " .. data["Release year"] end end if data["Issues"] ~= "" then outputText = outputText .. " throught " .. data["Issues"] end if outputText == "" then outputText = "No data." else outputText = outputText .. "."			end outputText = "+ " .. outputText .. ""   		local name = current["Pagename"] local varBin = util_vars.setVar("sc-" .. name, outputText) end end end
 * ?Pagename
 * ?Anthology
 * ?Issues
 * ?Season
 * ?Range
 * ?Audio series
 * ?Writer
 * ?Publisher
 * ?Release date
 * ?Release end date
 * ?Series
 * ?Adapted from
 * ?Citation series ]=] )

function p.displayInfo( frame ) story = frame:getParent.args[1] if (util_vars.getVar("SC-stories") == "") or (util_vars.getVar("SC-stories") == nil) then util_vars.setVar("SC-stories", "" .. story .. "") else util_vars.setVar("SC-stories", util_vars.getVar("SC-stories") .. " || " .. story .. "") end return util_vars.getVar("sc-" .. story) end

--from https://sandbox.semantic-mediawiki.org/wiki/Module:Sm --- Concatenates a variable number of strings and numbers to one single string -- ignores tables, bools, functions, and such and replaces them with the empty string -- -- What is the benefit of using variable.concat instead of the .. operator? -- Answer: .. throws an error, when trying to concat bools, tables, functions, etc. -- This here handels them by converting them to an empty string -- -- @param ... varaibles to concatenate -- -- @return string concat = function(...) local args = {...} if #args == 0 then error('you must supply at least one argument to \'concat\' (got none)') end local firstArg = table.remove(args, 1) if type(firstArg) == 'string' or type(firstArg) == 'number' then firstArg = print(firstArg) else firstArg = '' end if #args == 0 then return firstArg else return firstArg .. concat(unpack(args)) end end

--- This dumps the variable (converts it into a string representation of itself) -- -- @param entity mixed, value to dump -- @param indent string, can bu used to set an indentation -- @param omitType bool, set to true to omit the () in front of the value -- -- @return string dump = function(entity, indent, omitType) local entity = entity local indent = indent and indent or '' local omitType = omitType if type( entity ) == 'table' then local subtable if not omitType then subtable = '(table)[' .. #entity .. ']:'       end indent = indent .. '\t' for k, v in pairs( entity ) do           subtable = concat(subtable, '\n', indent, k, ': ', dump(v, indent, omitType)) end return subtable elseif type( entity ) == 'nil' or type( entity ) == 'function' or type( entity ) == 'boolean' then return ( not omitType and '(' .. type(entity) .. ') ' or '' ) .. print(entity) elseif type( entity ) == 'string' then entity = mw.ustring.gsub(mw.ustring.gsub(entity, "\\'", "'"), "'", "\\'") return concat(omitType or '(string) ', '\, entity, '\) else -- number value expected return concat(omitType or '(' .. type( entity ) .. ') ', entity) end end

--- This function prints a variable depending on its type: -- * tables get concatenated by a comma -- * bools get printed as true or false -- * strings and numbers get simple returned as string -- * functions and nils return as emtpy string -- @return string print = function(v) if type( v ) == 'table' then return table.concat(v, ',') elseif type( v ) == 'boolean' then return ( v and 'true' or 'false' ) elseif type(v) == 'string' or type(v) == 'number' then return tostring(v) else return '' end end

return p