No edit summary |
m (Undo revision 25641 by Tobi 406 (talk): Accidently saved) Tag: Undo |
||
Line 2: | Line 2: | ||
local i18n = { |
local i18n = { |
||
− | user_rights = ' |
+ | user_rights = 'User rights', |
− | extension_ns = ' |
+ | extension_ns = 'Extension', |
− | non_default_ext = ' |
+ | non_default_ext = 'From non-default extensions' |
− | groups = 'Gruppen', |
||
− | addgroups = 'Kann hinzufügen: ', |
||
− | rmvgroups = 'Kann entfernen: ', |
||
− | middlesep = ', ', |
||
− | lastsep= ' und ' |
||
} |
} |
||
Line 37: | Line 32: | ||
function p.extensionSort(t1,t2) |
function p.extensionSort(t1,t2) |
||
if t1['extName'] < t2['extName'] then |
if t1['extName'] < t2['extName'] then |
||
− | return true |
||
− | end |
||
− | return false |
||
− | end |
||
− | |||
− | function p.groupSort(t1,t2) |
||
− | if t1 < t2 then |
||
return true |
return true |
||
end |
end |
||
Line 50: | Line 38: | ||
function p.main(frame) |
function p.main(frame) |
||
− | local rights = mw.loadData('Module: |
+ | local rights = mw.loadData('Module:User_group_rights/data') |
local group = frame:getParent().args[1] |
local group = frame:getParent().args[1] |
||
local grouprights = {} |
local grouprights = {} |
||
Line 96: | Line 84: | ||
text = text .. '<h3>' .. i18n['non_default_ext'] .. '</h3>\n' .. exttext |
text = text .. '<h3>' .. i18n['non_default_ext'] .. '</h3>\n' .. exttext |
||
end |
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 |
||
− | |||
− | table.sort(addgroups, p.extensionSort) |
||
− | table.sort(removegroups, p.extensionSort) |
||
− | |||
− | |||
− | -- make text |
||
− | local addgroupstext = '' |
||
− | for i, g in ipairs(addgroups) do |
||
− | g = '[[' .. frame:preprocess(mw.message.new('grouppage-' .. g):inLanguage(mw.getContentLanguage()):plain()) .. '|' .. 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('grouppage-' .. g):inLanguage(mw.getContentLanguage()):plain()) .. '|' .. 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<h3>' .. i18n['groups'] .. '</h3>' |
||
− | if addgroupstext > '' then |
||
− | text = text .. '\n' .. i18n['addgroups'] .. addgroupstext |
||
− | end |
||
− | if removegroupstext > '' then |
||
− | text = text .. '\n\n' .. i18n['rmvgroups'] .. removegroupstext |
||
− | end |
||
− | end |
||
− | |||
return text |
return text |
||
end |
end |
Revision as of 15:28, 20 August 2019
This module has three configurable variables:
user_rights = 'User rights',
extension_ns = 'Extension',
non_default_ext = 'From non-default extensions'
These should be updated to reflect the language-specific text.
Subpages
The above documentation is transcluded from Module:User group rights/doc.[edit | history | purge]
local p = {}
local i18n = {
user_rights = 'User rights',
extension_ns = 'Extension',
non_default_ext = 'From non-default extensions'
}
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:User_group_rights/data')
local group = frame:getParent().args[1]
local grouprights = {}
local text = '<h2>' .. i18n['user_rights'] .. '</h2>\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()) .. ' <code>(' .. right['right'] .. ')</code>\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<h4>[[' .. i18n['extension_ns'] .. ':'..extension..'|'..extension..']]</h4>\n'
for i, right in ipairs(rights) do
exttext = exttext .. '\n* ' .. frame:preprocess(mw.message.new('right-' .. right['right']):inLanguage(mw.getContentLanguage()):plain()) .. ' <code>(' .. right['right'] .. ')</code>'
end
end
if exttext > '' then
text = text .. '<h3>' .. i18n['non_default_ext'] .. '</h3>\n' .. exttext
end
return text
end
return p