Difference between revisions of "Module:Extension"
Jump to navigation
Jump to search
>Shirayuki m (Undo revision 1381204 by Shirayuki (talk): Doesn't work on Extension:AuthorInfo, etc.) |
>Ricordisamoa m (simplify) |
||
Line 2: | Line 2: | ||
local translation = mw.getCurrentFrame():expandTemplate{ title = 'translation' } | local translation = mw.getCurrentFrame():expandTemplate{ title = 'translation' } | ||
local addr = { | local addr = { | ||
GNU = '//www.gnu.org/', | GNU = '//www.gnu.org/licenses/', | ||
OSI = 'http://opensource.org/licenses/', | OSI = 'http://opensource.org/licenses/', | ||
CC = '//creativecommons.org/licenses/', | CC = '//creativecommons.org/licenses/', | ||
Line 21: | Line 21: | ||
} | } | ||
local licenses = { | local licenses = { | ||
['GPL-2.0'] = { '[' .. addr.GNU .. ' | ['GPL-2.0'] = { '[' .. addr.GNU .. 'gpl-2.0.html GNU General Public License 2.0]', 'GPL' }, | ||
['GPL-2.0+'] = { '[' .. addr.GNU .. ' | ['GPL-2.0+'] = { '[' .. addr.GNU .. 'gpl-2.0.html GNU General Public License 2.0] or later', 'GPL' }, | ||
['GPL-3.0'] = { '[' .. addr.GNU .. ' | ['GPL-3.0'] = { '[' .. addr.GNU .. 'gpl-3.0.html GNU General Public License 3.0]', 'GPL' }, | ||
['GPL-3.0+'] = { '[' .. addr.GNU .. ' | ['GPL-3.0+'] = { '[' .. addr.GNU .. 'gpl-3.0.html GNU General Public License 3.0] or later', 'GPL' }, | ||
['AGPL-3.0'] = { '[' .. addr.GNU .. ' | ['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+'] = { '[' .. addr.GNU .. 'agpl-3.0.html GNU Affero General Public License 3.0] or later', 'AGPL' }, | ||
['LGPL-2.1'] = { '[' .. addr.GNU .. ' | ['LGPL-2.1'] = { '[' .. addr.GNU .. 'lgpl-2.1.html GNU Lesser General Public License 2.1]', 'LGPL' }, | ||
['LGPL-2.1+'] = { '[' .. addr.GNU .. ' | ['LGPL-2.1+'] = { '[' .. addr.GNU .. 'lgpl-2.1.html GNU Lesser General Public License 2.1] or later', 'LGPL' }, | ||
['LGPL-3.0'] = { '[' .. addr.GNU .. ' | ['LGPL-3.0'] = { '[' .. addr.GNU .. 'lgpl-3.0.html GNU Lesser General Public License 3.0]', 'LGPL' }, | ||
['LGPL-3.0+'] = { '[' .. addr.GNU .. ' | ['LGPL-3.0+'] = { '[' .. addr.GNU .. 'lgpl-3.0.html GNU Lesser General Public License 3.0] or later', 'LGPL' }, | ||
['FDL'] = { '[' .. addr.GNU .. ' | ['FDL'] = { '[' .. addr.GNU .. 'fdl.html GNU Free Documentation License]' }, | ||
['MIT'] = { '[' .. addr.OSI .. 'mit-license.php MIT License]', 'MIT' }, | ['MIT'] = { '[' .. addr.OSI .. 'mit-license.php MIT License]', 'MIT' }, | ||
['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' }, |
Revision as of 18:45, 30 January 2015
Documentation for this module may be created at Module:Extension/doc
local lang = mw.language.getContentLanguage()
local translation = mw.getCurrentFrame():expandTemplate{ title = 'translation' }
local addr = {
GNU = '//www.gnu.org/licenses/',
OSI = 'http://opensource.org/licenses/',
CC = '//creativecommons.org/licenses/',
Mozilla = '//www.mozilla.org/'
}
local cats = {
GPL = 'GPL licensed extensions',
LGPL = 'LGPL licensed extensions',
AGPL = 'AGPL licensed extensions',
MIT = 'MIT licensed extensions',
BSD = 'BSD licensed extensions',
MPL = 'MPL licensed extensions',
WTFPL = 'WTFPL licensed extensions',
Apache = 'Apache licensed extensions',
PD = 'Public domain licensed extensions',
CC = 'Creative Commons licensed extensions',
ECL = 'Educational Community licensed extensions',
}
local licenses = {
['GPL-2.0'] = { '[' .. addr.GNU .. 'gpl-2.0.html GNU General Public License 2.0]', 'GPL' },
['GPL-2.0+'] = { '[' .. addr.GNU .. 'gpl-2.0.html GNU General Public License 2.0] or later', 'GPL' },
['GPL-3.0'] = { '[' .. addr.GNU .. 'gpl-3.0.html GNU General Public License 3.0]', 'GPL' },
['GPL-3.0+'] = { '[' .. addr.GNU .. 'gpl-3.0.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] or later', 'AGPL' },
['LGPL-2.1'] = { '[' .. addr.GNU .. 'lgpl-2.1.html GNU Lesser General Public License 2.1]', 'LGPL' },
['LGPL-2.1+'] = { '[' .. addr.GNU .. 'lgpl-2.1.html GNU Lesser General Public License 2.1] or later', 'LGPL' },
['LGPL-3.0'] = { '[' .. addr.GNU .. 'lgpl-3.0.html GNU Lesser General Public License 3.0]', 'LGPL' },
['LGPL-3.0+'] = { '[' .. addr.GNU .. 'lgpl-3.0.html GNU Lesser General Public License 3.0] or later', 'LGPL' },
['FDL'] = { '[' .. addr.GNU .. 'fdl.html GNU Free Documentation License]' },
['MIT'] = { '[' .. addr.OSI .. 'mit-license.php MIT License]', 'MIT' },
['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' },
['Apache-2.0'] = { '[http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0]', 'Apache' },
['ECL-2.0'] = { '[[wikipedia:Educational Community License|Educational Community License 2.0]]', 'ECL' },
}
local types = {
ajax = { '[[w:AJAX|Ajax]]', 'Ajax extensions' },
api = { '[[API:Main page|API]]', 'API extensions' },
['beta feature'] = { '[[Beta Features|Beta Feature]]', 'Beta Feature extensions' },
contenthandler = { '[[Manual:ContentHandler|ContentHandler]]', 'ContentHandler extensions' },
database = { '[[Manual:Database layout|Database]]', 'Database extensions' },
db = { 'Database', 'Database extensions' },
['data extraction'] = { 'Data extraction', 'Data extraction extensions' },
example = { 'Example', 'Extension examples' },
['extended syntax'] = { '[[Manual:Extending wiki markup|Extended syntax]]', 'Extended syntax extensions' },
filerepo = { 'File repository', 'File repository extensions' },
hook = { '[[Manual:Hooks|Hook]]', 'Hook extensions' },
interface = { 'User interface', 'User interface extensions' },
link = { '[[Manual:Extending wiki markup|Link markup]]', 'Link markup extensions' },
media = { 'Media', 'Media handling extensions' },
mywiki = { '[[Manual:Personalization|MyWiki]]', 'Personalization extensions' },
notify = { 'Notify', 'Notification extensions' },
['page action'] = { '[[Manual:Parameters to index.php#Actions|Page action]]', 'Page action extensions' },
parser = { '[[Manual:Extending wiki markup|Parser extension]]', 'Parser extensions' },
['parser function'] = { '[[Manual:Parser functions|Parser function]]', 'Parser function extensions' },
pfunc = { '[[Manual:Parser functions|Parser functions]]', 'Parser function extensions' },
search = { 'Search', 'Search 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' },
locale = { '[[Manual:Localization|Locale]]', 'Internationalization extensions' },
tag = { '[[Manual:Tag extensions|Tag]]', 'Tag extensions' },
['user access'] = { '[[Manual:Security|User access]]', 'User access extensions' },
['user identity'] = { '[[Manual:Security|User identity]]', 'User identity extensions' },
['user rights'] = { '[[Manual:Security|User rights]]', 'User rights extensions' },
['user activity'] = { '[[Manual:Security|User activity]]', 'User activity extensions' },
variable = { '[[Manual:Variables|Variable]]', 'Variable extensions' },
-- DEPRECATED TYPES (as per 2007-09 taxonomy discussion)
category = { 'Category', 'Category extensions', deprecated = true },
form = { 'Form', 'Form extensions', deprecated = true },
list = { 'List', 'List extensions', deprecated = true },
namespace = { '[[Manual:Namespaces|Namespace]]', 'Namespace extensions', deprecated = true },
['table'] = { 'Table', 'Table extensions', deprecated = true },
}
-- DEPRECATED TYPES (multiple types handled via type1,type2,...)
local deprecatedTypes = {
['link, tag, special'] = { 'link', 'tag', 'special' },
['parser function, special'] = { 'parser function', 'special page' },
['tag, parser function'] = { 'tag', 'parser function' },
['tag, parser function, special'] = { 'tag', 'parser function', 'special page' },
['tag, special'] = { 'tag', 'special page' },
['parser, pfunc'] = { 'parser function' },
['parser, hook, special'] = { 'tag' --[[ sic ]], 'hook', 'special' },
}
local function cat( title )
return '[[Category:' .. title .. ']]'
end
local function tcat( title )
return cat( title .. translation )
end
local function getType( str, str2 )
local str = mw.ustring.lower( str )
local cnf = types[str]
local res
if cnf then
res = cnf[1] .. '[[Category:' .. cnf[2] .. translation .. ']]'
if cnf.deprecated then
res = res .. '\'\'-deprecated\'\'' ..
tcat( 'Extensions with deprecated types' )
end
else
cnf = deprecatedTypes[str]
if cnf then
local dtypes = {}
for _, sstr in ipairs( cnf ) do
table.insert( dtypes, getType( sstr ) )
end
res = table.concat( dtypes, ', ' ) ..
'<br />\'\'(deprecated, please use [[Template:Extension/doc#type|type1,type2'
if #cnf > 2 then
res = res .. ',type3'
end
res = res .. ']] instead)\'\'' .. tcat( 'Extensions with deprecated types' )
elseif str == '_missing_' then
res = tcat( 'Extensions with invalid or missing type' )
elseif str == '_demomode_' then
if str2 then
res = lang:ucfirst( str2 )
else
res = "''unknown''"
end
else
res = ( str or '\'\'unknown\'\'' ) ..
' [[Template:Extension/doc#type|(\'\'\'\'\'invalid type\'\'\'\'\')]]' ..
tcat( 'Extensions with invalid or missing type' )
end
end
return res
end
local function getLicenseCategory( str )
local cnf = licenses[str]
if cnf then
if #cnf > 1 then
return tcat( cats[cnf[2]] )
end
else
return tcat( 'Extensions with unknown license' )
end
end
local function getFormattedLicense( str )
local cnf = licenses[str]
if cnf then
return cnf[1]
else
return str
end
end
local p = {}
function p.getTypes( frame )
local args = frame:getParent().args
local types = {}
local params = {
args.type1 or args['type'] or 'missing',
args.type2,
args.type3,
args.type4,
args.type5,
args.type6,
}
for _, param in ipairs( params ) do
if param == nil or mw.text.trim( param ) == '' then
break
end
local param = mw.text.trim( param )
if args.templatemode == 'nocats' then
table.insert( types, getType( '_demomode_', param ) )
else
table.insert( types, getType( param ) )
end
end
return table.concat( types, ', ' )
end
function p.getType( frame )
return getType( frame.args[1] )
end
function p.getLicenseCategory( frame )
return getLicenseCategory( frame.args[1] )
end
function p.getFormattedLicense( frame )
return getFormattedLicense( frame.args[1] )
end
return p