
در صورت تمایل یک صفحهٔ توضیحات برای این پودمان اسکریبونتو ایجاد کنید. ویرایشگران میتوانند در صفحات تمرین (ایجاد | آینه) و آزمایشی (ایجاد) این پودمان را آزمایش کنند. لطفاً ردهها را به زیرصفحهٔ /توضیحات بیافزایید. زیرصفحههای این پودمان. |
local check = require('پودمان:Check2') local wd = require('پودمان:Wikidata2') local locMap = require('پودمان:Location map') local cfgParams = mw.loadData('پودمان: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 argsParent[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 ) local tr = mw.html.create ( 'tr' ) tr:tag('td') :attr('colspan', colSpan ) :addClass('qbHeader') :wikitext(text) return tostring ( tr ) end function quickbar.trItemTH ( className, text1, text2, text3, text4 ) local tr = mw.html.create ( 'tr' ) tr:addClass('qbItem ' .. className ) :tag('th') :addClass('qbItem-key') :wikitext(text1) if ( text2 ~= nil ) then tr:tag('td'):addClass('qbItem-value1'):wikitext(text2) end if ( text3 ~= nil ) then tr:tag('td'):addClass('qbItem-value2'):wikitext(text3) end if ( text4 ~= nil ) then tr:tag('td'):addClass('qbItem-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('qbItem-value1'):wikitext(text2) end if ( text3 ~= nil ) then tr:tag('td'):addClass('qbItem-value2'):wikitext(text3) end if ( text4 ~= nil ) then tr:tag('td'):addClass('qbItem-value3'):wikitext(text4) end return tostring ( tr ) end function quickbar.trSingleTD ( className, text, colSpan ) if ( colspan == nil ) then colSpan = '2' end local tr = mw.html.create ( 'tr' ) tr:addClass('qbItem ' .. className ) :tag('td') :attr('colspan', colSpan ) :addClass('qbItem-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('qbItem ' .. className ) :tag('td') :attr('colspan', colSpan) :addClass('qbImageCell') :tag('div') :addClass('qbImage') :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('qbImage') :wikitext(imageFile1) local td2 = mw.html.create ( 'td' ) td2:addClass( className2 ) :tag('div') :addClass('qbImage') :wikitext(imageFile2) local tr = mw.html.create ( 'tr' ) tr:addClass('qbItem ' .. className ) :tag('td') :attr('colspan', colSpan) :addClass('qbImageCell') :tag('table') :tag('tr') :node(td1) :node(td2) return tostring ( tr ) end function quickbar.locmap ( colSpan, map ) local tr = mw.html.create ( 'tr' ) tr:addClass('qbLocMap') :tag('td') :attr('colspan', colSpan) :wikitext(locMap.locationMap(map)) return tostring ( tr ) end function quickbar.hr ( colSpan ) local hr = mw.html.create ( 'tr' ) hr:addClass('qb-line') :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 posPossible = { rechts = '', links = '', left = '', right = '', 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 = 'qb' if pos == 'left' then classes = classes .. ' qbleft' end if pos == 'rechts' then classes = classes .. ' qbleft' end -- if pos == 'normal' then classes = classes .. ' qbleft' end if pos == 'right' then classes = classes .. ' qbright' end if pos == 'links' then classes = classes .. ' qbright' end if topBorder == 'yes' then classes = classes .. ' qbTopBorder' 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 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 ) end function quickbar.qb_item ( frame ) local qbHeading = getParameter ( frame, cfgParams["qb_item"], 'heading' ) local qbValue = getParameter ( frame, cfgParams["qb_item"], 'value' ) return check._testParams ( frame:getParent().args, cfgParams["qb_item"], 'Quickbar2' ) .. quickbar.trItemTH ( '', qbHeading, qbValue ) 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' ) if ( qbImage == '' ) then qbImage = wd.getProperty ( wd.getBestStatement ( wd.EntityId(), qbWikidataProperty ).statement, qbWikidataFormat ) end if ( qbHeading ~= '' ) then display = display .. quickbar.theader ( qbColspan, qbHeading ) end display = display .. errorStr .. check._testParams ( frame:getParent().args, cfgParams["qb_image"], 'Quickbar2' ) .. quickbar.trImage ( '', qbImage, qbColspan ) return display end function quickbar.qb_line ( frame ) local qbColspan = getParameter ( frame, cfgParams["qb_line"], 'colspan' ) 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 ) end function quickbar.createEntry ( localItem, wdItem, wdID, cssClass, itemName, noWDCat, diffCat, equalCat ) local display = '' if ( localItem ~= '' ) then display = display .. quickbar.trItemTH ( cssClass, itemName, localItem ) if ( localItem ~= wdItem and wdItem ~= '' ) then display = display .. quickbar.trSingleTD ( 'qb-wd-comment', 'andere(r) ' .. itemName .. ' auf Wikidata [[File:View-so edit simple.svg|15px|link=wikidata:' .. wdID .. '|' .. itemName .. ' in Wikidata aktualisieren]] <span data-qb-item="'.. cssClass .. '" class="qb-edit-delete">[[File:Symbol delete vote.svg|15px|Eintrag aus der Quickbar entfernen und Wikidata benutzen]]</span>' ) if ( diffCat ~= nil ) then display = display .. '[[رده:' .. diffCat .. ']]' end end if ( localItem == wdItem and localItem ~= '' ) then display = display .. quickbar.trSingleTD ( 'qb-wd-comment', 'identische Angabe für ' .. itemName .. ' auf Wikidata. <span data-qb-item="'.. cssClass .. '" class="qb-edit-delete">[[File:Symbol delete vote.svg|15px|Eintrag aus der Quickbar entfernen und Wikidata benutzen]]</span>' ) if ( equalCat ~= nil ) then display = display .. '[[رده:' .. equalCat .. ']]' end end displayItem = true elseif ( wdItem ~= '' ) then display = display .. quickbar.trItemTH ( cssClass, itemName, '<span class="wikidata-content">' .. wdItem .. '</span>' ) displayItem = true else display = display .. quickbar.trItemTH ( 'qbEmpty ' .. 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=wikidata:' .. wdID .. '|' .. itemName .. ' nachtragen]]' ) if ( noWDCat ~= nil ) then display = display .. '[[رده:' .. 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, cssClass, itemName, noWDCat, noItemCat ) local display = '' local errorStr = '' if ( localItem ~= '' ) then display = display .. quickbar.trImage ( 'qb-image ' .. cssClass, localItem ) elseif ( wdItem ~= '' ) then local fileCheck = check._testFile ( wdItem, 'Quickbar2' ) if ( fileCheck == '' ) then display = display .. quickbar.trImage ( 'qb-image ' .. cssClass, mw.ustring.match ( wdItem, '%[%[.-%]%]' ) ) else errorStr = errorStr .. fileCheck end else errorStr = errorStr .. '[[رده:' .. noItemCat .. ']]' 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=wikidata:' .. wdID .. '|' .. itemName .. ' nachtragen]]' ) if ( noWDCat ~= nil ) then errorStr = errorStr .. '[[رده:' .. 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 errorStr .. display end function quickbar.createEntryTwoImages ( localItem1, wdItem1, wdID1, cssClass1, itemName1, noWDCat1, noItemCat1, localItem2, wdItem2, wdID2, cssClass2, itemName2, noWDCat2, noItemCat2 ) local display = '' local display1 = '' local display2 = '' local errorStr = '' local fileCheck1 = '' local fileCheck2 = '' if ( localItem1 ~= '' ) then display1 = localItem1 elseif ( wdItem1 ~= '' ) then fileCheck1 = check._testFile ( wdItem1, 'Quickbar2' ) if ( fileCheck1 == '' ) then display1 = mw.ustring.match ( wdItem1, '%[%[.-%]%]' ) else errorStr = errorStr .. fileCheck1 end else errorStr = errorStr .. '[[رده:' .. noItemCat1 .. ']]' end if ( localItem2 ~= '' ) then display2 = localItem2 elseif ( wdItem2 ~= '' ) then fileCheck2 = check._testFile ( wdItem2, 'Quickbar2' ) if ( fileCheck2 == '' ) then display2 = mw.ustring.match ( wdItem2, '%[%[.-%]%]' ) else errorStr = errorStr .. fileCheck2 end else errorStr = errorStr .. '[[رده:' .. noItemCat2 .. ']]' end if ( display1 ~= '' and display2 ~= '' ) then display = display .. quickbar.trTwoImages ( 'qb-image', cssClass1, cssClass2, display1, display2, 2 ) elseif ( display1 ~= '' and display2 == '' ) then display = display .. quickbar.trImage ( 'qb-image ' .. cssClass1, display1 ) elseif ( display1 == '' and display2 ~= '' ) then display = display .. quickbar.trImage ( 'qb-image ' .. cssClass2, display2 ) else end if ( wdItem1 == '' ) then if ( wdID1 ~= '' ) then display = display .. quickbar.trSingleTD ( 'qb-wd-comment', 'kein(e) ' .. itemName1 .. ' auf Wikidata: [[File:View-so edit simple.svg|15px|link=wikidata:' .. wdID1 .. '|' .. itemName1 .. ' nachtragen]]' ) if ( noWDCat1 ~= nil ) then errorStr = errorStr .. '[[رده:' .. noWDCat1 .. ']]' 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 if ( wdItem2 == '' ) then if ( wdID2 ~= '' ) then display = display .. quickbar.trSingleTD ( 'qb-wd-comment', 'kein(e) ' .. itemName2 .. ' auf Wikidata: [[File:View-so edit simple.svg|15px|link=wikidata:' .. wdID2 .. '|' .. itemName2 .. ' nachtragen]]' ) if ( noWDCat2 ~= nil ) then errorStr = errorStr .. '[[رده:' .. noWDCat2 .. ']]' 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 errorStr .. display end function quickbar.createEntryQuantity ( localItem, wdItem, wdID, wdProperty, wdFormat, cssClass, itemName, noWDCat, diffCat, equalCat ) local display = '' local errorStr = '' local property = '' if ( localItem ~= '' ) then if ( cssClass == '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 ( '<small>.*</small>', '' ):gsub ( '%(.*%)', '' ):gsub ( 'km²', '' ):gsub ( 'km2', '' ):gsub ( 'km<sup>2</sup>', '' ):gsub ( 'm', '' ) if ( localItem ~= wdItem and wdItem ~= '' ) then display = display .. quickbar.trSingleTD ( 'qb-wd-comment', '<span title="Wikivoyage: ' .. localItem .. '- Wikidata: ' .. wdItem .. '">anderer Wert für ' .. itemName .. ' auf Wikidata: ' .. wdItem .. '</span> [[File:View-so edit simple.svg|15px|link=wikidata:' .. wdID .. '|' .. itemName .. ' in Wikidata aktualisieren]] <span data-qb-item="'.. cssClass .. '" class="qb-edit-delete">[[File:Symbol delete vote.svg|15px|Eintrag aus der Quickbar entfernen und Wikidata benutzen]]</span>' ) if ( diffCat ~= nil ) then display = display .. '[[رده:' .. diffCat .. ']]' end end if ( localItem == wdItem and localItem ~= '' ) then display = display .. quickbar.trSingleTD ( 'qb-wd-comment', 'identische Angabe für ' .. itemName .. ' auf Wikidata. <span data-qb-item="'.. cssClass .. '" class="qb-edit-delete">[[File:Symbol delete vote.svg|15px|Eintrag aus der Quickbar entfernen und Wikidata benutzen]]</span>' ) if ( equalCat ~= nil ) then display = display .. '[[رده:' .. equalCat .. ']]' end end displayItem = true elseif ( wdItem ~= '' ) then property = wd.getProperty ( wd.getBestStatement( wdID, wdProperty ).statement, wdFormat ) property = property:gsub('<span class="qbItemSmall">%(%)</span>','') display = display .. quickbar.trItemTH ( cssClass, itemName, '<span class="wikidata-content">' .. property .. '</span>' ) displayItem = true else display = display .. quickbar.trItemTH ( 'qbEmpty ' .. cssClass , itemName , '<em>unbekannt</em>' ) end if ( wdItem == '' ) then if ( wdID ~= '' ) then display = display .. quickbar.trSingleTD ( 'qb-wd-comment', 'kein Wert für ' .. itemName .. ' auf Wikidata: [[File:View-so edit simple.svg|15px|link=wikidata:' .. wdID .. '|' .. itemName .. ' nachtragen]]' ) if ( noWDCat ~= nil ) then errorStr = errorStr .. '[[رده:' .. 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 errorStr .. display end return quickbar