Difference between revisions of "SMWpc Documentation API Object"
m (1 revision(s)) |
|
(No difference)
|
Latest revision as of 23:44, 23 March 2008
Contents
SMWpc: API on Object level
The following functions operate on object level (instance level). This means that they are applied to a a MediaWiki page which is an Instance of a SMWpc Class. See also the complete list of SMWpc interfaces.
Template:.obj is a
Declares a MediaWiki article page to be an instance of a SMWpc Class.
Syntax: {{.obj is a|<class>}}
- expects as first parameter the name of the class without the 'Class' prefix.
- generates a statment like 'Obj is a Class'
- generates a link to a page which shows inverted links, i.e. other article which have a property that points to the current object
Implementation notes
- This template sets internal variables to allow other templates faster access to the class name
- proposed syntax for a parser function: {{#object:class|<class>}}.
- This template assigns the meta property .obj is a to the object.
Template:.obj get , Template:.obj getText , Template:.obj getMy , Template:.obj getMyText
Return the value of a property.
Syntax: {{.obj get|<instance>|<property>|[<default value>]}}
or {{.obj getMy|<property>|[<default value>]}}
- The standard variant expects as first parameter the name of an instance of a class.
- The getMy-variants take the instance name from a variable named 'this' which is for example filled by a preceding call of {{.obj is a|<class>}}.
- expects as second parameter the name of a property (without "Property:")
- takes a default value as an optional third parameter. This will be delivered if the requested property is not set for the object.
- if there is no default value given and the property is not set an empty string will be returned.
- .obj get and .obj getMy return the value of the property; if its type is a page you will get a hyperlink to the page
- the Text-variants always return plain text, even if the value is of Type 'page'.
Examples
- {{.obj get|Peter|Born at}} returns '{{#vardefine:x|{{#replace:{{#ask:format=list|PeterBorn at::*}}|/^[^\]]*\]\] */|}}}}{{#var:x}}'.
- {{.obj getText|Peter|Born at}} returns '{{#vardefine:x|{{#replace:{{#ask:format=list|PeterBorn at::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}'.
- {{.obj get|Tony|Born at}} returns '{{#vardefine:x|{{#replace:{{#ask:format=list|TonyBorn at::*}}|/^[^\]]*\]\] */|}}}}{{#var:x}}'.
- {{.obj get|Tony|Born at|''unknown''}} returns '{{#vardefine:x|{{#replace:{{#ask:format=list|TonyBorn at::*}}|/^[^\]]*\]\] */|}}}}{{#var:x}}'.
- Now we set 'this' to 'Lucie' : {{#vardefine:this|Lucie}}{{#vardefine:this|Lucie}}
- {{.obj getMy|Born at}} returns '{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#var:this}}]]Born at::*}}|/^[^\]]*\]\] */|}}}}{{#var:x}}'.
Implementation notes
- This template uses an internal variable which holds the class name
- proposed syntax for a parser function: {{#object:get|<instance>|<property>|[<default value>]}}.
Template:.obj set
Assign a value to a property of the current object.
Syntax: {{.obj set|<property>|<value>|[<prefix>]}}
- assigns the value if the property is valid for the object's Type or on of its ancestors' Types.
- If the property is invalid, a wrning will be issued and no assignment is made
- If 'prefix' is a '-' the assignment will be silently made; otherwise the the assignment will be 'verbose', i.e. the value of the property will be printed; in addition the prefix will be printed before the property value. Skipping the third parameter completely will make a verbose assignment with no prefix being displayed.
Template:-
Print the argument and store its value as the 'current property'.
Syntax: {{-|<property>}}
- display the property name
- store its name as 'the current property'; successive calls of Template:+ can be used to assign a value to this property.
Implementation notes
- An internal variable called 'prop' is used to store the property. There is no such thing like a property stack.
Template:+
Assign a value to the 'current property'.
Syntax: {{+|<value>|[<prefix>]}}
- assign the value using Template:.obj set
- The second parameter is passed to 'Template:.obj set'.
Template:.obj is referenced by
Display a list of objects which have a property that points to the object. This is kind of a 'semantic what links here'.
Syntax: {{.obj is referenced by|<instance>|<class>}}
- expects an instance name
- expects a class name (without 'Class ' prefix)
Examples
{{.obj is referenced by|Bassoon|Musical Instrument}} returns {{#vardefine:self|Bassoon}}{{#ask:format=template|template=.obj is referenced by.ask|link=none|.prop refers to::Class Musical Instrument}}
Implementation notes
- This template uses an internal variable which holds the class name
- This template uses the subtemplate Template:.obj is referenced by.ask
- proposed syntax for a parser function: {{#object:get|<class>|<property>|[<default value>]}}.