Modul:Commonscat
Documentația acestui modul poate fi creată la Modul:Commonscat/doc
local getArgs = require('Modul:Arguments').getArgs
local wikidata = require('Modul:Wikidata')
local StringUtils = require('Modul:StringUtils')
local p = {}
local function makeInvokeFunc(funcName)
return function(frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
p._main = function(args)
local mainDiv = mw.html.create('div')
:addClass('noprint')
:css('clear', 'right')
:css('border', 'solid #aaa 1px')
:css('margin', '0 0 1em 1em')
:css('font-size', '90%')
:css('background', 'var(--background-color-interactive-subtle, #f8f9f9)')
:css('color', 'color:var(--color-base, #000)')
:css('width', '230px')
:css('padding', '2px')
:css('spacing', '2px')
:css('text-align', 'center')
:css('float', 'right')
mainDiv:tag('div')
:css('float', 'left')
:css('vertical-align', 'middle')
:wikitext('[[Fișier:Commons-logo.svg|30px|none|Commons]]')
local innerDiv = mainDiv:tag('div')
:css('margin-left', '35px')
:css('line-height', 'normal')
:css('vertical-align', 'middle')
local commonsCatName = args[1] or StringUtils.emptyToNil({wikidata.findOneValue('P373')}) or mw.title.getCurrentTitle().text
local displayCatName = args[2] or StringUtils.emptyToNil({wikidata.getLabel()}) or mw.title.getCurrentTitle().text
local commonsCatURL = mw.uri.fullUrl('commons:Category:' .. commonsCatName, { uselang = 'ro' })
local commonsCatSpan = mw.html.create('span'):addClass('plainlinks'):wikitext("'''[" .. tostring(commonsCatURL) .. " " .. displayCatName .. "]'''")
innerDiv:wikitext('[[Wikimedia Commons]] conține materiale multimedia legate de ' .. tostring(commonsCatSpan))
return tostring(mainDiv)
end
p.main = makeInvokeFunc('_main');
p._inline = function(args)
local commonsCatName = args[1] or StringUtils.emptyToNil({wikidata.findOneValue('P373')}) or mw.title.getCurrentTitle().text
local displayCatName = args[2] or StringUtils.emptyToNil({wikidata.getLabel()}) or mw.title.getCurrentTitle().text
local commonsCatURL = mw.uri.fullUrl('commons:Category:' .. commonsCatName, { uselang = 'ro' })
local commonsCatSpan = mw.html.create('span'):addClass('plainlinks'):wikitext("'''[" .. tostring(commonsCatURL) .. " " .. displayCatName .. "]'''")
return '[[File:Commons-logo.svg|16x16px]]' .. ' Materiale media legate de ' .. tostring(commonsCatSpan) .. ' la [[Wikimedia Commons]]'
end
p.inline = makeInvokeFunc('_inline');
return p