Mòdul:Statement+/prova
Aparença
Podeu crear la pàgina d'ús per documentar aquest mòdul Lua. |
local p = {}
local SA = require "Module:SimpleArgs"
local SD = require "Module:SimpleDebug"
local dir = require('Module:Dir')
local mRandom = require('Module:Random')
local lang = mw.language.getContentLanguage().code
local dirh = ''
if dir.isRTL(lang) then
dirh = 'rtl'
else
dirh = 'ltr'
end
function block (val, vv, bgcolor, showTables)
if (val == nil) and (val == '') then
return ''
else
local s = mw.html.create("table")
function forvar (ap, v)
function begintd (td)
if bgcolor == nil then
bgcolor = 'white'
end
td
:css ('vertical-align','top')
:css ('padding-left','0.5em')
:css ('background', bgcolor)
end
local tr = s:newline():tag('tr')
local td1 = tr:newline():tag('td')
:css ('background', 'white')
:css ('width', '2em')
local td2 = tr:newline():tag('td')
begintd (td2)
td2:css ('width', '12em')
if ap ~= nil then
td2:wikitext (ap)
end
local td3 = tr:newline():tag('td')
begintd (td3)
td3:wikitext (v)
end
function forvar2 (v)
if v ~= (nil or '') then
forvar (nil, v)
end
end
s:attr ('direction', dirh)
s:css ('border-collapse', 'collapse')
s:css ('border-spacing', 0)
s:css ('width', '100%')
if showTables then
s:css('border-style', 'solid')
s:css('border-width', '2px')
s:css('border-color', 'orange')
end
forvar (val, vv[1])
forvar2 (vv[2])
forvar2 (vv[3])
return tostring(s)
end
end --block
function p.blockf (frame)
local args,NArgs = SA.GetArgs (frame)
val = SA.Str_Par (args,'p')
if (val ~= nil) and (val ~= '') then
local showTables = SA.Bool_Par (args,'showTables')
return block (val, {SA.Str_Par(args,'v1'), SA.Str_Par(args,'v2'), SA.Str_Par(args,'v3')}, SA.Str_Par(args,'bgcolor'), showTables)
end
end --blockf
function p.block (frame)
local args,NArgs = SA.GetArgs (frame)
val = SA.Str_Par (args,1)
v1 = SA.Str_Par (args,2)
v1 = SA.Str_Par (args,3)
v1 = SA.Str_Par (args,4)
if (val ~= nil) and (val ~= '') then
local showTables = SA.Bool_Par (args,'showTables')
return block (val, {SA.Str_Par(args,'v1'), SA.Str_Par(args,'v2'), SA.Str_Par(args,'v3')}, SA.Str_Par(args,'bgcolor'), showTables)
end
end --block
function p.gblock (args, vn, first, rn, showTables)
local s = ''
local p, bgcolor
local v = {nil, nil, nil}
if first == 'q' then
for qn = 1, 8 do
local par = {}
if vn == 1 then
par = {'V1.q'..qn..'.', 'V1q'..qn, 'v1.q'..qn..'.', 'v1q'..qn, 'q'..qn..'.', 'q'..qn, }
local kk = ''
if qn > 1 then
kk = qn
end
table.insert (par, 'q'..kk)
else
par = {'V'..vn..'.q'..qn..'.', 'V'..vn..'q'..qn, 'v'..vn..'.q'..qn..'.', 'v'..vn..'q'..qn}
local kk = ''
if qn > 1 then
kk = qn
end
table.insert (par, 'V'..vn..'.q'..kk)
end
local par2 = {}
for j, kk in ipairs(par) do
table.insert (par2, kk..'p')
end
p = SA.Str_Par (args, par2)
if (p ~= nil) and (p ~= '') then
for z = 1, 3 do
local par2 = {}
for j, qn in ipairs(par) do
local S = ''
if (j < #par) or (z > 1) then
S = 'v'..z
else
S = 'v'
end
table.insert (par2, qn..S)
end
v[z] = SA.Str_Par (args, par2)
if v[z] == nil then
break
end
end
bgcolor = 'white'
s = s..block (p, v, bgcolor, showTables)
else
break
end
end
else
for pn = 1, 5 do
local par = {}
if vn == 1 then
par = {'V1.r'..rn..'.p'..pn, 'V1r'..rn..'p'..pn, 'v1.r'..rn..'.p'..pn, 'v1r'..rn..'p'..pn, 'r'..rn..'.p'..pn, 'r'..rn..'p'..pn, }
--[[
rn = 1
pn=1 r1.p1={{{ V1.r1.p1 | {{{ V1r1p1 | {{{ v1.r1.p1 | {{{ v1r1p1 | {{{ r1.p1 | {{{ r1p1 -- rp
pn=2 r1.p2={{{ V1.r1.p2 | {{{ V1r1p2 | {{{ v1.r1.p2 | {{{ v1r1p2 | {{{ r1.p2 | {{{ r1p2 -- rp2
rn = 2
pn=1 r2.p1={{{ V1.r2.p1 | {{{ V1r2p1 | {{{ v1.r2.p1 | {{{ v1r2p1 | {{{ r2.p1 | {{{ r2p1 -- r2p
pn=2 r2.p2={{{ V1.r2.p2 | {{{ V1r2p2 | {{{ v1.r2.p2 | {{{ v1r2p2 | {{{ r2.p2 | {{{ r2p2
rn = 3
pn=1 r2.p1={{{ V1.r3.p1 | {{{ V1r3p1 | {{{ v1.r3.p1 | {{{ v1r3p1 | {{{ r3.p1 | {{{ r3p1 -- r3p
pn=2 r2.p2={{{ V1.r3.p2 | {{{ V1r3p2 | {{{ v1.r3.p2 | {{{ v1r3p2 | {{{ r3.p2 | {{{ r3p2
--]]
if pn == 1 then
if rn == 1 then
table.insert (par, 'rp')
else
table.insert (par, 'r'..rn..'p')
end
else
if rn == 1 then
table.insert (par, 'rp'..pn)
end
end
else
par = {'V'..vn..'.r'..rn..'.p'..pn, 'V'..vn..'r'..rn..'p'..pn, 'v'..vn..'.r'..rn..'.p'..pn, 'v'..vn..'r'..rn..'p'..pn,}
--[[
rn = 1
pn=1 r1.p1={{{ V2.r1.p1 | {{{ V2r1p1 | {{{ v2.r1.p1 | {{{ v2r1p1 -- V2.rp |
pn=2 r1.p2={{{ V2.r1.p2 | {{{ V2r1p2 | {{{ v2.r1.p2 | {{{ v2r1p2 -- V2.rp2
rn = 2
pn=1 r2.p1={{{ V2.r2.p1 | {{{ V2r2p1 | {{{ v2.r2.p1 | {{{ v2r2p1 -- V2.r2p
pn=2 r2.p2={{{ V2.r2.p2 | {{{ V2r2p2 | {{{ v2.r2.p2 | {{{ v2r2p2 -- V2.r2p2
--]]
local temp = 'V2.'
if pn == 1 then
if rn == 1 then
table.insert (par, temp..'rp')
else
table.insert (par, temp..'r'..rn..'p')
end
else
if rn == 1 then
table.insert (par, temp..'rp'..pn)
else
table.insert (par, temp..'r'..rn..'p'..pn)
end
end
end
pval = SA.Str_Par (args, par)
if (pval ~= nil) and (pval ~= '') then
for z = 1, 3 do
if vn == 1 then
par = {'V1.r'..rn..'.p'..pn..'.v'..z, 'V1r'..rn..'p'..pn..'v'..z, 'v1.r'..rn..'.p'..pn..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pn==1 r2.p1.v2={{{ V1.r2.p1.v2 | {{{ V1r2p1v2 | {{{ v1.r2.p1.v2 | {{{ v1r2p1v2 | {{{ r2.p1.v2 | {{{ r2p1v2 -- r2v2
pn==2 r2.p2.v2={{{ V1.r2.p2.v2 | {{{ V1r2p2v2 | {{{ v1.r2.p2.v2 | {{{ v1r2p2v2 | {{{ r2.p2.v2 | {{{ r2p2v2
--]]
if rn == 1 then
if z == 1 then
if pn == 1 then
table.insert (par, 'r1v1')
table.insert (par, 'rv')
else
table.insert (par, 'rp'..pn..'v1')
table.insert (par, 'rp'..pn..'v')
end
else
if pn == 1 then
table.insert (par, 'r1v'..z)
table.insert (par, 'rv'..z)
else
table.insert (par, 'rp'..pn..'v'..z)
end
end
else
if z == 1 then
if pn == 1 then
table.insert (par, 'r'..rn..'v1')
table.insert (par, 'r'..rn..'v')
else
table.insert (par, 'r'..rn..'p'..pn..'v')
end
else
if pn == 1 then
table.insert (par, 'r'..rn..'v'..z)
end
end
end
else
par = {'V'..vn..'r'..rn..'.p'..pn..'.v'..z, 'V'..vn..'r'..rn..'p'..pn..'v'..z, 'v'..vn..'r'..rn..'.p'..pn..'.v'..z, 'v..vn..r'..rn..'p'..pn..'v'..z,}
--[[
z = 1
pn=1 r1.p1.v1={{{ V2.r1.p1.v1 | {{{ V2r1p1v1 | {{{ v2.r1.p1.v1 | {{{ v2r1p1v1 -- V2.rv |
pn=2 r1.p2.v1={{{ V2.r1.p2.v1 | {{{ V2r1p2v1 | {{{ v2.r1.p2.v1 | {{{ v2r1p2v1 -- V2.rp2v
pn=3 r1.p3.v1={{{ V2.r1.p3.v1 | {{{ V2r1p3v1 | {{{ v2.r1.p3.v1 | {{{ v2r1p3v1 -- V2.rp3v
z = 2..
pn=1 r1.p1.v2={{{ V2.r1.p1.v2 | {{{ V2r1p1v2 | {{{ v2.r1.p1.v2 | {{{ v2r1p1v2 -- V2.rv2
pn=2 r1.p2.v2={{{ V2.r1.p2.v2 | {{{ V2r1p2v2 | {{{ v2.r1.p2.v2 | {{{ v2r1p2v2 -- V2.rp2v2
pn=3 r1.p3.v2={{{ V2.r1.p3.v2 | {{{ V2r1p3v2 | {{{ v2.r1.p3.v2 | {{{ v2r1p3v2 -- V2.rp3v2
--]]
if pn == 1 then
table.insert (par, 'V'..vn..'rv')
else
table.insert (par, 'V'..vn..'rp'..pn..'v')
end
if z > 1 then
par[#par] = par[#par]..z
end
end
SD.vtos (par)
v[z] = SA.Str_Par (args, par)
bgcolor = '#f7f8f9'
if v[z] == nil then
break
end
end
s = s..block (pval, v, bgcolor, showTables)
end
end
end
return s
end --gblock
function p.gblockf (frame)
local args,NArgs = SA.GetArgs (frame)
first = SA.Str_Par (args,1)
num = SA.Int_Par (args,2)
showTables = SA.Bool_Par (args,3)
return p.gblock (args, 1, first, num, showTables)
end
function p.forValue (args, V, i, showTables)
local RankLabel = V..'.rank'
local RankLabels = {}
if i == 1 then
RankLabels = {RankLabel, 'V1.rank', 'V1.Rank', 'rank', 'Rank'}
else
RankLabels = {RankLabel, 'V'..i..'.rank', 'V'..i..'.Rank', 'rank'..i, 'Rank'..i}
end
local rank = SA.Str_Par (args, RankLabels, '')
if rank == '' then
rank = 0
elseif (rank ~= 'p') and (rank ~= 'n') then
SA.CheckSIsInt (rank, RankLabel, -1, 1)
rank = tonumber(rank)
end
function rankF()
local File = ''
local msg = ''
if (rank == 1) or (rank == 'p') then
file = 'Preferred'
msg = 'wikibase-statementview-rank-preferred'
elseif (rank == 0) or (rank == 'n') then
file = 'Normal'
msg = 'wikibase-statementview-rank-normal'
else
file = 'Deprecated'
msg = 'wikibase-statementview-rank-deprecated'
end
return '[[File:'..file..' rank.svg|8px|'..mw.message.new(msg):plain()..'|link=]]'
end --rankF
function WhenR (adiv, n)
adiv:newline():tag('table') --separator
:css ('width', '100%')
:css ('height', '7px')
:css ('background', 'white')
:css ('border-collapse', 'collapse')
:css ('border-spacing', 0)
adiv:wikitext (p.gblock (args, i, 'r', n, showTables))
end
local random = mRandom.number({1000000})
local s = mw.html.create("table")
local dirh = ''
if dir.isRTL(lang) then
dirh = 'rtl'
else
dirh = 'ltr'
end
s:attr ('direction', dirh)
s:css ('width', '100%')
s:css ('border-collapse', 'collapse')
s:css ('border-spacing', 0)
if showTables then
s:css ('border-style', 'solid')
s:css ('border-width', '2px')
s:css ('border-color', 'blue')
end
local tr1 = s:newline():tag('tr')
local td1 = tr1:newline():tag('td')
:css ('vertical-align', 'top')
:css ('padding-left', '2px')
:css ('padding-top', '0.45em')
:css ('background', 'white')
:css ('width', '2em')
:wikitext (rankF())
local td2 = tr1:newline():tag('td')
:css ('vertical-align', 'top')
:css ('padding-top', '0.7em')
:css ('background', 'white')
:attr('colspan', 2)
if (V == nil) or (V == '') then
td2:wikitext (mw.message.new('wikibase-snakview-snaktypeselector-novalue'):plain())
else
td2:wikitext (V)
end
local td3 = tr1:newline():tag('td')
:css ('vertical-align', 'top')
:css ('padding-top', '0.7em')
:css ('padding-left', '0.75em')
:css ('background', 'white')
:css ('width', '25%')
:wikitext ('[[File:Arbcom ru editing.svg|frameless|14px|link=]]'..mw.message.new('editlink'):plain())
:css ('color', 'silver')
local tr2 = s:newline():tag('tr')
local td4 = tr2:newline():tag('td')
:css ('background', 'white')
:attr('colspan', 4)
:wikitext (p.gblock (args, i, 'q', 0, showTables))
local n = 0
local vx = {nil, nil, nil}
for j = 3, 1, -1 do
local vrpLabels = {}
if i == 1 then
vrpLabels = {'V1.r'..j..'.p1', 'V1r'..j..'p1', 'v1.r'..j..'.p1', 'v1r'..j..'p1', 'r'..j..'.p1', 'r'..j..'p1'}
if j == 1 then
table.insert (vrpLabels, 'rp')
else
table.insert (vrpLabels, 'rp'..j)
end
else
vrpLabels = {'V'..i..'.r'..j..'.p1', 'V'..i..'r'..j..'p1', 'v'..i..'.r'..j..'.p1', 'v'..i..'r'..j..'p1', }
if j == 1 then
table.insert (vrpLabels, 'V'..i..'.rp')
else
table.insert (vrpLabels, 'V'..i..'.r'..j..'p')
end
end
vx[j] = SA.Str_Par (args, vrpLabels)
if ((vx[j] ~= nil) or (vx[j] == '')) and (n == 0) then
n = j
end
end
local tr3 = s:newline():tag('tr')
local td5 = tr3:newline():tag('td')
:css ('vertical-align', 'top')
:css ('padding-top', '1em')
:css ('background', 'white')
:css ('width', '2em')
local td6 = tr3:newline():tag('td')
:css ('vertical-align', 'top')
:css ('padding-top', '1em')
:css ('background', 'white')
:attr('colspan', 3)
local div1 = td6:newline():tag('div')
:addClass ('mw-customtoggle-'..random)
:css ('color', '#0c45ab')
:wikitext ('▼ '..n..' '..mw.message.new('Wikibase-diffview-reference'):plain())
local tr4 = s:newline():tag('tr')
local td7 = tr4:newline():tag('td')
:css ('background', 'white')
:attr('colspan', 4)
local div2 = td7:newline():tag('div')
if n > 0 then
local reference = args['reference']
if reference == 'close' then
reference = "mw-collapsible mw-collapsed"
else
reference = "mw-collapsible innercollapse"
end
div2:addClass (reference)
end
div2
:attr ('id', 'mw-customcollapsible-'..random)
:css ('padding', '0px')
:css ('border', '0px')
local div3 = div2:newline():tag('div')
:addClass ("mw-collapsible-content")
:css ('text-align', 'left')
if (vx[1] ~= nil) and (vx[1] ~= '') then
div3:wikitext (p.gblock (args, i, 'r', 1, showTables))
end
if (vx[2] ~= nil) and (vx[2] ~= '') then
WhenR (div3, 2)
end
if (vx[3] ~= nil) and (vx[3] ~= '') then
WhenR (div3, 3)
end
local tab2 = div3:newline():tag('table')
:css ('width', '100%')
:css ('border-collapse', 'collapse')
:css ('border-spacing', 0)
local tr4 = tab2:newline():tag('tr')
local td8 = tr4:newline():tag('td')
:css ('width', '75%')
local td9 = tr4:newline():tag('td')
:css ('vertical-align', 'top')
:css ('padding-top', '0.4em')
:css ('padding-bottom', '0.9em')
:css ('padding-left', '1.2em')
:css ('background', 'white')
:css ('width', '25%')
:css ('color', 'silver')
:wikitext ("'''+''' "..mw.message.new('wikibase-addreference'):plain())
return tostring(s)
end --forValue
function p.allF (frame)
local args,NArgs = SA.GetArgs (frame)
showTables = SA.Bool_Par (args, 'showTables')
return p.forValue (args, args['v1'], 1, showTables)
end
local NB = require ('Module:Navbar')
function p.main (frame)
local args,NArgs = SA.GetArgs (frame)
local showTables = SA.Bool_Par (args, 'showTables')
local navbar = SA.Bool_Par (args, 'navbar', true)
local width = SA.Str_Par (args, 'widht', '80%')
local indent = SA.Str_Par (args, 'indent', '0px')
local tururuts = {}
local prop = SA.Str_Par (args, {'p','P'}, mw.message.new('wikibase-entity-property'):plain())
local doc = SA.Str_Par (args, 'doc', '')
local color_doc = SA.Str_Par (args, 'color_doc', '#F5F5F5')
local width_doc = SA.Str_Par (args, 'width_doc', '20%')
local s = mw.html.create("table")
local bcolor = ''
if showTables then
bcolor = 'black'
else
bcolor = '#c7cbd0'
end
if navbar then
s:attr ('direction', dirh)
:css ('width', width)
:css ('margin-left', indent)
:css ('border-style', 'none')
:css ('border-collapse', 'collapse')
:css ('border-spacing', 0)
:css ('border-width', '0px')
:css ('border-color', bcolor)
local tr0 = s:newline():tag('tr')
tr0 :addClass('nv-view')
local td0 = tr0:newline():tag('tr')
td0 :wikitext('[[File:Commons-emblem-notice.svg|18px|link=Template:Statement+]]')
end
local borderw = ''
if showTables then
borderw = '2px'
else
borderw = '1px'
end
local t = mw.html.create("table")
t:attr ('direction', dirh)
:css ('width', width)
:css ('margin-left', indent)
:css ('border-style', 'solid')
:css ('border-collapse', 'collapse')
:css ('border-spacing', 0)
:css ('border-color', bcolor)
:css ('border-width', borderw)
local tr1 = t:newline():tag('tr')
local td1 = tr1:newline():tag('td')
td1 :css ('vertical-align', 'top')
:css ('padding-top', '0.8em')
:css ('padding-left', '1em')
:css ('background', '#E9EBEF')
:css ('width', '20%')
:attr('rowspan', 4)
:wikitext (prop)
local tdx = {}
local tdrx = {}
local tdrdx = {}
local ss = ''
--local v = args['v1']
v = SA.Str_Par (args, {'v1','V1','V','v'})
if v ~= nil then
tdx1 = td1:newline():tag('td')
tdx1 :css ('background', 'white')
:css ('padding-left', '0em')
:css ('padding-right', '0em')
:css ('padding-top', '0em')
:css ('padding-bottom', '0em')
:css ('width', '')
:attr('colspan', 2)
:wikitext (p.forValue (args, v, 1, showTables))
for i = 2, 9 do
--local vv = args['v'..i]
vv = SA.Str_Par (args, {'v'..i, 'V'..i})
if vv == nil then
break
else
tdx[i] = tdx1:newline():tag('table')
tdx[i]
:css ('width', '100%')
:css ('height', '1px')
:css ('background', '#E9EBEF')
:css ('border-collapse', 'collapse')
:css ('border-spacing', 0)
:attr('colspan', 2)
tdrx[i] = tdx[i]:newline():tag('tr')
tdrdx[i] = tdrx[i]:newline():tag('td')
tdx1:wikitext (p.forValue (args, vv, i, showTables))
end
end
end
if doc ~= '' then
local td3 = tr1:newline():tag('td')
td3 :css ('vertical-align', 'top')
:css ('padding-top', '0.8em')
:css ('padding-left', '1em')
:css ('padding-right', '1em')
:css ('background', color_doc)
:css ('width', width_doc)
:attr('rowspan', 2)
:css ('', '')
:wikitext (doc)
end
local tr4 = t:newline():tag('tr')
local td4 = tr4:newline():tag('td')
td4 :css ('padding-left', '1em')
:css ('background', '#E9EBEF')
:css ('width', '')
local td5 = tr4:newline():tag('td')
td5 :css ('vertical-align', 'top')
:css ('padding-left', '1em')
:css ('padding-top', '0.3em')
:css ('padding-bottom', '0.2em')
:css ('background', '#E9EBEF')
:css ('width', '20%')
:css ('color', 'silver')
:wikitext ("'''+'''"..' '..mw.message.new('wikibase-statementlistview-add'):plain())
local res = ''
if navbar then
res = tostring(s)..'\n\n'
else
res = ''
end
return res..tostring(t)
end --main
return p