Difference between revisions of "Module:Extension"

51 bytes added ,  13:44, 21 June 2019
i18n using parameters from Template:Extension, define aliases for essentially same types
>Ciencia Al Poder
(check against data being nil (Topic:V00kusib8yt1u3vu))
>Tacsipacsi
(i18n using parameters from Template:Extension, define aliases for essentially same types)
Line 24: Line 24:
}
}
local licenses = {
local licenses = {
['GPL-2.0']      = { '[' .. addr.GNU .. 'old-licenses/gpl-2.0-standalone.html GNU General Public License 2.0]', 'GPL' },
['GPL-2.0']      = { addr.GNU .. 'old-licenses/gpl-2.0-standalone.html', 'GNU General Public License 2.0', 'GPL' },
['GPL-2.0-only'] = { '[' .. addr.GNU .. 'old-licenses/gpl-2.0-standalone.html GNU General Public License 2.0 only]', 'GPL' },
['GPL-2.0-only'] = { addr.GNU .. 'old-licenses/gpl-2.0-standalone.html', 'GNU General Public License 2.0 only', 'GPL' },
['GPL-2.0-or-later'] = { '[' .. addr.GNU .. 'old-licenses/gpl-2.0-standalone.html GNU General Public License 2.0 or later]', 'GPL' },
['GPL-2.0-or-later'] = { addr.GNU .. 'old-licenses/gpl-2.0-standalone.html', 'GNU General Public License 2.0 or later', 'GPL' },
['GPL-3.0']      = { '[' .. addr.GNU .. 'gpl-3.0-standalone.html GNU General Public License 3.0]', 'GPL' },
['GPL-3.0']      = { addr.GNU .. 'gpl-3.0-standalone.html', 'GNU General Public License 3.0', 'GPL' },
['GPL-3.0-only'] = { '[' .. addr.GNU .. 'gpl-3.0-standalone.html GNU General Public License 3.0 only]', 'GPL' },
['GPL-3.0-only'] = { addr.GNU .. 'gpl-3.0-standalone.html', 'GNU General Public License 3.0 only', 'GPL' },
['GPL-3.0-or-later'] = { '[' .. addr.GNU .. 'gpl-3.0-standalone.html GNU General Public License 3.0 or later]', 'GPL' },
['GPL-3.0-or-later'] = { addr.GNU .. 'gpl-3.0-standalone.html', 'GNU General Public License 3.0 or later', 'GPL' },
['AGPL-3.0']    = { '[' .. addr.GNU .. 'agpl-3.0.html GNU Affero General Public License 3.0]', 'AGPL' },
['AGPL-3.0']    = { addr.GNU .. 'agpl-3.0.html', 'GNU Affero General Public License 3.0', 'AGPL' },
['LGPL-2.1']    = { '[' .. addr.GNU .. 'old-licenses/lgpl-2.1-standalone.html GNU Lesser General Public License 2.1]', 'LGPL' },
['LGPL-2.1']    = { addr.GNU .. 'old-licenses/lgpl-2.1-standalone.html', 'GNU Lesser General Public License 2.1', 'LGPL' },
['LGPL-2.1-only'] = { '[' .. addr.GNU .. 'old-licenses/lgpl-2.1-standalone.html GNU Lesser General Public License 2.1 only]', 'LGPL' },
['LGPL-2.1-only'] = { addr.GNU .. 'old-licenses/lgpl-2.1-standalone.html', 'GNU Lesser General Public License 2.1 only', 'LGPL' },
['LGPL-2.1-or-later'] = { '[' .. addr.GNU .. 'old-licenses/lgpl-2.1-standalone.html GNU Lesser General Public License 2.1 or later]', 'LGPL' },
['LGPL-2.1-or-later'] = { addr.GNU .. 'old-licenses/lgpl-2.1-standalone.html', 'GNU Lesser General Public License 2.1 or later', 'LGPL' },
['LGPL-3.0']    = { '[' .. addr.GNU .. 'lgpl-3.0-standalone.html GNU Lesser General Public License 3.0]', 'LGPL' },
['LGPL-3.0']    = { addr.GNU .. 'lgpl-3.0-standalone.html', 'GNU Lesser General Public License 3.0', 'LGPL' },
['LGPL-3.0-only'] = { '[' .. addr.GNU .. 'lgpl-3.0-standalone.html GNU Lesser General Public License 3.0 only]', 'LGPL' },
['LGPL-3.0-only'] = { addr.GNU .. 'lgpl-3.0-standalone.html', 'GNU Lesser General Public License 3.0 only', 'LGPL' },
['LGPL-3.0-or-later'] = { '[' .. addr.GNU .. 'lgpl-3.0-standalone.html GNU Lesser General Public License 3.0 or later]', 'LGPL' },
['LGPL-3.0-or-later'] = { addr.GNU .. 'lgpl-3.0-standalone.html', 'GNU Lesser General Public License 3.0 or later', 'LGPL' },
['FDL']          = { '[' .. addr.GNU .. 'fdl.html GNU Free Documentation License]', 'FDL' },
['FDL']          = { addr.GNU .. 'fdl.html', 'GNU Free Documentation License', 'FDL' },
['MIT']          = { '[' .. addr.OSI .. 'mit-license.php MIT License]', 'MIT' },
['MIT']          = { addr.OSI .. 'mit-license.php', 'MIT License', 'MIT' },
['ISC']          = { '[' .. addr.OSI .. 'ISC ISC License]', 'ISC' },
['ISC']          = { addr.OSI .. 'ISC', 'ISC License', 'ISC' },
['BSD-2-Clause'] = { '[' .. addr.OSI .. 'BSD-2-Clause BSD 2-clause "Simplified" License]', 'BSD' },
['BSD-2-Clause'] = { addr.OSI .. 'BSD-2-Clause', 'BSD 2-clause "Simplified" License', 'BSD' },
['BSD-3-Clause'] = { '[' .. addr.OSI .. 'BSD-3-Clause BSD 3-clause "Modified" License]', 'BSD' },
['BSD-3-Clause'] = { addr.OSI .. 'BSD-3-Clause', 'BSD 3-clause "Modified" License', 'BSD' },
['BSD-4-Clause'] = { '[' .. addr.GNU .. 'license-list.html#OriginalBSD BSD-4-Clause BSD 4-clause "Original" License]', 'BSD' },
['BSD-4-Clause'] = { addr.GNU .. 'license-list.html#OriginalBSD', 'BSD 4-clause "Original" License', 'BSD' },
['MPL-1.0']      = { '[' .. addr.Mozilla .. 'MPL/1.0/ Mozilla Public License 1.0]', 'MPL' },
['MPL-1.0']      = { addr.Mozilla .. 'MPL/1.0/', 'Mozilla Public License 1.0', 'MPL' },
['MPL-2.0']      = { '[' .. addr.Mozilla .. 'MPL/2.0/ Mozilla Public License 2.0]', 'MPL' },
['MPL-2.0']      = { addr.Mozilla .. 'MPL/2.0/', 'Mozilla Public License 2.0', 'MPL' },
['WTFPL']        = { '[http://www.wtfpl.net WTFPL 2.0]', 'WTFPL' },
['WTFPL']        = { 'http://www.wtfpl.net', 'WTFPL 2.0', 'WTFPL' },
['Apache-2.0']  = { '[//www.apache.org/licenses/LICENSE-2.0 Apache License 2.0]', 'Apache' },
['Apache-2.0']  = { '//www.apache.org/licenses/LICENSE-2.0', 'Apache License 2.0', 'Apache' },
['Zlib']        = { '[' .. addr.OSI .. 'Zlib zlib License]' },
['Zlib']        = { addr.OSI .. 'Zlib', 'zlib License' },
['CC0-1.0']      = { '[//creativecommons.org/publicdomain/zero/1.0/ Creative Commons Zero v1.0 Universal]', 'PD' },
['CC0-1.0']      = { '//creativecommons.org/publicdomain/zero/1.0/', 'Creative Commons Zero v1.0 Universal', 'PD' },
['CC-BY-3.0']    = { '[' .. addr.CC .. 'by/3.0/ Creative Commons Attribution 3.0]', 'CC' },
['CC-BY-3.0']    = { addr.CC .. 'by/3.0/', 'Creative Commons Attribution 3.0', 'CC' },
['CC-BY-SA-2.0'] = { '[' .. addr.CC .. 'by-sa/2.0/ Creative Commons Attribution Share Alike 2.0]', 'CC' },
['CC-BY-SA-2.0'] = { addr.CC .. 'by-sa/2.0/', 'Creative Commons Attribution Share Alike 2.0', 'CC' },
['CC-BY-SA-2.5'] = { '[' .. addr.CC .. 'by-sa/2.5/ Creative Commons Attribution Share Alike 2.5]', 'CC' },
['CC-BY-SA-2.5'] = { addr.CC .. 'by-sa/2.5/', 'Creative Commons Attribution Share Alike 2.5', 'CC' },
['CC-BY-NC-SA-2.5'] = { '[' .. addr.CC .. 'by-nc-sa/2.5/ Creative Commons Attribution NonCommercial Share Alike 2.5]', 'CC' },
['CC-BY-NC-SA-2.5'] = { addr.CC .. 'by-nc-sa/2.5/', 'Creative Commons Attribution NonCommercial Share Alike 2.5', 'CC' },
['CC-BY-NC-SA-3.0'] = { '[' .. addr.CC .. 'by-nc-sa/3.0/ Creative Commons Attribution NonCommercial Share Alike 3.0]', 'CC' },
['CC-BY-NC-SA-3.0'] = { addr.CC .. 'by-nc-sa/3.0/', 'Creative Commons Attribution NonCommercial Share Alike 3.0', 'CC' },
['CC-BY-NC-3.0'] = { '[' .. addr.CC .. 'by-nc/3.0/ Creative Commons Attribution NonCommercial 3.0]', 'CC' },
['CC-BY-NC-3.0'] = { addr.CC .. 'by-nc/3.0/', 'Creative Commons Attribution NonCommercial 3.0', 'CC' },
['CC-BY-SA-3.0'] = { '[' .. addr.CC .. 'by-sa/3.0/ Creative Commons Attribution Share Alike 3.0]', 'CC' },
['CC-BY-SA-3.0'] = { addr.CC .. 'by-sa/3.0/', 'Creative Commons Attribution Share Alike 3.0', 'CC' },
['CC-BY-SA-4.0'] = { '[' .. addr.CC .. 'by-sa/4.0/ Creative Commons Attribution Share Alike 4.0]', 'CC' },
['CC-BY-SA-4.0'] = { addr.CC .. 'by-sa/4.0/', 'Creative Commons Attribution Share Alike 4.0', 'CC' },
['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' },
}
}
local types = {
local types = {
Line 66: Line 66:
contenthandler      = { '[[Manual:ContentHandler|ContentHandler]]',              'ContentHandler extensions' },
contenthandler      = { '[[Manual:ContentHandler|ContentHandler]]',              'ContentHandler extensions' },
database            = { '[[Manual:Database layout|Database]]',                    'Database extensions' },
database            = { '[[Manual:Database layout|Database]]',                    'Database extensions' },
db                  = { 'Database',                                              'Database extensions' },
['data extraction'] = { 'Data extraction',                                        'Data extraction extensions' },
['data extraction'] = { 'Data extraction',                                        'Data extraction extensions' },
example            = { 'Example',                                                'Extension examples' },
example            = { 'Example',                                                'Extension examples' },
Line 80: Line 79:
parser              = { '[[Manual:Extending wiki markup|Parser extension]]',      'Parser extensions' },
parser              = { '[[Manual:Extending wiki markup|Parser extension]]',      'Parser extensions' },
['parser function'] = { '[[Manual:Parser functions|Parser function]]',            'Parser function extensions' },
['parser function'] = { '[[Manual:Parser functions|Parser function]]',            'Parser function extensions' },
pfunc              = { '[[Manual:Parser functions|Parser functions]]',          'Parser function extensions' },
php                = { 'PHP',                                                    'PHP extensions' },
php                = { 'PHP',                                                    'PHP extensions' },
search              = { 'Search',                                                'Search extensions' },
search              = { 'Search',                                                'Search extensions' },
skin                = { '[[Manual:Skins|Skin]]',                                  'Skin extensions' },
skin                = { '[[Manual:Skins|Skin]]',                                  'Skin extensions' },
special            = { '[[Manual:Special pages|Special page]]',                  'Special page extensions' },
['special page']    = { '[[Manual:Special pages|Special page]]',                  'Special page extensions' },
['special page']    = { '[[Manual:Special pages|Special page]]',                  'Special page extensions' },
locale              = { '[[Manual:Localization|Locale]]',                        'Internationalization extensions' },
locale              = { '[[Manual:Localization|Locale]]',                        'Internationalization extensions' },
Line 99: Line 96:
namespace          = { '[[Manual:Namespaces|Namespace]]',                        'Namespace extensions', deprecated = true },
namespace          = { '[[Manual:Namespaces|Namespace]]',                        'Namespace extensions', deprecated = true },
['table']          = { 'Table',                                                  'Table extensions',    deprecated = true },
['table']          = { 'Table',                                                  'Table extensions',    deprecated = true },
}
local typeAliases = {
db = 'database',
pfunc = 'parser function',
special = 'special page',
}
}


