Page MenuHomePhabricator

[Task] Have Wikibase client extend Capiunto with an addStatement method
Open, LowPublic1 Story Points

Description

The capiunto interface allows to use methods like addRow or addImage to add data to an infobox. One should also be able to call addStatement and pass the label of a property to get a row with the statements for that property. The module should be used like this:

In this first version, references and qualifiers are not supported. There will be other tasks to discuss and decide how they should be included in this pattern.

Code example

Module:Infobox
local infobox = require 'capiunto-wikibase'

local p = {}

function p.run()
	return infobox.create( {
		title = 'Title of the Infobox'
	} )
	:addRow( 'A label', 'some data' )
	:addHeader( 'A header between the data rows' )
	:addRow( 'Another label', 'more data' )
	:addStatement( 'Some wikidata property' )
end

return p

Event Timeline

Bene created this task.May 30 2015, 11:27 AM
Bene updated the task description. (Show Details)
Bene raised the priority of this task from to Needs Triage.
Bene added subscribers: Bene, Aklapper.
Bene added a comment.May 30 2015, 2:10 PM

P707 is a proposal how this module could/should look like.

1local capiunto = require 'capiunto'
2local util = require 'libraryUtil'
3
4local referenceRenderer
5
6function addStatement( t, property )
7 local value = ''
8 local frame = mw.getCurrentFrame()
9
10 if frame.args[property] then
11 value = frame.args[property]
12 else
13 local entity = mw.wikibase.getEntity()
14 local propertyId = mw.wikibase.resolvePropertyId( property )
15
16 if propertyId ~= nil then
17 value = renderStatements( entity:getStatements( propertyId ) )
18 end
19 end
20
21 if value ~= '' then
22 t:addRow( property, value )
23 end
24
25 return t
26end
27
28function renderStatements( statements )
29 local value = ''
30 local frame = mw.getCurrentFrame()
31
32 for k, statement in pairs( statements ) do
33 if value ~= '' then
34 value = value .. tostring( mw.message.new( 'comma-separator' ) )
35 end
36
37 value = value .. mw.wikibase.renderSnak( statement.mainsnak )
38
39 if statement.references then
40 value = value .. renderReferences( statement.references )
41 end
42 end
43
44 return value
45end
46
47function renderReferences( references )
48 local value = ''
49 local frame = mw.getCurrentFrame()
50
51 for k, reference in pairs( references ) do
52 value = value .. frame:preprocess(
53 '<ref name="' .. reference.hash .. '">' .. referenceRenderer( reference.snaks ) .. '</ref>'
54 )
55 end
56
57 return value
58end
59
60function defaultReferenceRenderer( snaks )
61 return mw.wikibase.renderSnaks( snaks )
62end
63
64local create = capiunto.create
65
66capiunto.create = function( options )
67 local infobox = create( options )
68 infobox.addStatement = addStatement
69
70 referenceRenderer = options.referenceRenderer or defaultReferenceRenderer
71 util.checkType( 'referenceRenderer', 1, referenceRenderer, 'function' )
72
73 return infobox
74end
75
76return capiunto

Bene set Security to None.May 30 2015, 5:56 PM
Bene added a subscriber: hoo.
hoo renamed this task from Add an `addStatement` method to the capiunto interface to Have Wikibase client extend Capiunto with an addStatement method.May 30 2015, 6:02 PM
Bene claimed this task.Jun 12 2015, 10:51 AM
Lydia_Pintscher triaged this task as Normal priority.Jun 12 2015, 1:14 PM

Change 217876 had a related patch set uploaded (by Bene):
Extend capiunto with an addStatement function

https://gerrit.wikimedia.org/r/217876

Bene edited a custom field.Jun 16 2015, 7:42 PM
Jonas renamed this task from Have Wikibase client extend Capiunto with an addStatement method to [Taks] Have Wikibase client extend Capiunto with an addStatement method.Aug 13 2015, 3:30 PM
Lydia_Pintscher renamed this task from [Taks] Have Wikibase client extend Capiunto with an addStatement method to [Task] Have Wikibase client extend Capiunto with an addStatement method.Aug 13 2015, 7:04 PM
Lydia_Pintscher lowered the priority of this task from Normal to Low.Apr 23 2017, 5:49 PM
hoo moved this task from Incoming to To do later on the Wikibase-Lua board.Apr 12 2018, 1:58 PM

Change 217876 abandoned by Addshore:
Extend capiunto with an addStatement function

https://gerrit.wikimedia.org/r/217876