Module:User Wikimedia project
This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
Usage
{{#invoke:User Wikimedia project|user_wikimedia_project}}
local p = {} --p stands for package
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local langSwitch = require('Module:Fallback')._langSwitch
local userbox = require('Module:Userbox').userbox
function is_wikimania_number_prefix(prefix)
local function is_prefix(wm)
return mw.ustring.sub(prefix, 1, mw.ustring.len(wm)) and mw.ustring.len(prefix) > mw.ustring.len(wm) and tonumber(mw.ustring.sub(prefix, mw.ustring.len(wm) + 1, -1))
end
return is_prefix('wm') or is_prefix('wikimania')
end
function project_name(prefix)
if is_wikimania_number_prefix(prefix) then
return 'Wikimania ' .. mw.ustring.sub(prefix, -4, -1)
end
local names = {
['b'] = 'Wikibooks',
['wikibooks'] = 'Wikibooks',
['c'] = 'Wikimedia Commons',
['commons'] = 'Wikimedia Commons',
['d'] = 'Wikidata',
['wikidata'] = 'Wikidata',
['f'] = 'Wikifunctions',
['wikifunctions'] = 'Wikifunctions',
['incubator'] = 'Incubator',
['m'] = 'Wikimedia MetaWiki',
['metawiki'] = 'Wikimedia MetaWiki',
['metawikimedia'] = 'Wikimedia MetaWiki',
['metawikipedia'] = 'Wikimedia MetaWiki',
['mw'] = 'MediaWiki',
['n'] = 'Wikinews',
['wikinews'] = 'Wikinews',
['q'] = 'Wikiquote',
['wikiquote'] = 'Wikiquote',
['s'] = 'Wikisource',
['wikisource'] = 'Wikisource',
['species'] = 'Wikispecies',
['wikispecies'] = 'Wikispecies',
['v'] = 'Wikiversity',
['wikiversity'] = 'Wikiversity',
['voy'] = 'Wikivoyage',
['wikivoyage'] = 'Wikivoyage',
['w'] = 'Wikipedia',
['wikipedia'] = 'Wikipedia',
['wikt'] = 'Wiktionary',
['wiktionary'] = 'Wiktionary',
['outreach'] = 'Wikimedia Outreach',
['wikitech'] = 'Wikitech',
['wm'] = 'Wikimania',
['wikimania'] = 'Wikimania'
}
return names[prefix] or prefix
end
function project_has_lang(prefix)
local no_lang_projects = {
['Wikimedia Commons'] = true,
['Incubator'] = true,
['Wikimedia MetaWiki'] = true,
['MediaWiki'] = true,
['Wikispecies'] = true,
['Wikimedia Outreach'] = true,
['Wikitech'] = true,
['Wikimania'] = true,
['Wikidata'] = true,
['Wikifunctions'] = true
}
return no_lang_projects[project_name(prefix)] ~= true and not is_wikimania_number_prefix(prefix)
end
function localized_project_name(prefix, lang_code, display_lang)
local name = project_name(prefix)
local project_names = {
['ang'] = {
['Wikipedia'] = 'Wicipædie'
},
['eo'] = {
['Wikipedia'] = 'Vikipedio'
},
['es'] = {
['Wikibooks'] = 'Wikilibros',
['Incubator'] = 'la Incubadora de Wikimedia',
['Wikinews'] = 'Wikinoticias',
['Wikispecies'] = 'Wikiespecies',
['Wikiversity'] = 'la Wikiversidad',
['Wikivoyage'] = 'Wikiviajes',
['Wiktionary'] = 'Wikcionario',
['Wikimania'] = 'Wikimanía'
},
['fa'] = {
['Wikisource'] = 'ویکینبشته '
},
['fi'] = {
['Wikidata'] = 'Wikidatassa',
['Wikiquote'] = 'Wikisitaateissa',
['Wikipedia'] = 'Wikipediassa'
},
['fr'] = {
['Wiktionary'] = 'Wiktionnaire',
['Wikipedia'] = 'Wikipédia'
},
['he'] = {
['Wikidata'] = 'ראשי',
['Wikimedia Commons'] = 'עמוד ראשי',
['Wikimedia MetaWiki'] = 'במטא-ויקי',
['Wiktionary'] = 'וויקימילון',
['Wikisource'] = 'וויקיטקסט'
},
['hr'] = {
['Wikipedia'] = 'Wikipediji'
},
['hu'] = {
['Wikipedia'] = 'Wikipédián'
},
['ja'] = {
['Wikidata'] = 'ウィキデータ',
['Wikimedia Commons'] = 'ウィキメディア・コモンズ',
['Wikimedia MetaWiki'] = 'メタ・ウィキメディア',
['Wikivoyage'] = 'ウィキボヤージュ',
['Wikiversity'] = 'ウィキバーシティ',
['Wikispecies'] = 'ウィキスピーシーズ',
['Wikiquote'] = 'ウィキクオート',
['Wiktionary'] = 'ウィクショナリー',
['Wikisource'] = 'ウィキソース',
['Wikipedia'] = 'ウィキペディア'
},
['ko'] = {
['Wikimedia Commons'] = '위키미디어 공용',
['Wikimedia MetaWiki'] = '위키미디어 메타',
['Wikiversity'] = '위키배움터'
},
['pa'] = {
['Wikimedia Commons'] = 'ਵਿਕੀਮੀਡੀਆ ਕਾਮਨਜ਼',
['Wikimedia MetaWiki'] = 'ਵਿਕੀਮੀਡੀਆ ਮੈਟਾ-ਵਿਕੀ',
['Wikidata'] = 'ਵਿਕੀਡਾਟਾ',
['Wikisource'] = 'ਵਿਕੀਸਰੋਤ',
['Wikipedia'] = 'ਵਿਕੀਪੀਡੀਆ'
},
['ta'] = {
['Wikipedia'] = 'விக்கிப்பீடியாது',
},
['tr'] = {
['Wikidata'] = 'Vikiveri',
['Wikimedia MetaWiki'] = 'Wikimedia Meta Viki',
['Wikispecies'] = 'Vikitür',
['Wiktionary'] = 'Vikisözlük'
},
['uk'] = {
['Wikipedia'] = 'Вікіпедії'
},
['vec'] = {
['Wikipedia'] = 'Wikipèdia'
}
}
local localized_name = name
if project_names[display_lang] then
if project_names[display_lang][name] then
localized_name = project_names[display_lang][name]
elseif mw.ustring.sub(name, 1, 9) == 'Wikimania' and project_names[display_lang]['Wikimania'] then
localized_name = string.gsub(name, 'Wikimania', project_names[display_lang]['Wikimania'])
end
end
if project_has_lang(prefix) and lang_code then
local language_adjectives = {
['ang'] = {
['ang'] = 'Engliscan'
},
['en'] = {
['ang'] = 'Old English',
['ar'] = 'Arabic',
['az'] = 'Azerbaijani',
['bn'] = 'Bengali',
['br'] = 'Breton',
['cs'] = 'Czech',
['da'] = 'Danish',
['de'] = 'German',
['en'] = 'English',
['eo'] = 'Esperanto',
['es'] = 'Spanish',
['fa'] = 'Persian',
['fi'] = 'Finnish',
['fr'] = 'French',
['gl'] = 'Galician',
['he'] = 'Hebrew',
['hi'] = 'Hindi',
['hr'] = 'Croatian',
['hu'] = 'Hungarian',
['hy'] = 'Armenian',
['id'] = 'Indonesian',
['it'] = 'Italian',
['ja'] = 'Japanese',
['ko'] = 'Korean',
['ml'] = 'Malayalam',
['nl'] = 'Dutch',
['no'] = 'Norwegian (Bokmål)',
['pa'] = 'Punjabi',
['pl'] = 'Polish',
['ro'] = 'Romanian',
['ru'] = 'Russian',
['simple'] = 'Simple English',
['sk'] = 'Slovak',
['sq'] = 'Albanian',
['sv'] = 'Swedish',
['ta'] = 'Tamil',
['tr'] = 'Turkish',
['uk'] = 'Ukrainian',
['vec'] = 'Venetian',
['vi'] = 'Vietnamese',
['zh'] = 'Chinese'
},
['eo'] = {
['fr'] = 'Franca'
},
['es'] = {
['ang'] = {['m'] = 'anglosajón', ['f'] = 'anglosajona'},
['ar'] = {['m'] = 'árabe', ['f'] = 'árabe'},
['az'] = {['m'] = 'azerí', ['f'] = 'azerí'},
['bn'] = {['m'] = 'bengalí', ['f'] = 'bengalí'},
['br'] = {['m'] = 'bretón', ['f'] = 'bretona'},
['cs'] = {['m'] = 'checo', ['f'] = 'checa'},
['da'] = {['m'] = 'danés', ['f'] = 'danesa'},
['de'] = {['m'] = 'alemán', ['f'] = 'alemana'},
['en'] = {['m'] = 'inglés', ['f'] = 'inglesa'},
['eo'] = {['m'] = 'en esperanto', ['f'] = 'en esperanto'},
['es'] = {['m'] = 'español', ['f'] = 'española'},
['fa'] = {['m'] = 'persa', ['f'] = 'persa'},
['fi'] = {['m'] = 'finés', ['f'] = 'finesa'},
['fr'] = {['m'] = 'francés', ['f'] = 'francesa'},
['gl'] = {['m'] = 'gallego', ['f'] = 'gallega'},
['he'] = {['m'] = 'hebreo', ['f'] = 'hebrea'},
['hi'] = {['m'] = 'hindi', ['f'] = 'hindi'},
['hr'] = {['m'] = 'croata', ['f'] = 'croata'},
['hu'] = {['m'] = 'húngaro', ['f'] = 'húngara'},
['hy'] = {['m'] = 'armenio', ['f'] = 'armenia'},
['id'] = {['m'] = 'indonesio', ['f'] = 'indonesia'},
['it'] = {['m'] = 'italiano', ['f'] = 'italiana'},
['ja'] = {['m'] = 'japonés', ['f'] = 'japonesa'},
['ko'] = {['m'] = 'coreano', ['f'] = 'coreana'},
['ml'] = {['m'] = 'malayalam', ['f'] = 'malayalam'},
['nl'] = {['m'] = 'holandés', ['f'] = 'holandesa'},
['no'] = {['m'] = 'en noruego (bokmål)', ['f'] = 'en noruego (bokmål)'},
['pa'] = {['m'] = 'punjabi', ['f'] = 'punjabi'},
['pl'] = {['m'] = 'polaco', ['f'] = 'polaca'},
['ro'] = {['m'] = 'rumano', ['f'] = 'rumana'},
['ru'] = {['m'] = 'ruso', ['f'] = 'rusa'},
['simple'] = {['m'] = 'en inglés simple', ['f'] = 'en inglés simple'},
['sk'] = {['m'] = 'eslovaco', ['f'] = 'eslovaca'},
['sq'] = {['m'] = 'albanés', ['f'] = 'albanesa'},
['sv'] = {['m'] = 'sueco', ['f'] = 'sueca'},
['ta'] = {['m'] = 'támil', ['f'] = 'támil'},
['tr'] = {['m'] = 'turco', ['f'] = 'turca'},
['uk'] = {['m'] = 'ucraniano', ['f'] = 'ucraniana'},
['vec'] = {['m'] = 'véneto', ['f'] = 'véneta'},
['vi'] = {['m'] = 'vietnamita', ['f'] = 'vietnamita'},
['zh'] = {['m'] = 'chino', ['f'] = 'china'}
},
['fi'] = {
['fi'] = 'suomenkielisessä',
['fr'] = 'ranskankielisessä'
},
['fr'] = {
['fr'] = 'Français'
},
['ja'] = {
['ja'] = '日本語版'
},
['pa'] = {
['pa'] = 'ਪੰਜਾਬੀ'
},
['ta'] = {
['ta'] = 'தமிழ்'
}
}
if language_adjectives[display_lang] and language_adjectives[display_lang][lang_code] then
if display_lang == 'en' then
localized_name = 'the ' .. language_adjectives[display_lang][lang_code] .. " " .. localized_name
elseif display_lang == 'ang' then
localized_name = 'þæm ' .. language_adjectives[display_lang][lang_code] .. " " .. localized_name
elseif display_lang == 'eo' then
localized_name = 'la ' .. language_adjectives[display_lang][lang_code] .. " " .. localized_name
elseif display_lang == 'es' then
if localized_name == 'la Incubadora de Wikimedia' or localized_name == 'la Wikiversidad' then
localized_name = localized_name .. ' ' .. language_adjectives[display_lang][lang_code]['f']
elseif localized_name == 'Wikinoticias' or localized_name == 'Wikiespecies' or localized_name == 'Wikimanía' then
localized_name = 'la ' .. localized_name .. ' ' .. language_adjectives[display_lang][lang_code]['f']
else
localized_name = 'el ' .. localized_name .. ' ' .. language_adjectives[display_lang][lang_code]['m']
end
elseif display_lang == 'fi' or display_lang == 'ta' then
localized_name = language_adjectives[display_lang][lang_code] .. " " .. localized_name
elseif display_lang == 'fr' then
localized_name = 'le ' .. localized_name .. ' ' .. language_adjectives[display_lang][lang_code]
end
else
localized_name = lang_code .. '-' .. localized_name
end
end
return localized_name
end
function project_link_prefix(prefix, lang_code)
if project_name(prefix) == 'Wikimedia MetaWiki' then
return 'm:'
else
local link_prefix = prefix
if project_has_lang(prefix) and lang_code then
link_prefix = link_prefix .. ':' .. lang_code
end
link_prefix = link_prefix .. ':'
return link_prefix
end
end
function project_userpage_link(prefix, lang_code, username, page_word)
return "'''[[" .. project_link_prefix(prefix, lang_code) .. 'User:' .. username .. '|<span title="User:' .. username .. '">' .. page_word .. "</span>]]'''"
end
function project_project_link(prefix, lang_code, display_lang)
if prefix == 'wikidata' then
return '[[' .. project_link_prefix(prefix, lang_code) .. 'Special:MyLanguage/Wikidata:Main_Page|' .. localized_project_name(prefix, lang_code, display_lang) .. ']]'
else
return '[[' .. project_link_prefix(prefix, lang_code) .. 'Special:MyLanguage/Main_Page|' .. localized_project_name(prefix, lang_code, display_lang) .. ']]'
end
end
function project_text(prefix, lang_code, username, gender, display_lang)
local args = {
['ang'] = 'Þes brūcend hæfþ ' .. project_userpage_link(prefix, lang_code, username, 'tramet') .. ' on ' .. project_project_link(prefix, lang_code, 'ang') .. '.',
['da'] = 'Denne bruger har ' .. project_userpage_link(prefix, lang_code, username, 'en side') .. ' på ' .. project_project_link(prefix, lang_code, 'da') .. '.',
['de'] = 'Dieser Benutzer hat ' .. project_userpage_link(prefix, lang_code, username, 'eine Seite') .. ' auf ' .. project_project_link(prefix, lang_code, 'en') .. '.',
['en'] = 'This user has ' .. project_userpage_link(prefix, lang_code, username, 'a page') .. ' on ' .. project_project_link(prefix, lang_code, 'en') .. '.',
['eo'] = 'Ĉi tiu uzanto havas ' .. project_userpage_link(prefix, lang_code, username, 'retpaĝo') .. ' en ' .. project_project_link(prefix, lang_code, 'eo') .. '.',
['es'] = mw.language.getContentLanguage():gender(gender, 'Este usuario', 'Esta usuaria', 'Esta persona') .. ' tiene ' .. project_userpage_link(prefix, lang_code, username, 'una página') .. ' en ' .. project_project_link(prefix, lang_code, 'es') .. '.',
['fa'] = 'کاربر دارای' .. project_userpage_link(prefix, lang_code, username, 'یک صفحه') .. ' در ' .. project_project_link(prefix, lang_code, 'fa') .. ' است.',
['fi'] = 'Tällä käyttäjällä on ' .. project_userpage_link(prefix, lang_code, username, 'käyttäjäsivu') .. ' projektissa ' .. project_project_link(prefix, lang_code, 'fi') .. '.',
['fr'] = mw.language.getContentLanguage():gender(gender, 'Cet utilisateur', 'Cette utilisatrice', 'Cette personne') .. ' a ' .. project_userpage_link(prefix, lang_code, username, 'une page') .. ' sur ' .. project_project_link(prefix, lang_code, 'fr') .. '.',
['he'] = '<div style="text-align:right; direction:rtl;">' .. 'יש ' .. mw.language.getContentLanguage():gender(gender, 'למשתמש זה', 'למשתמשת זו', 'למשתמש זה') .. ' ' .. project_userpage_link(prefix, lang_code, username, 'דף משתמש') .. ' ' .. 'ב' .. project_project_link(prefix, lang_code, 'he') .. '.</div>',
['hr'] = 'Ovaj suradnik ima ' .. project_userpage_link(prefix, lang_code, username, 'suradničku stranicu') .. ' na ' .. project_project_link(prefix, lang_code, 'hr') .. '.',
['hu'] = 'Ennek a szerkesztőnek a ' .. project_project_link(prefix, lang_code, 'hu') .. ' oldalán is van ' .. project_userpage_link(prefix, lang_code, username, 'fiókja') .. '.',
['id'] = 'Pengguna ini memiliki ' .. project_userpage_link(prefix, lang_code, username, 'akun') .. ' di ' .. project_project_link(prefix, lang_code, 'id') .. '.',
['it'] = mw.language.getContentLanguage():gender(gender, 'Questo utente', 'Questa utente', "Quest'utente") .. ' ha ' .. project_userpage_link(prefix, lang_code, username, 'una pagina') .. ' su ' .. project_project_link(prefix, lang_code, 'it') .. '.',
['ja'] = 'この利用者の' .. project_userpage_link(prefix, lang_code, username, '利用者ページ') .. 'は' .. project_project_link(prefix, lang_code, 'ja') .. 'にあります。',
['ko'] = '이 사용자는 ' .. project_project_link(prefix, lang_code, 'ko') .. '에 ' .. project_userpage_link(prefix, lang_code, username, '사용자 문서') .. '가 있습니다. ',
['nl'] = 'Deze gebruiker heeft ' .. project_userpage_link(prefix, lang_code, username, 'een pagina') .. ' op ' .. project_project_link(prefix, lang_code, 'nl') .. '.',
['pa'] = 'ਇਸ ਵਰਤੋਂਕਾਰ ਦਾ ' .. project_project_link(prefix, lang_code, 'pa') .. ' ਉੱਤੇ ' .. project_userpage_link(prefix, lang_code, username, 'ਵਰਤੋਂਕਾਰ ਸਫ਼ਾ') .. ' ਹੈ।',
['pl'] = mw.language.getContentLanguage():gender(gender, 'Ten użytkownik', 'Ta użytkowniczka', 'Ta osoba') .. ' posiada własną ' .. project_userpage_link(prefix, lang_code, username, 'stronę') .. ' na ' .. project_project_link(prefix, lang_code, 'pl') .. '.',
['ta'] = 'இந்தப் பயனருக்கு ' .. project_project_link(prefix, lang_code, 'ta') .. ' ' .. project_userpage_link(prefix, lang_code, username, 'பக்கம் உள்ளது') .. '.',
['tr'] = 'Bu kullanıcının ' .. project_project_link(prefix, lang_code, 'tr') .. "'da " .. project_userpage_link(prefix, lang_code, username, 'bir sayfası') .. ' var.',
['uk'] = mw.language.getContentLanguage():gender(gender, 'Цей користувач', 'Ця користувачка') .. ' має ' .. project_userpage_link(prefix, lang_code, username, 'сторінку') .. ' у ' .. project_project_link(prefix, lang_code, 'uk') .. '.',
['vec'] = 'Sta utensa cuà ' .. project_userpage_link(prefix, lang_code, username, 'ła ga na pàzena') .. ' so ' .. project_project_link(prefix, lang_code, 'vec') .. '.'
}
local lang1 = lang_code
if lang1 == 'simple' or not lang_code or not args[lang1] then
lang1 = 'en'
end
local lang2 = display_lang or mw.getCurrentFrame():preprocess("{{Int:Lang}}")
if lang2 == 'simple' or not args[lang2] then
lang2 = 'en'
end
if lang1 == lang2 or not project_has_lang(prefix) then
return '<p lang="' .. lang2 .. '">' .. args[lang2] .. '</p>'
else
return '<p lang="' .. lang1 .. '">' .. args[lang1] .. '</p>\n----\n<p lang="' .. lang2 .. '">' .. args[lang2] .. '</p>'
end
end
function project_image(prefix)
local filename
local name = project_name(prefix)
if name == 'Wikimedia MetaWiki' then
filename = 'Wikimedia Community Logo.svg'
elseif name == 'Wikimedia Commons' then
filename = 'Commons-logo.svg'
elseif name == 'Wikimedia Outreach' then
filename = 'Wikimedia-logo.svg'
elseif name == 'Wikitech' then
filename = 'Wikitech-2021-blue-icon.svg'
elseif name == 'MediaWiki' then
filename = 'MediaWiki-2020-icon.svg'
elseif name == 'Wikiversity' then
filename = 'Wikiversity logo 2017.svg'
elseif name == 'Wikimania' or is_wikimania_number_prefix(prefix) then
filename = 'Wikimania.svg'
else
filename = mw.title.makeTitle('File', name .. '-logo.svg').text
end
return '[[File:' .. filename .. '|x40px]]'
end
function p._user_wikimedia_project(args)
local prefix = string.lower(args[1] or args.prefix or "metawiki")
local lang_code = args[2] or args.lang_code or args['lang code'] or 'en'
local username = args[3] or args.username or mw.title.getCurrentTitle().rootText
local gender = args.gender or username
local display_lang = args.display_lang or args['display lang']
local userbox_args = {
['border-c'] = '#bbbbbb',
['id'] = args.image or project_image(prefix),
['id-c'] = '#ffffff',
['info'] = project_text(prefix, lang_code, username, gender, display_lang),
['info-c'] = '#f6f6f6',
['usercategory'] = args.usercategory,
['usercategory2'] = args.usercategory2,
['usercategory3'] = args.usercategory3,
['nocat'] = args.nocat
}
return mw.getCurrentFrame():expandTemplate {
['title'] = 'Userbox sister project',
['args'] = userbox_args
}
--return userbox(userbox_args)
end
function p.user_wikimedia_project(frame)
return p._user_wikimedia_project(getArgs(frame))
end
return p