-- DEPRECATED TYPES (multiple types handled via type1,type2,...)
-- DEPRECATED TYPES (multiple types handled via type1,type2,...)
local deprecatedTypes = {
local deprecatedTypes = {
['link, tag, special'] = { 'link', 'tag', 'special' },
['link, tag, special'] = { 'link', 'tag', 'special page' },
['parser function, special'] = { 'parser function', 'special page' },
['parser function, special'] = { 'parser function', 'special page' },
['tag, parser function'] = { 'tag', 'parser function' },
['tag, parser function'] = { 'tag', 'parser function' },
Line 109: Line 112:
['tag, special'] = { 'tag', 'special page' },
['tag, special'] = { 'tag', 'special page' },
['parser, pfunc'] = { 'parser function' },
['parser, pfunc'] = { 'parser function' },
['parser, hook, special'] = { 'tag' --[[ sic ]], 'hook', 'special' },
['parser, hook, special'] = { 'tag' --[[ sic ]], 'hook', 'special page' },
}
}
local function setI18n( from, to, index )
for n, v in pairs( from ) do
if to[n] then
to[n][index] = v
end
end
end


local function cat( title )
local function cat( title )
Line 122: Line 133:
local function getType( str, str2 )
local function getType( str, str2 )
local str = mw.ustring.lower( str )
local str = mw.ustring.lower( str )
if typeAliases[str] then
str = typeAliases[str]
end
local cnf = types[str]
local cnf = types[str]
local res
local res
Line 166: Line 180:
local cnf = licenses[str]
local cnf = licenses[str]
if cnf then
if cnf then
if #cnf > 1 then
if #cnf > 2 then
return tcat( cats[cnf[2]] )
return tcat( cats[cnf[3]] )
end
end
else
else
Line 174: Line 188:
end
end


