Modul:Quickbar2
Die Dokumentation für dieses Modul kann unter Modul:Quickbar2/doc erstellt werden
local check = require('Modul:Check2')
local wd = require('Modul:Wikidata2')
local locMap = require('Modul:Location map')
local cfgParams = mw.loadData('Modul:Quickbar2/Params')
-- Auswertung und Prüfung von übergebenen Parametern
local function getParameter ( Frame, Params, Parameter )
local argsParent = Frame:getParent().args
local argsFrame = Frame.args
for key,value in pairs ( argsParent ) do
argsParent[string.lower(key)] = value
end
for key,value in pairs ( argsFrame ) do
argsFrame[string.lower(key)] = value
end
return argsParent[Parameter] or argsFrame[Parameter] or Params[Parameter]
end
-- generiert Attibute für die Tabelle der Quickbar
local function theadAttr ( class, style )
local tableAttr = 'cellspacing="0" class="' .. class ..'"'
if (style ~= nil) and (style ~= '') then tableAttr = tableAttr .. ' style="' .. style .. '"' end
return tableAttr
end
local quickbar = {}
-- erzeugt einen Überschrifteneintrag in der Quickbar
function quickbar.theader ( colSpan, text, rowClass )
local class = rowClass or ''
local tr = mw.html.create ( 'tr' )
tr:addClass( class )
tr:tag('td')
:attr('colspan', colSpan )
:addClass('voy-qb-header' )
:wikitext(text)
return tostring ( tr )
end
function quickbar.trItemTH ( className, text1, text2, text3, text4 )
local tr = mw.html.create ( 'tr' )
tr:addClass('voy-qb-item ' .. className )
:tag('th')
:addClass('voy-qb-item-key')
:wikitext(text1)
if ( text2 ~= nil ) then tr:tag('td'):addClass('voy-qb-item-value1'):wikitext(text2) end
if ( text3 ~= nil and text3 ~= '' ) then tr:tag('td'):addClass('voy-qb-item-value2'):wikitext(text3) end
if ( text4 ~= nil and text4 ~= '' ) then tr:tag('td'):addClass('voy-qb-item-value3'):wikitext(text4) end
return tostring ( tr )
end
function quickbar.trItemTD ( className, text1, text2, text3, text4 )
local tr = mw.html.create ( 'tr' )
tr:addClass('qbItem ' .. className )
:tag('td')
:addClass('qbItem-key')
:wikitext(text1)
if ( text2 ~= nil ) then tr:tag('td'):addClass('voy-qb-item-value1'):wikitext(text2) end
if ( text3 ~= nil ) then tr:tag('td'):addClass('voy-qb-item-value2'):wikitext(text3) end
if ( text4 ~= nil ) then tr:tag('td'):addClass('voy-qb-item-value3'):wikitext(text4) end
return tostring ( tr )
end
function quickbar.trSingleTD ( className, text, colSpan, attributes )
if ( colSpan == nil ) then colSpan = '2' end
local attrTable = { ['colspan'] = colSpan };
if ( attributes ~= nil ) then
for k,v in pairs(attributes) do attrTable[k] = v end
end
local tr = mw.html.create ( 'tr' )
tr:addClass('voy-qb-item ' .. className )
:tag('td')
:attr(attrTable)
:addClass('voy-qb-item-value')
:wikitext(text)
return tostring ( tr )
end
function quickbar.trImage ( className, imageFile, colSpan )
if ( not colSpan ) then colSpan = 2 end
local tr = mw.html.create ( 'tr' )
tr:addClass('voy-qb-item ' .. className )
:tag('td')
:attr('colspan', colSpan)
:addClass('voy-qb-imagecell')
:tag('div')
:addClass('voy-qb-image')
:wikitext(imageFile)
return tostring ( tr )
end
function quickbar.trTwoImages ( className, className1, className2, imageFile1, imageFile2, colSpan )
if ( not colSpan ) then colSpan = 2 end
local td1 = mw.html.create ( 'td' )
td1:addClass( className1 )
:tag('div')
:addClass('voy-qb-image')
:wikitext(imageFile1)
local td2 = mw.html.create ( 'td' )
td2:addClass( className2 )
:tag('div')
:addClass('voy-qb-image')
:wikitext(imageFile2)
local tr = mw.html.create ( 'tr' )
tr:addClass('voy-qb-item ' .. className )
:tag('td')
:attr('colspan', colSpan)
:addClass('voy-qb-imagecell')
:tag('table')
:addClass('voy-qb-twoimages')
:tag('tr')
:node(td1)
:node(td2)
return tostring ( tr )
end
function quickbar.locmap ( colSpan, map, rowClass )
local class = rowClass or ''
local tr = mw.html.create ( 'tr' )
tr:addClass('voy-qb-locmap '..class)
:tag('td')
:attr('colspan', colSpan)
:wikitext(locMap.locationMap(map))
return tostring ( tr )
end
function quickbar.hr ( colSpan, rowClass )
local class = rowClass or ''
local hr = mw.html.create ( 'tr' )
hr:addClass('voy-qb-line '..class)
:tag('td')
:attr('colspan', colSpan)
:tag('hr')
return tostring ( hr )
end
-- Funktionen für Verwendung in Vorlagen
function quickbar.qb_table ( frame )
local args = frame:getParent().args
local errorStr = ''
local topBorder = getParameter ( frame, cfgParams["qb_table"], 'topBorder' )
local pos = getParameter ( frame, cfgParams["qb_table"], 'pos' )
local qbTableClass = getParameter ( frame, cfgParams["qb_table"], 'tableclass' )
local posPossible = { rechts = '', links = '', right = '', left = '', normal = '' }
if posPossible[pos] == nil then errorStr = check._error ('Falscher Wert für Parameter <em>pos</em>: <em>' .. pos .. '</em> im Tabellenkopf', 'Quickbar' ) end
local styles = args[1]
if (styles == nil) or (styles == '') then styles = frame.args[1] end
-- if (styles == nil) or (styles == '') then styles = '' end -- 300px in Stilvorlage
local classes = 'voy-qb ' .. qbTableClass
if pos == 'right' then classes = classes .. ' voy-qb-right' end
if pos == 'rechts' then classes = classes .. ' voy-qb-right' end
-- if pos == 'normal' then classes = classes .. ' voy-qb-right' end
if pos == 'left' then classes = classes .. ' voy-qb-left' end
if pos == 'links' then classes = classes .. ' voy-qb-left' end
if topBorder == 'yes' then classes = classes .. ' voy-qb-topborder' end
return errorStr .. check._testParams ( args, cfgParams["qb_table"], 'Quickbar2' ) .. theadAttr ( classes, styles )
end
function quickbar.qb_header ( frame )
local qbColspan = getParameter ( frame, cfgParams["qb_header"], 'colspan' )
local qbRowClass = getParameter ( frame, cfgParams["qb_header"], 'rowclass' )
local qbText = frame.args[1] or frame:getParent().args[1] or getParameter ( frame, cfgParams["qb_header"], 'text' )
return check._testParams ( frame:getParent().args, cfgParams["qb_header"], 'Quickbar2' ) .. quickbar.theader ( qbColspan, qbText, qbRowClass )
end
function quickbar.qb_item ( frame )
local qbHeading = getParameter ( frame, cfgParams["qb_item"], 'heading' )
local qbValue = getParameter ( frame, cfgParams["qb_item"], 'value' )
local qbValue2 = getParameter ( frame, cfgParams["qb_item"], 'value2' )
local qbValue3 = getParameter ( frame, cfgParams["qb_item"], 'value3' )
local qbRowClass = getParameter ( frame, cfgParams["qb_item"], 'rowclass' )
return check._testParams ( frame:getParent().args, cfgParams["qb_item"], 'Quickbar2' ) .. quickbar.trItemTH ( qbRowClass, qbHeading, qbValue, qbValue2, qbValue3 )
end
function quickbar.qb_image( frame )
local display = ''
local errorStr = ''
local qbHeading = getParameter ( frame, cfgParams["qb_image"], 'heading' )
local qbImage = getParameter ( frame, cfgParams["qb_image"], 'image' )
local qbColspan = getParameter ( frame, cfgParams["qb_image"], 'colspan' )
local qbWikidataProperty = getParameter ( frame, cfgParams["qb_image"], 'wikidataproperty' )
local qbWikidataFormat = getParameter ( frame, cfgParams["qb_image"], 'wikidataformat' )
local qbRowClass = getParameter ( frame, cfgParams["qb_image"], 'rowclass' )
if ( qbImage == '' ) then
qbImage = wd.getProperty (
wd.getBestStatement (
wd.EntityId(),
qbWikidataProperty
).statement,
qbWikidataFormat
)
end
if ( qbHeading ~= '' ) then display = display .. quickbar.theader ( qbColspan, qbHeading, qbRowClass ) end
display = display .. errorStr .. check._testParams ( frame:getParent().args, cfgParams["qb_image"], 'Quickbar2' ) .. quickbar.trImage ( qbRowClass, qbImage, qbColspan )
return display
end
function quickbar.qb_line ( frame )
local qbColspan = getParameter ( frame, cfgParams["qb_line"], 'colspan' )
local qbRowClass = getParameter ( frame, cfgParams["qb_line"], 'rowclass' )
local errorStr = ''
if mw.ustring.match ( qbColspan, '^%d*$' ) == nil then
errorStr = check._error ('Falscher Wert für Parameter <em>colspan</em>: <em>'
.. qbColspan
.. '</em> bei einer Zwischenlinie. Bitte eine ganze Zahl eingeben', 'Quickbar' )
qbColspan = cfgParams['qb_line']['colspan']
end
return errorStr .. check._testParams ( frame:getParent().args, cfgParams["qb_line"], 'Quickbar2' ) .. quickbar.hr ( qbColspan, qbRowClass )
end
function quickbar.createEntry ( localItem, wdItem, wdID, wdProperty, cssClass, itemName, noWDCat, diffCat, equalCat )
local display = ''
local displayItem
if ( localItem ~= '' ) then
display = display .. quickbar.trItemTH ( cssClass, itemName, localItem )
if ( localItem ~= wdItem and wdItem ~= '' and diffCat ~= nil ) then
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel1', 'andere(r) ' .. itemName .. ' auf Wikidata [[File:View-so edit simple.svg|15px|link=' .. wd.getWikidataLink(wdID) .. '|class=noviewer|' .. itemName .. ' in Wikidata aktualisieren]] <div data-qb-item="'.. cssClass .. '" class="qb-edit-delete">[[File:Symbol delete vote.svg|15px|class=noviewer|Eintrag aus der Quickbar entfernen und Wikidata benutzen]]</div>' )
display = display .. '[[Kategorie:' .. diffCat .. ']]'
end
if ( localItem == wdItem and localItem ~= '' ) then
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel1', 'identische Angabe für ' .. itemName .. ' auf Wikidata. <div data-qb-item="'.. cssClass .. '" class="qb-edit-delete">[[File:Symbol delete vote.svg|15px|class=noviewer|Eintrag aus der Quickbar entfernen und Wikidata benutzen]]</div>' )
if ( equalCat ~= nil ) then
display = display .. '[[Kategorie:' .. equalCat .. ']]'
end
end
displayItem = true
elseif ( wdItem ~= '' ) then
display = display .. '[[Kategorie:Seiten, die die Wikidata-Eigenschaft ' .. wdProperty .. ' benutzen]]'
display = display .. quickbar.trItemTH ( cssClass, itemName, '<span class="wikidata-content">' .. wdItem .. '</span>' )
displayItem = true
else
display = display .. quickbar.trItemTH ( 'voy-qb-empty ' .. cssClass, itemName, '<em>unbekannt</em>' )
end
if ( wdItem == '' ) then
if ( wdID ~= '' ) then
display = display .. quickbar.trSingleTD ( 'qb-wd-comment', 'kein(e) ' .. itemName .. ' auf Wikidata: [[File:View-so edit simple.svg|15px|link=' .. wd.getWikidataLink(wdID) .. '|class=noviewer|' .. itemName .. ' nachtragen]]' )
if ( noWDCat ~= nil ) then
display = display .. '[[Kategorie:' .. noWDCat .. ']]'
end
else
display = display .. quickbar.trSingleTD ( 'qb-wd-comment', 'kein Objekt auf Wikidata: ([https://www.wikidata.org/w/index.php?search=&title=Special%3ASearch&go=Seite Suchen und Anlegen])' )
end
end
return display
end
function quickbar.createEntryImage ( localItem, wdItem, wdID, wdProperty, cssClass, itemName, noWDCat, noItemCat )
local display = ''
local errorStr = ''
if ( localItem ~= '' ) then
display = display .. quickbar.trImage ( 'voy-qb-image ' .. cssClass, localItem )
elseif ( wdItem ~= '' ) then
display = display .. '[[Kategorie:Seiten, die die Wikidata-Eigenschaft ' .. wdProperty .. ' benutzen]]'
local fileCheck = check._testFile ( wdItem, 'Quickbar2' )
if ( fileCheck == '' ) then
display = display .. quickbar.trImage ( 'voy-qb-image ' .. cssClass, mw.ustring.match ( wdItem, '%[%[.-%]%]' ) )
else
errorStr = errorStr .. fileCheck
end
else
errorStr = errorStr .. '[[Kategorie:' .. noItemCat .. ']]'
end
if ( wdItem == '' ) then
if ( wdID ~= '' ) then
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel1', 'kein(e) ' .. itemName .. ' auf Wikidata: [[File:View-so edit simple.svg|15px|link=' .. wd.getWikidataLink(wdID) .. '|class=noviewer|' .. itemName .. ' nachtragen]]' )
if ( noWDCat ~= nil ) then
errorStr = errorStr .. '[[Kategorie:' .. noWDCat .. ']]'
end
else
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel1', 'kein Objekt auf Wikidata: ([https://www.wikidata.org/w/index.php?search=&title=Special%3ASearch&go=Seite Suchen und Anlegen])' )
end
end
return errorStr .. display
end
function quickbar.createEntryTwoImages (
localItem1, wdItem1, wdID1, wdProperty1, cssClass1, itemName1, noWDCat1, noItemCat1,
localItem2, wdItem2, wdID2, wdProperty2, cssClass2, itemName2, noWDCat2, noItemCat2,
cssClass
)
local display = ''
local display1 = ''
local display2 = ''
local errorStr = ''
local fileCheck1 = ''
local fileCheck2 = ''
local rowClass = cssClass or ''
if ( localItem1 ~= '' ) then
display1 = localItem1
elseif ( wdItem1 ~= '' ) then
display = display .. '[[Kategorie:Seiten, die die Wikidata-Eigenschaft ' .. wdProperty1 .. ' benutzen]]'
fileCheck1 = check._testFile ( wdItem1, 'Quickbar2' )
if ( fileCheck1 == '' ) then
display1 = mw.ustring.match ( wdItem1, '%[%[.-%]%]' )
else
errorStr = errorStr .. fileCheck1
end
else
errorStr = errorStr .. '[[Kategorie:' .. noItemCat1 .. ']]'
end
if ( localItem2 ~= '' ) then
display2 = localItem2
elseif ( wdItem2 ~= '' ) then
display = display .. '[[Kategorie:Seiten, die die Wikidata-Eigenschaft ' .. wdProperty2 .. ' benutzen]]'
fileCheck2 = check._testFile ( wdItem2, 'Quickbar2' )
if ( fileCheck2 == '' ) then
display2 = mw.ustring.match ( wdItem2, '%[%[.-%]%]' )
else
errorStr = errorStr .. fileCheck2
end
else
errorStr = errorStr .. '[[Kategorie:' .. noItemCat2 .. ']]'
end
if ( display1 ~= '' and display2 ~= '' ) then
display = display .. quickbar.trTwoImages ( 'voy-qb-image ' .. rowClass, cssClass1, cssClass2, display1, display2, 2 )
elseif ( display1 ~= '' and display2 == '' ) then
display = display .. quickbar.trImage ( 'voy-qb-image ' .. cssClass1, display1 )
elseif ( display1 == '' and display2 ~= '' ) then
display = display .. quickbar.trImage ( 'voy-qb-image ' .. cssClass2, display2 )
else
end
if ( wdItem1 == '' ) then
if ( wdID1 ~= '' ) then
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel1', 'kein(e) ' .. itemName1 .. ' auf Wikidata: [[File:View-so edit simple.svg|15px|link=wikidata:' .. wdID1 .. '|class=noviewer|' .. itemName1 .. ' nachtragen]]' )
if ( noWDCat1 ~= nil ) then
errorStr = errorStr .. '[[Kategorie:' .. noWDCat1 .. ']]'
end
else
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel1', 'kein Objekt auf Wikidata: ([https://www.wikidata.org/w/index.php?search=&title=Special%3ASearch&go=Seite Suchen und Anlegen])' )
end
end
if ( wdItem2 == '' ) then
if ( wdID2 ~= '' ) then
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel1', 'kein(e) ' .. itemName2 .. ' auf Wikidata: [[File:View-so edit simple.svg|15px|link=wikidata:' .. wdID2 .. '|class=noviewer|' .. itemName2 .. ' nachtragen]]' )
if ( noWDCat2 ~= nil ) then
errorStr = errorStr .. '[[Kategorie:' .. noWDCat2 .. ']]'
end
else
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel1', 'kein Objekt auf Wikidata: ([https://www.wikidata.org/w/index.php?search=&title=Special%3ASearch&go=Seite Suchen und Anlegen])' )
end
end
return errorStr .. display
end
function quickbar.createEntryQuantity ( localItem, wdItem, wdID, wdProperty, wdFormat, cssClass, itemName, noWDCat, diffCat, equalCat )
local display = ''
local errorStr = ''
local property = ''
local displayItem
if ( localItem ~= '' ) then
if ( cssClass == 'voy-qb-altitude' ) then
display = display .. quickbar.trItemTH ( cssClass, itemName, localItem:gsub ( ' ', '' ):gsub ( 'm', '' ) .. ' m' )
else
display = display .. quickbar.trItemTH ( cssClass, itemName, localItem )
end
localItem = localItem:gsub ( '%.', '' ):gsub ( ',', '' ):gsub ( ' ', '' ):gsub ( 'ca', '' ):gsub ( ' ', '' ):gsub ( '<span class="voy-small">.*</span>', '' ):gsub ( '%(.*%)', '' ):gsub ( 'km²', '' ):gsub ( 'km2', '' ):gsub ( 'km<sup>2</sup>', '' ):gsub ( 'm', '' )
if ( localItem ~= wdItem and wdItem ~= '' and diffCat ~= nil ) then
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel2', 'anderer Wert für ' .. itemName .. ' auf Wikidata: ' .. wdItem .. ' [[File:View-so edit simple.svg|15px|link=' .. wd.getWikidataLink(wdID, wdProperty) .. '|class=noviewer|' .. itemName .. ' in Wikidata aktualisieren]] <span data-qb-item="'.. cssClass .. '" class="qb-edit-delete">[[File:Symbol delete vote.svg|15px|class=noviewer|Eintrag aus der Quickbar entfernen und Wikidata benutzen]]</span>', '2', { ['title'] = 'Wikivoyage: ' .. localItem .. '- Wikidata: ' .. wdItem } )
display = display .. '[[Kategorie:' .. diffCat .. ']]'
end
if ( localItem == wdItem and localItem ~= '' ) then
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel2', 'identische Angabe für ' .. itemName .. ' auf Wikidata. <div data-qb-item="'.. cssClass .. '" class="qb-edit-delete">[[File:Symbol delete vote.svg|15px|class=noviewer|Eintrag aus der Quickbar entfernen und Wikidata benutzen]]</div>' )
if ( equalCat ~= nil ) then
display = display .. '[[Kategorie:' .. equalCat .. ']]'
end
end
displayItem = true
elseif ( wdItem ~= '' ) then
display = display .. '[[Kategorie:Seiten, die die Wikidata-Eigenschaft ' .. wdProperty .. ' benutzen]]'
property = wd.getProperty ( wd.getBestStatement( wdID, wdProperty ).statement, wdFormat )
property = property:gsub('<div class="voy-small">%(%)</div>','')
display = display .. quickbar.trItemTH ( cssClass, itemName, '<div class="wikidata-content">' .. property .. '</div>' )
displayItem = true
else
display = display .. quickbar.trItemTH ( 'voy-qb-empty ' .. cssClass , itemName , '<em>unbekannt</em>' )
end
if ( wdItem == '' ) then
if ( wdID ~= '' ) then
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel2', 'kein Wert für ' .. itemName .. ' auf Wikidata: [[File:View-so edit simple.svg|15px|link=' .. wd.getWikidataLink(wdID, wdProperty) .. '|class=noviewer|' .. itemName .. ' nachtragen]]' )
if ( noWDCat ~= nil ) then
errorStr = errorStr .. '[[Kategorie:' .. noWDCat .. ']]'
end
else
display = display .. quickbar.trSingleTD ( 'qb-wd-comment carousel2', 'kein Objekt auf Wikidata: ([https://www.wikidata.org/w/index.php?search=&title=Special%3ASearch&go=Seite Suchen und Anlegen])' )
end
end
return errorStr .. display
end
return quickbar