Difference between revisions of "Module:Extension"

1,828 bytes added ,  18:42, 25 April 2020
Syncing from sandbox: get more data (incl. hooks) from extension.json if not specified in template
>Kghbln
(add AGPL-3.0-or-later)
>Pppery
(Syncing from sandbox: get more data (incl. hooks) from extension.json if not specified in template)
Line 1: Line 1:
local lang = mw.language.getContentLanguage()
local lang = mw.language.getContentLanguage()
--local translation = mw.getCurrentFrame():expandTemplate{ title = 'translation' }
local translation = mw.getCurrentFrame():callParserFunction{name='#translation', args="1"}
local translation = mw.getCurrentFrame():callParserFunction{name='#translation', args="1"}
local addr = {
local addr = {
Line 22: Line 21:
CC    = 'Creative Commons licensed extensions',
CC    = 'Creative Commons licensed extensions',
ECL    = 'Educational Community licensed extensions',
ECL    = 'Educational Community licensed extensions',
BLANK  = 'Extensions with no license specified'
}
}
local licenses = {
local licenses = {
Line 60: Line 60:
['ECL-2.0']      = { '', '[[wikipedia:Educational Community License|Educational Community License 2.0]]', 'ECL' },
['ECL-2.0']      = { '', '[[wikipedia:Educational Community License|Educational Community License 2.0]]', 'ECL' },
['PD']          = { '', '[[wikipedia:Public domain|Public domain]]', 'PD' },
['PD']          = { '', '[[wikipedia:Public domain|Public domain]]', 'PD' },
['unspecified']  = { '', 'No license specified', 'BLANK'}
}
}
local types = {
local types = {
Line 175: Line 176:
end
end


local function getExtData()
local pg = mw.title.getCurrentTitle().rootPageTitle:partialUrl() -- need to get rid of translation subpage.
return mw.loadData( 'Module:ExtensionJson' )[pg]
end
local function getLicenseString (str)
str = mw.text.trim(str)
if str == "" or str == nil then
local data = getExtData()
if data and data["license-name"] then
str = data["license-name"]
else
str = "unspecified"
end
end
return str
end
local function getLicenseCategory( str )
local function getLicenseCategory( str )
str = getLicenseString(str)
if mw.ustring.sub( str, -1 ) == '+' then
if mw.ustring.sub( str, -1 ) == '+' then
str = mw.ustring.sub( str, 1, -2 )
str = mw.ustring.sub( str, 1, -2 )
Line 191: Line 210:
local function getFormattedLicense( str, orlatertext )
local function getFormattedLicense( str, orlatertext )
local orlater = ''
local orlater = ''
local license = str
local license = getLicenseString(str)
if mw.ustring.sub( str, -1 ) == '+' then
if mw.ustring.sub( license, -1 ) == '+' then
license = mw.ustring.sub( str, 1, -2 )
license = mw.ustring.sub( license, 1, -2 )
orlater = orlatertext
orlater = orlatertext
end
end
Line 200: Line 219:
return (cnf[1] ~= '' and ('[' .. cnf[1] .. ' ' .. cnf[2] .. ']') or cnf[2]) .. orlater
return (cnf[1] ~= '' and ('[' .. cnf[1] .. ' ' .. cnf[2] .. ']') or cnf[2]) .. orlater
else
else
return str
return license
end
end
end
end
Line 243: Line 262:
function p.getFormattedLicense( frame )
function p.getFormattedLicense( frame )
setI18n( frame.args, licenses, 2 )
setI18n( frame.args, licenses, 2 )
return getFormattedLicense( frame.args[1] and mw.text.trim( frame.args[1] ) or nil, frame.args['+'] or ' or later' )
return getFormattedLicense( frame.args[1], frame.args['+'] or ' or later' )
end
end


function getExtData()
local pg = mw.title.getCurrentTitle().rootPageTitle:partialUrl() -- need to get rid of translation subpage.
return mw.loadData( 'Module:ExtensionJson' )[pg]
end


-- Return if the extension does schema updates
-- Return if the extension does schema updates
Line 273: Line 288:
     return ''
     return ''
end
end
 
function p.getHooks(frame)
local hookOutput = frame.args.header
local hooks = {}
local index = 1
local pframe = frame:getParent()
local foundLocalHooks = false
while true do
local argument = pframe.args["hook" .. index]
if argument and mw.text.trim(argument) ~= "" then
hooks[argument] = true
foundLocalHooks = true
else
break
end
index = index + 1
end
if not foundLocalHooks then
local data = getExtData()
if data == nil then
return ""
end
hooks = data.Hooks
if hooks == nil then
return ""
end
end
local first = true
for hook, _ in pairs(hooks) do
if first then
first = false
else
hookOutput = hookOutput .. frame.args.delim
end
hookOutput = hookOutput .. frame:expandTemplate{title="Extension/HookInUse",args={hook,templatemode=frame.args.templatemode}}
end
return hookOutput .. frame.args.footer
end
function p.getParameters(frame)
local data = getExtData()
if data == nil then
return ""
end
local config = data.config
if config == nil then
return ""
end
local out = ""
for key, _ in pairs(config) do
out = out .. "* $wg" .. key .. "\n"
end
return out
end
function p.getRights(frame)
local data = getExtData()
if data == nil then
return ""
end
local rights = data.AvailableRights
if rights == nil then
return ""
end
local out = ""
-- [[Module:ExtensionJson]] starts at zero, but Lua tables start at 1
local iter, table_ = ipairs(rights)
for _, right in iter, table_, -1 do
out = out .. "* " .. right .. "\n"
end
return out
end
return p
return p
Anonymous user