Module:Cite source

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

function p.getinfo( frame ) local testText = "" local queryResult = mw.smw.ask( [=[ The Daleks (TV story) || Regeneration (TV story) || The Holy Terror (audio story) || Rosa (TV story) || The Eight Doctors (novel) || Mr Saldaamir (short story) || Skywatch-7 (comic story) || The Klepton Parasites (comic story) || The Lonely Assassins (video game) || Doctor Who in an Exciting Adventure with the Daleks (novelisation) || The Dreadful Flap (short story) || Rise and Fall (audio story) || Martha Jones' MySpace blog (short story)	if queryResult == nil then       return "No data."    end    if type( queryResult ) == "table" then    	for queryResultsCounter = 1, #queryResult do    		local current = queryResult[queryResultsCounter]    		local outputText = ""	    	local data = {["Anthology"] = "", ["Writer"] = "", ["Publisher"] = "", ["Novelisation of"] = "", ["Adapted from"] = "", ["Issues"] = ""} for key, val in pairs(data) do	   		if type( current[key] ) == "string" then data[key] = current[key] elseif type( current[key] ) == "table" then data[key] = "" for i = 1, #current[key] do data[key] = data[key] .. 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 --making series text if current["Citation series"] then data["Series"] = current["Citation series"] elseif current["Range"] then data["Series"] = "\'\'" .. 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"] .. " " .. current["Season"] end end if data["Series"] then outputText = data["Series"] else outputText = "" end local name = current[1] local varBin = util_vars.setVar("sc-" .. name, outputText) testText = testText .. current[1] .. ": " .. outputText .. "\n\n" end end testText = testText .. " " .. dump(queryResult) .. " " .. util_vars.getVar("sc-Regeneration (TV story)") return testText end
 * ?Pagename
 * ?Anthology
 * ?Issues
 * ?Season
 * ?Range
 * ?Audio series
 * ?Writer
 * ?Publisher
 * ?Release date
 * ?Series
 * ?Novelisation of
 * ?Adapted from
 * ?Citation series ]=] )

--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