Module:Quickbar
模块文档[创建]
您可能想要创建本的文档。 编者可以在本模板的沙盒 (创建 | 镜像)和测试样例 (创建)页面进行实验。 请在/doc子页面中添加分类。本模块的子页面。 |
local function renderRow(heading, value)return '|-\n| class="info" | \'\'\'' .. heading .. '\'\'\'\n| style="padding-right:5px;" | ' .. value .. '\n'endlocal function renderLinkedClaim(id)local linkTarget = mw.wikibase.sitelink(id)local linkName = mw.wikibase.label(id)if linkTarget == nil thenreturn linkNameelsereturn '[[' .. linkTarget .. '|' .. linkName .. ']]'endendlocal function rSimple(item, property)return item:formatPropertyValues( property ).valueendlocal function rPopulation(item, property, frame)local s = item:getBestStatements( property )[1]local result = mw.wikibase.renderSnak( s.mainsnak )-- Brainstorming a bit on significant digits:-- local result = '' -- local num, sigfig = require('Module:Convert').make_sigfig(frame, s.mainsnak.datavalue.value.amount, 3)-- result = result .. num .. ' * 10^'..sigfigif s.qualifiers ~= nil and s.qualifiers['P585'] ~= nil and #s.qualifiers['P585'] > 0 thenresult = result .. '(' .. string.match(s.qualifiers['P585'][1].datavalue.value.time, '0*([1-9][0-9]+)\-', 1) .. ')'endreturn resultendlocal function rElectricity(item, property)local claims = item:getBestStatements( property )local voltage = {}for _,s in pairs(claims) do local v = mw.wikibase.renderSnak( s.mainsnak )if s.qualifiers ~= nil and s.qualifiers['P2144'] ~= nil and #s.qualifiers['P2144'] > 0 thenv = v .. ' / ' .. mw.wikibase.renderSnak(s.qualifiers['P2144'][1])endtable.insert(voltage, v)endlocal result = table.concat(voltage, '、')if #item:getBestStatements('P2853') > 0 thenresult = result .. '(' .. item:formatPropertyValues( 'P2853' ).value .. ')'endreturn resultendlocal function claimOrLabel(id, property) local item = mw.wikibase.getEntity( id )if #item:getBestStatements( property ) > 0 and item:getBestStatements( property )[1].mainsnak.datavalue ~= nil thenreturn mw.wikibase.renderSnak( item:getBestStatements( property )[1].mainsnak )endreturn item:getLabel()endlocal function rCurrency(item, property)local claims = item:getBestStatements(property)local result = {}for _, claim in pairs(claims) dolocal id = 'Q' .. claim.mainsnak.datavalue.value['numeric-id']local currency = mw.wikibase.getEntity( id )local subresult = currency:getLabel()local symbol = claimOrLabel( id, 'P498' )if symbol ~= currency:getLabel() thensubresult = subresult .. '(' .. symbol .. ')'endif #currency:getBestStatements('P2284') > 0 thenfor _, price in pairs(currency:getBestStatements('P2284')) dosubresult = subresult .. '<br/>1 '..symbol..' = '.. string.format('%.4f', price.mainsnak.datavalue.value.amount ) .. ' ' .. claimOrLabel(string.match(price.mainsnak.datavalue.value.unit , 'Q%d+$'), 'P498')endendtable.insert(result, subresult)endreturn table.concat(result, '<br/>')endlocal function rEmergency(item, property)local claims = item:getBestStatements( property )local result = {}for _, claim in pairs(claims) dolocal id = 'Q' .. claim.mainsnak.datavalue.value['numeric-id']local res = claimOrLabel(id, 'P1329')if claim.qualifiers ~= nil and claim.qualifiers['P366'] ~= nil and #claim.qualifiers['P366'] > 0 thenlocal usage = {}for _, qual in pairs(claim.qualifiers['P366']) dotable.insert( usage, mw.wikibase.renderSnak(qual) )endres = res .. '(' .. table.concat(usage, '、') .. ')'endtable.insert(result, res)endreturn table.concat(result, '、')endlocal function rTimezones(item, property)local claims = item:getBestStatements( property )if #claims > 3 thenlocal minEntity = nillocal maxEntity = nillocal minOffset = 20local maxOffset = -20local unknownTZs = {}for _, claim in pairs(claims) dolocal e = mw.wikibase.getEntity('Q' .. claim.mainsnak.datavalue.value['numeric-id'] )if #e:getBestStatements( 'P2907' ) == 1 thenlocal val = tonumber( e:getBestStatements( 'P2907' )[1].mainsnak.datavalue.value.amount )if val < minOffset thenminOffset = valminEntity = eendif val > maxOffset thenmaxOffset = valmaxEntity = eendelsetable.insert(unknownTZs, e:getLabel())endendif minEntity ~= nil and maxEntity ~= nil and minOffset ~= maxOffset thenlocal r = minEntity:getLabel() .. '至' .. maxEntity:getLabel()if #unknownTZs > 0 thenr = r .. ' and ' .. table.concat(unknownTZs, ', ')endreturn rendendreturn rSimple(item, property)endlocal function rSingleLinked(item, property) if item:getBestStatements( property )[1].mainsnak.datavalue ~= nil thenreturn renderLinkedClaim('Q'..item:getBestStatements( property )[1].mainsnak.datavalue.value['numeric-id'])elsereturn nilendendlocal function rLinked(item, property)local claims = item.claims[property]local result = {}for _, claim in pairs(claims) doif claim.mainsnak.datavalue ~= nil thenlocal id = 'Q' .. claim.mainsnak.datavalue.value['numeric-id']table.insert(result, renderLinkedClaim(id))endendreturn table.concat(result, ', ')endlocal conf = {{{'capital','首都'}, '首都', 36, rSingleLinked},{{'currency','货币'}, '货币', 38, rCurrency},{{'population','人口'}, '人口', 1082, rPopulation},{{'electricity','电力','輸電'}, '[[电力系统|-{zh-hans:电力系统; zh-hant:輸電網路;}-]]', 2884, rElectricity},{{'callingcode','区号','區號'}, '[[国际电话区号列表|国家区号]]', 474, rSimple},{{'timezone','时区','時區'}, '[[时区]]', 421, rTimezones},{{'language','語言','语言'}, '语言', 37, rLinked},{{'emergencies','紧急','緊急'}, '紧急电话', 2852, rEmergency},{{'driving side'}, '驾驶方向', 1622, rSimple}}local p = {}function p.quickbar( frame )local parentArgs = frame:getParent().argslocal elements = {}local item = mw.wikibase.getEntity( )local useWikidata = (item ~= nil and item.claims ~= nil)local missingInfo = falseif parentArgs['首府'] == 'yes' thenconf[1][2]='首府'endlocal locationMap = parentArgs['location'] or parentArgs['位置']if (locationMap ~= nil and locationMap ~= '') or (useWikidata and item.claims['P242'] ~= nil and item.claims['P242'][1] ~= nil) thenif useWikidata and (locationMap == nil or locationMap == '') thenlocationMap = mw.wikibase.renderSnak( item:getBestStatements('P242')[1].mainsnak )endtable.insert(elements, '| colspan="2" style="text-align:center;padding:0" | [[File:' .. locationMap .. '|250px]]\n' )elsemissingInfo = trueend for _, params in pairs( conf ) do if params[3] ~= 0 then local val = nil for __, paramname in pairs(params[1]) do val = val or parentArgs[paramname] end if val == '' or val == nil then if useWikidata and #item:getBestStatements('P' .. params[3]) > 0 then val = params[4]( item, 'P' .. params[3], frame) if val ~= nil then table.insert( elements, renderRow(params[2], val) ) else missingInfo = true end else missingInfo = true end else table.insert(elements, renderRow(params[2], val) ) end end endlocal editRow = ''if item ~= nil theneditRow = '|-\n| colspan="2" class="info footer" |[[:d:'.. item.id .. '|在维基数据编辑]]\n'endif #elements > 0 thenif missingInfo == true and mw.title.getCurrentTitle().namespace == 0 thentable.insert(elements, '[[Category:Quickbar信息不完整的条目]]')endif mw.title.getCurrentTitle().namespace == 0 thentable.insert(elements, '[[Category:使用了Quickbar的條目]]\n')endreturn frame:extensionTag {name = 'templatestyles', args = {src = 'Quickbar/styles.css'}} .. '<div id="quickbar" class="wv-quickbar floatright">\n{| cellpadding="0" cellspacing="0"\n|-\n' ..table.concat(elements)..'\n'.. editRow.. '|}</div>'elseif mw.title.getCurrentTitle().namespace == 0 thenreturn '[[Category:Quickbar信息不完整的条目]][[Category:使用了Quickbar的條目]]\n'endreturn ''endendreturn p
🔥 Popular: 首页广州閩南語會話手冊Special:搜索中东中国行政区划国际电话区号列表京都府联合国教科文组织世界遗产名录西歐File:Vietnam Regions Map (zh-hans)-越南地图.png杭州巧家会泽富源威信中欧欧洲亚美尼亚广州白云国际机场汝城长征湄潭关岭京都市安顺宜章毕节意大利非洲中亚阿姆斯特丹Special:最近更改File:Map of India (zh-hans)-印度地图.png柏林/東部巴塞罗那文化Wiki Travel:地理分层File:Map-USA-Regions (zh-hans)-美国地图.png列支敦士登關西地方语言Wiki Travel:机器人Wiki Travel:免责声明北美洲瑞金新山Wiki Travel:互助客栈东南亚福州话会话手册格鲁吉亚User:Theklan喬科大田毛里求斯File:Map of Asia (zh-hans)-亚洲地图.png广州 (消歧义)印度京都巴尔干德國Category:会话手册常山摩爾曼斯克州黑水车臣格陵兰Wiki Travel:Resources/中山公交B1路线不丹南美洲Wiki Travel:指南条目土耳其語會話手冊新北File:Wikimania 2022 Vector (2022) Presentation.pdf马来语会话手册越南语会话手册File:Wikipedia 2006 1.pdfWiki Travel:Twinkle马来西亚