Moduł:Mscore
Wygląd
Służy do łączenia oraz zmiany szerokości obiektów <score>
score_version = '"2.18.2"'
page_namespace = 100
function error( txt )
return '<span style="color:red">Błąd użycia szablonu Sscore: ' .. txt .. '</span>'
end
function getnextpage( start, name )
local stdargs = { start='', next='0', score='', cont='', width='180', layout='', midi='', minwidth='', maxwidth='', resizable='0' }
local wynik = { }
local wynik2 = { }
local strona, kod, kod2, kod3, kod4, n
if string.match( name, '^Strona:') == 'Strona:' then
name = string.sub( name, 8 )
end
strona = mw.title.makeTitle( 'Strona', name )
kod = strona:getContent()
if kod == nil then
return nil
end
kod = string.match( kod, '{{[Ss]score%s*|.*cont *= *' .. start .. '.*}}' )
if kod == nil then
return ''
end
kod = string.sub( kod, 1, string.find( kod, '[^!]}}' ) )
for kod2 in string.gmatch( kod, '|[^|]*') do
kod3 = mw.text.trim( string.sub( kod2, 2 ) )
n = string.find( kod3, '=' )
kod4 = mw.text.trim( string.sub( kod3, 1, n-1 ) )
if stdargs[kod4] ~= nil then
stdargs[kod4] = mw.text.trim( string.sub( kod3, n+1 ) )
else
wynik[kod4] = mw.text.trim( string.sub( kod3, n+1 ) )
end
end
if stdargs['next'] ~= '0' then
wynik2 = getnextpage( start, stdargs['next'] )
if type( wynik2 ) ~= "table" then
return wynik2
end
end
for k, v in pairs( wynik ) do
if wynik2[k] ~= nil then
wynik[k] = wynik[k] .. ' ' .. wynik2[k]
end
wynik[k] = string.gsub( wynik[k], '{{!}}', '|' )
end
return wynik
end
function scal( frame, parsedargs )
local stdargs = { start='', next='0', score='', cont='', width='180', layout='', debug='0', midi='', minwidth='', maxwidth='', resizable='0' }
local args = frame:getParent().args
if parsedargs ~= nil then
args = parsedargs
stdargs['resizable'] = '1'
end
local kod_score = ""
local warning = ''
local argn = { }
local title = mw.title.getCurrentTitle()
local paper_size = "a2"
for k, v in pairs( args ) do
if type( k ) == "number" then
return error('nienazwany parametr; prawdopodobnie użyto | zamiast {{!}}')
elseif type( k ) == "string" and stdargs[k] ~= nil then
stdargs[k] = v
end
end
if stdargs['score'] == '' then
return error('brak kodu dla score')
end
if stdargs['start'] ~= '' and stdargs['next'] == '0' then
warning = warning .. error('brak wskazania kolejnej strony') .. '<br>'
end
if stdargs['start'] ~= '' and stdargs['cont'] ~= '' then
warning = warning .. error('pierwsza strona nie może być jednocześnie kolejną') .. '<br>'
end
if title.namespace ~= page_namespace and stdargs['cont'] ~= '' then
return warning
end
if title.namespace ~= page_namespace and stdargs['start'] ~= '' and stdargs['next'] ~= '0' then
argn = getnextpage( stdargs['start'], stdargs['next'] )
if argn == nil then
return error( 'brak strony wskazanej jako kolejna' )
elseif type( argn ) == "string" and argn == '' then
return error( 'brak szablonu kontynuacji na stronie kontynuacji' )
elseif type( argn ) ~= "table" then
return error( 'niezidentyfikowany błąd' )
end
end
for k, v in pairs( args ) do
if type( k ) == "string" and stdargs[k] == nil then
kod_score = kod_score .. "\n" .. k .. ' = '
if string.sub( k, 1, 1 ) == 'l' then
kod_score = kod_score .. "\\lyricmode "
end
kod_score = kod_score .. "{ " .. v;
if argn[k] ~= nil then
kod_score = kod_score .. ' ' .. argn[k]
end
kod_score = kod_score .. " }\n"
end
end
-- ograniczenie szerokości w przestrzeni Strona
if title.namespace == page_namespace and tonumber(stdargs['width']) > 140 and stdargs['resizable'] ~= '1' then
stdargs['width'] = '140'
end
-- optimize paper size: a2 / a3 / a4 ; width in milimeters
if tonumber(stdargs['width']) > 400 then
stdargs['width'] = '400'
elseif tonumber(stdargs['width']) < 190 then
paper_size = "a4"
elseif tonumber(stdargs['width']) < 280 then
paper_size = "a3"
end
-- set-paper-size does not work in safe mode, fittig to default
if tonumber(stdargs['width']) > 200 then
stdargs['width'] = '200'
end
kod_score = kod_score .. "\n\\paper { #(set-paper-size \"" .. paper_size .. "\")\n oddHeaderMarkup = \"\" evenHeaderMarkup = \"\" }\n\\header { tagline = ##f }\n\\version " .. score_version
kod_score = kod_score .. "\n\\score {\n\\midi { " .. stdargs['midi'] .. " }\n\\layout { line-width = #" .. stdargs['width'] .. "\n" .. stdargs['layout'] .. "}\n" .. stdargs['score'] .. " }"
if stdargs['debug'] == '1' then
warning = warning .. "\n<code><nowiki>" .. kod_score .. "</nowiki></code>\n"
end
return warning .. frame:extensionTag( 'score', kod_score, { raw = "1", midi = "1", vorbis = "1" } )
end
local p = {}
function p.genscore( frame, args )
return scal( frame, args )
end
return p