Module:Benutzergruppenrechte

local p = {}

local i18n = { user_rights = 'Rechte', extension_ns = 'Erweiterung', non_default_ext = 'Von nicht standardmäßigen Erweiterungen', groups = 'Gruppen', addgroups = 'Kann hinzufügen: ', rmvgroups = 'Kann entfernen: ', middlesep = ', ', lastsep= ' und ' }

function p.removeLinks(message) local cleanmsg = mw.text.trim(string.gsub(message,'%[%%-%|([^%|%]]-)%]%]','%1'),'%p') return cleanmsg end

function p.rightsSort(t1, t2) local l1 = p.removeLinks(mw.message.new('right-' .. t1['right']):inLanguage(mw.getContentLanguage):plain) local l2 = p.removeLinks(mw.message.new('right-' .. t2['right']):inLanguage(mw.getContentLanguage):plain) if l1 < l2 then return true end return false end

function p.findIndex(et,ext) for i,v in ipairs(et) do		if v.extName == ext then return i		end end return -1 end

function p.extensionSort(t1,t2) if t1['extName'] < t2['extName'] then return true end return false end

function p.main(frame) local rights = mw.loadData('Module:Benutzergruppenrechte/data') local group = frame:getParent.args[1] local grouprights = {} local text = ' ' .. i18n['user_rights'] .. ' \n' --get the rights in the selected group for i, right in ipairs(rights) do		for i2, g in ipairs(right['groups']) do			if g == group then table.insert(grouprights, right) end end end --now we sort the rights by the localized right description table.sort(grouprights,p.rightsSort) local extensionrights = {} --and now process default rights for i, right in ipairs(grouprights) do		if right['extension'] == nil then text = text .. '* ' .. frame:preprocess(mw.message.new('right-' .. right['right']):inLanguage(mw.getContentLanguage):plain) .. ' \n' else local idx = p.findIndex(extensionrights, right['extension']) if idx == -1 then table.insert(extensionrights,{ extName = right['extension'], rights = {right} }) else table.insert(extensionrights[idx]['rights'], right) end end end table.sort(extensionrights,p.extensionSort) local exttext = '' --and extension rights for i, extrights in ipairs(extensionrights) do		local extension = extrights['extName'] local rights = extrights['rights'] exttext = exttext .. '\n '..extension..' \n' for i, right in ipairs(rights) do exttext = exttext .. '\n* ' .. frame:preprocess(mw.message.new('right-' .. right['right']):inLanguage(mw.getContentLanguage):plain) .. ' '			end end if exttext > '' then text = text .. ' ' .. i18n['non_default_ext'] .. ' \n'	.. exttext end

-- prepare group tables local addgroups = {} local removegroups = {} local groupdata = mw.loadData('Module:Benutzergruppenrechte/groupdata') for i, tgroup in ipairs(groupdata) do		for i2, a in ipairs(tgroup['addedby']) do			if a == group then table.insert(addgroups, tgroup['group']) end end for i2, a in ipairs(tgroup['removedby']) do			if a == group then table.insert(removegroups, tgroup['group']) end end end -- sort tables table.sort(addgroups, function(a, b) return a:byte < b:byte end) table.sort(removegroups, function(a, b) return a:byte < b:byte end) -- make text local addgroupstext = '' for i, g in ipairs(addgroups) do               g =  .. frame:preprocess(mw.message.new('group-' .. g):inLanguage(mw.getContentLanguage):plain) ..  if i == 1 then addgroupstext = g               else if i == table.getn(addgroups) then addgroupstext = addgroupstext .. i18n['lastsep'] .. g                       else addgroupstext = addgroupstext .. i18n['middlesep'] .. g                       end end end

local removegroupstext = '' for i, g in ipairs(removegroups) do               g =  .. frame:preprocess(mw.message.new('group-' .. g):inLanguage(mw.getContentLanguage):plain) ..  if i == 1 then removegroupstext = g               else if i == table.getn(removegroups) then removegroupstext = removegroupstext .. i18n['lastsep'] .. g                       else removegroupstext = removegroupstext .. i18n['middlesep'] .. g                       end end end

-- add text if addgroupstext >  or removegroupstext >  then text = text .. '\n ' .. i18n['groups'] .. ' '               if addgroupstext > '' then text = text .. '\n' .. i18n['addgroups'] .. addgroupstext end if removegroupstext > '' then text = text .. '\n\n' .. i18n['rmvgroups'] .. removegroupstext end end

return text end

return p