local function getFormattedLicense( str )
local function getFormattedLicense( str, orlatertext )
local orlater = ''
local orlater = ''
local license = str
local license = str
if mw.ustring.sub( str, -1 ) == '+' then
if mw.ustring.sub( str, -1 ) == '+' then
license = mw.ustring.sub( str, 1, -2 )
license = mw.ustring.sub( str, 1, -2 )
orlater = ' or later'
orlater = orlatertext
end
end
local cnf = licenses[license]
local cnf = licenses[license]
if cnf then
if cnf then
return cnf[1] .. orlater
return (cnf[1] ~= '' and ('[' .. cnf[1] .. ' ' .. cnf[2] .. ']') or cnf[2]) .. orlater
else
else
return str
return str
Line 192: Line 206:


function p.getTypes( frame )
function p.getTypes( frame )
setI18n( frame.args, types, 1 )
local args = frame:getParent().args
local args = frame:getParent().args
local types = {}
local types = {}
Line 217: Line 232:


function p.getType( frame )
function p.getType( frame )
setI18n( frame.args, types, 1 )
return getType( frame.args[1] )
return getType( frame.args[1] )
end
end
Line 225: Line 241:


function p.getFormattedLicense( frame )
function p.getFormattedLicense( frame )
return getFormattedLicense( frame.args[1] )
setI18n( frame.args, licenses, 2 )
return getFormattedLicense( frame.args[1] and mw.text.trim( frame.args[1] ) or nil, frame.args['+'] or ' or later' )
end
end


Anonymous user