Module:Exclusive

-- l10n text, needs to be translated. local l10n_data = 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 bit32 = require( 'bit32' ) local trim = mw.text.trim

-- this is much much faster then mw.text.split local explode = function(div,str) if (div=='') then return false end local pos,arr = 0,{} -- for each divider found for st,sp in function return string.find(str,div,pos,true) end do		arr[#arr + 1] = string.sub(str,pos,st-1) -- Attach chars left of current divider pos = sp + 1 -- Jump past current divider end arr[#arr + 1] = string.sub(str,pos) -- Attach chars right of last divider return arr end

local contentLanguage = mw.getContentLanguage

local lang local l10n = function(key) if l10n_data[lang] then return l10n_data[lang][key] or l10n_data['en'][key] else return l10n_data['en'][key] end end

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 standAndExtr = function(page) -- standardize pagename (remove section parts ('x#section' -> 'x') and replace underscores with spaces) page = contentLanguage:ucfirst(string.gsub(string.gsub(page or , '#.*', ), '_', ' ')) return exclusive_info[page] or 0 end

local override = function(info, dcom3j) for k,v in pairs(explode(':',dcom3j)) do		if v ~= '' then if v == '1' or v == 'y' or v == 'yes' then info = bit32.replace(info, 1, k-1) elseif v == '0' or v == 'n' or v == 'no' then info = bit32.replace(info, 0, k-1) end end end return info end

local getInfo = function(page, invert, pagenot, dcom3j) local info = 0 if page then info = standAndExtr(page) if invert then info = bit32.band(bit32.bnot(info), 31) -- invert dcom3, and set j = 0 end -- exclude some versions, depending on pagenot if pagenot then local info_not = standAndExtr(pagenot) info = bit32.band(info, bit32.bnot(info_not)) -- ex_d is true only when ex_d is set and exnot_d is not set. end end -- override if needed: if dcom3j == nil or dcom3j == ':::::' then return info else return override(info, dcom3j) end end

local eicons = function(info, _small) if bit32.btest(info, 32) then return mw.text.tag('span', {class='eicon j'..(_small and ' s' or '')}, mw.text.tag('span', {title=l10n('text_j')}, l10n('text_j'))) end

local class = 'eicon' local v = {} for i = 0, 4 do		if bit32.btest(info, 2^i) then class = class .. ' i'..i			v[#v+1] = l10n('text_'..i)		end end local v = mw.text.listToText(v, l10n('list_separator'), l10n('list_conjunction'))..contentLanguage:convertPlural(#v, l10n('version_plural_forms')) return mw.text.tag('span', {class=class..(_small and ' s' or '')}, mw.text.tag('span', {title=v}, v)) end

-

return { -- for template; get all exclusive info, set it in dplvars. -- parameters: $1 = pagename getInfo = function(frame) args_table = frame.args -- cache local info = getInfo(getArg(1), getArg('invert'), getArg('pagenot')) if info == 0 or info == 31 or info == 63 then -- dcom3 or dcom3j are also invalid. frame:callParserFunction{ name = '#dplvar:set', args = { 'ex_d', '', 'ex_c', '', 'ex_o', '', 'ex_m', '', 'ex_3', '', 'ex_j', '', 'ex_cached', 'y'			} } else frame:callParserFunction{ name = '#dplvar:set', args = { 'ex_d', bit32.btest(info, 2^0) and 'y' or '', 'ex_c', bit32.btest(info, 2^1) and 'y' or '', 'ex_o', bit32.btest(info, 2^2) and 'y' or '', 'ex_m', bit32.btest(info, 2^3) and 'y' or '', 'ex_3', bit32.btest(info, 2^4) and 'y' or '', 'ex_j', bit32.btest(info, 2^5) and 'y' or '', 'ex_cached', 'y'			} } end end,

-- for eicons = function(frame) args_table = frame.args -- cache local info = getInfo(getArg(1), getArg('invert'), getArg('pagenot'), getArg('dcom3j')) if info == 0 or info == 31 or info == 63 then -- dcom3 or dcom3j are also invalid. return frame:expandTemplate{ title='error', args={ l10n('eicons_error_text'), l10n('eicons_error_cate'), from = 'Eicons', inline = 'y'}} end lang = getArg('lang') -- set lang for l10n return eicons(info, getArg('small')) end,

-- for other modules such as Module:item; simple eicons: simpleEicons = function(page, language, small) local info = getInfo(page) if info == 0 or info == 31 or info == 63 then -- dcom3 or dcom3j are invalid. return '' end lang = language -- set lang for l10n return eicons(info, small) end,

}