模块:Wikibase
跳转到导航
跳转到搜索
File:Test Template Info-Icon - Version (2).svg 模块文档[查看] [编辑] [历史] [清除缓存]
| 警告 | 此模块被引用于约847,000个页面,占全部页面的17%。 为了避免造成大规模的影响,所有对此模块的编辑应先于沙盒或测试样例上测试。 测试后无误的版本可以一次性地加入此模块中,但是修改前请务必于讨论页发起讨论。 模板引用数量会自动更新。 |
| File:Edit-copy green with red question mark.svg | 此模块的文档不存在、不全面或不能详细描述其功能及/或其代码中的参数。请帮助扩充并改进其文档。 |
This module is copied from the example from the module documentation at mw:Extension:Wikibase Client/Lua. It should be kept consistent with that documentation, rather than being adapted further for use on Wikipedia.
Usage[编辑]
- id
{{#invoke: Wikibase | id }}
- label
{{#invoke: Wikibase | label }}{{#invoke: Wikibase | label | entity id (Q# or P#) }}
- description
{{#invoke: Wikibase | description }}{{#invoke: Wikibase | description | entity id (Q# or P#) }}
- page
{{#invoke: Wikibase | page }}{{#invoke: Wikibase | page | item id (Q#) }}
- datatype
{{#invoke: Wikibase | datatype | property id (P#) }}
Examples[编辑]
id[编辑]
{{#invoke:Wikibase | id }}→ 无mw.wikibase
label[编辑]
{{#invoke:Wikibase | label }}→ 第21行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | label | Q132689 }}→ 第27行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | label | P31 }}→ 第27行Lua错误:attempt to index field 'wikibase' (a nil value)
description[编辑]
{{#invoke:Wikibase | description }}→ 第34行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | description | Q132689 }}→ 第40行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | description | P31 }}→ 第40行Lua错误:attempt to index field 'wikibase' (a nil value)
page[编辑]
{{#invoke:Wikibase | page }}→ 第47行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | page | Q132689 }}→ 第53行Lua错误:attempt to index field 'wikibase' (a nil value)
datatype[编辑]
Commons media: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P18 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P18 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
Globe coordinate: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P625 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P625 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
Item: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P6 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P6 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
Property: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P1647 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P1647 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
String: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P225 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P225 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
Monolingual text: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P1448 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P1448 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
Quantity: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P1082 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P1082 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
Time: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P569 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P569 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
URL: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P856 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P856 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
Mathematical expression: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P2534 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P2534 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
External identifier: 未安装 Extension:Wikibase ?
{{#invoke:Wikibase | datatype | P212 }}→ 第63行Lua错误:attempt to index field 'wikibase' (a nil value){{#invoke:Wikibase | datatype | Property:P212 }}→ 第59行Lua错误:attempt to index field 'wikibase' (a nil value)
---------- Module:Wikibase ----------------
local p = {}
-- Return the item ID of the item linked to the current page.
function p.id(frame)
if not mw.wikibase then
return "无mw.wikibase"
end
entity = mw.wikibase.getEntityObject()
if entity == nil then
return "无项目"
end
return entity.id
end
-- Return the label of a given data item, or of connected page
-- if no argument is provided to this method.
function p.label(frame)
if frame.args[1] == nil then
entity = mw.wikibase.getEntityObject()
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
return mw.wikibase.label( id )
end
-- Return the description of a given data item, or of connected page
-- if no argument is provided to this method.
function p.description(frame)
if frame.args[1] == nil then
entity = mw.wikibase.getEntityObject()
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
return mw.wikibase.description( id )
end
-- Return the local page about a given data item, or of connected page
-- if id is not specified.
function p.page(frame)
if frame.args[1] == nil then
entity = mw.wikibase.getEntityObject()
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
return mw.wikibase.sitelink( id )
end
-- Return the data type of a property
function p.datatype(frame)
if frame.args[1] and string.find(frame.args[1], "Property:P") then
if mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P")) then
return mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P") ).datatype
end
elseif frame.args[1] and string.find(frame.args[1], "P") then
if mw.wikibase.getEntityObject(frame.args[1]) then
return mw.wikibase.getEntityObject(frame.args[1]).datatype
end
end
end
return p