Module:Exclusive

-- l10n text, needs to be translated. local l10n = mw.loadData('Module:Exclusive/l10n')

-- exclusive info database, please read the documentation of Module:Exclusive/data local exclusive_info = mw.loadData( 'Module:Exclusive/data' )

--- The following is not related to l10n. -- local trim = mw.text.trim

local args_table -- cache -- helper function local getArg = function(key) local value = trim(args_table[key] or '') return (value ~= '') and value or nil end

local function parameter(parameter, base) if parameter then if parameter == '1' or parameter == 'y' or parameter == 'yes' then return 'y'		end if parameter == '0' or parameter == 'n' or parameter == 'no' then return nil end end return base end

local standAndExtr = function(page) -- standardize pagename (remove section parts ('x#section' -> 'x') and replace underscores with spaces) page = mw.getContentLanguage:ucfirst(string.gsub(string.gsub(page or , '#.*', ), '_', ' ')) -- extract info local raw, ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, cached = exclusive_info[page] if raw then ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, cached = raw:find('d'), raw:find('c'), raw:find('o'), raw:find('m'), raw:find('3'), raw:find('j'), 'y'	end return ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, cached end

local getInfo = function(page, invert, pagenot) local ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, cached = standAndExtr(page)

-- invert? if invert then ex_d = not ex_d ex_c = not ex_c ex_o = not ex_o ex_m = not ex_m ex_3 = not ex_3 ex_j = false end -- exclude some versions, depending on pagenot if pagenot then local exnot_d, exnot_c, exnot_o, exnot_m, exnot_3, exnot_j = standAndExtr(pagenot) ex_d = ex_d and not exnot_d -- ex_d is true only when ex_d is set and exnot_d is not set. ex_c = ex_c and not exnot_c ex_o = ex_o and not exnot_o ex_m = ex_m and not exnot_m ex_3 = ex_3 and not exnot_3 end

return ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, cached end

local eicons = function(ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, _small, _link, lang) local link = '' local space = false local size local result = '' local l10n = l10n[lang] or l10n['en']

-- compact mode only if nolink. if link == '' then if ex_d and ex_c and ex_o and ex_m and not ex_3 and not ex_j then result = ''			return mw.text.tag('span',{class='eico'}, result) end if ex_d and ex_c and not ex_o and ex_m and not ex_3 and not ex_j then result = ''			return mw.text.tag('span',{class='eico'}, result) end end

if ex_d then result = ''		space = true end if ex_c then result = result .. (space and '&thinsp;' or '') .. ''		space = true end if ex_o then result = result .. (space and '&thinsp;' or '') .. ''		space = true end if ex_m then result = result .. (space and '&thinsp;' or '') .. ''		space = true end if ex_3 then result = result .. (space and '&thinsp;' or '') .. ''		space = true end if ex_j then result = result .. (space and '&thinsp;' or '') .. ''	end return mw.text.tag('span',{class='eico'}, result) end

local getExclusiveInfo = function(page, invert, pagenot) local ex_d, ex_c, ex_o, ex_m, ex_3, ex_j if page then ex_d, ex_c, ex_o, ex_m, ex_3, ex_j = getInfo(page, invert, pagenot) end -- override ex_d = parameter(getArg('dsk'), ex_d) ex_c = parameter(getArg('cns'), ex_c) ex_o = parameter(getArg('old'), ex_o) ex_m = parameter(getArg('mbl'), ex_m) ex_3 = parameter(getArg('3ds'), ex_3) ex_j = parameter(getArg('jas'), ex_j)

return ex_d, ex_c, ex_o, ex_m, ex_3, ex_j end

-

return { -- for template; get all exclusive info, set it in dplvars. -- parameters: $1 = pagename getInfo = function(frame) args_table = frame.args -- cache local page = getArg(1) if not page then frame:callParserFunction{ name = '#dplvar:set', args = { 'ex_d', , 'ex_c', , 'ex_o', , 'ex_m', , 'ex_3', , 'ex_j', , 'ex_cached', 'y'			} } return end local ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, cached = getInfo(page, getArg('invert'), getArg('pagenot')) frame:callParserFunction{ name = '#dplvar:set', args = { 'ex_d', ex_d and 'y' or '', 'ex_c', ex_c and 'y' or '', 'ex_o', ex_o and 'y' or '', 'ex_m', ex_m and 'y' or '', 'ex_3', ex_3 and 'y' or '', 'ex_j', ex_j and 'y' or '', 'ex_cached', cached and 'y' or '' } }	end,

-- for eicons = function(frame) args_table = frame.args -- cache local ex_d, ex_c, ex_o, ex_m, ex_3, ex_j = getExclusiveInfo(getArg(1), getArg('invert'), getArg('pagenot')) if not(ex_d or ex_c or ex_o or ex_m or ex_3 or ex_j) then return '' end local small = getArg('small') if small == 'n' or small == '0' or small == 'no' then small = false end return eicons(			ex_d, ex_c, ex_o, ex_m, ex_3, ex_j,			small, getArg('link'), getArg('lang')		) end,

-- for other modules such as Module:item; simple eicons: simpleEicons = function(page, lang, small, link) local ex_d, ex_c, ex_o, ex_m, ex_3, ex_j = getInfo(page) if not(ex_d or ex_c or ex_o or ex_m or ex_3 or ex_j) then return '' end return eicons(			ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, 			small, link, lang		) end, --purge luacached cache data. purge = function(frame) local cache = require 'mw.ext.LuaCache' cache.delete('exclusive-database') end, }