SMWpc Documentation API Class

From FollowTheScore
Jump to: navigation, search

SMWpc: API on Class level

The following functions operate on class level. This means that they are applied to MediaWiki pages which describe an SMWpc Class. See also the complete list of SMWpc interfaces.


Template:.class definition

Defines a class and sets its basic attributes.

Syntax: {{.class definition|<class>|color=<color>|icon=<icon>|extends=<base class>|doc=<doc>}}

  • expects as first parameter the name of the class without the 'Class' prefix.
  • color = an optional color (in rrggbb Notation without a leading '#'), defaults to #f7f7f7
  • icon = an optional icon file name (without the Image: prefix)
  • extends = an optional name of a base class (without 'Class ') from which the current class is derived
  • doc = an optional text describing the semantic concept of the class

This template should only be used within a class definition article (like 'Class Foo').

Implementation notes

  • It could be useful to have a 'Special:Classes' page.
  • This template assigns the meta properties .class color, .class icon, .class extends and .class doc to the class.


Template:.class description

Displays a list of properties of the class. Inherited properties are 'not' included.

Syntax: {{.class description|<class>}}

  • expects the name of a class without the 'Class' prefix.

Example


Template:.class inheritance

Print all superclasses and the direct subclasse for a class

Syntax: {{.class inheritance|<class>}}

  • expects the name of a class, e.g. 'Class Foo'


Template:.class instances

Displays a list of instances of the given class, including inherited properties.

Syntax: {{.class instances|<class>|[<criteria>]}}

  • expects the name of a class (or the generic symbol '...') without the 'Class' prefix.
  • criteria = an optional condition which restricts the amount of instances; syntax follows #ask.

Example


Template:.class menu

Displays a navigation aid to browse class definitions. If the currently selected class has an icon attached it will be shown. Also provides links to graphs of the model an of the meta model.

Syntax: {{.class menu|<class>|color=<color>}}

  • expects as first parameter the name of a class (or the generic symbol '...') without the 'Class' prefix.
  • color = the background color for the navigation bar; typically this will be the color of the current class


Template:.class references

Displays a list of properties (and their classes) which point to instances of the specified class.

Syntax: {{.class references|<class>}}

  • expects the name of a class without the 'Class' prefix.

Example

{{#var:refs}}


Implementation notes


Template:.class summary

Displays a summary information about the specified class:

  • description
  • inheritance
  • properties
  • references
  • instances

Syntax: {{.class summary|<class>}}

  • expects the name of a class without the 'Class' prefix.


Template:.class properties

Get a list of all properties for a class

Syntax: {{.class properties|<class>|[all]}}

  • expects the name of a class (without the 'Class ' prefix)
  • returns a comma separated string which contains the names of all properties which can be used to describe instances of that class.
  • If the second parameter is 'all' the string will also contain properties attached to base classes of the specified class ('inherited properties').

Examples

Implementation notes

  • 'Template:.class properties' does not use recursion because MediaWiki truncates recursive template calls. Instead it uses a fixed number of sub-templates - which limits the maximum depth of the class tree to 5.
  • This could be improved in a php implementation.
  • The proposed syntax for an implementation as a parser function is: {{#class:properties|<class>|[all]}}.


Template:.class parents

Get the parent class(es) of a class.

Syntax: {{.class parents|<class>}}

  • expects the name of a class (without the 'Class ' prefix)
  • returns a string which contains a chain of hyperlinks to all superclasses of the given class.

Example

  • get the superclasses of class 'Freshman': {{.class parents|Freshman}} returns: {{#vardefine:parent|{{#vardefine:x|{{#replace:{{#ask:format=list|Class Freshman.class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}}}{{#replace:{{#vardefine:parent|{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#var:parent}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}}}{{#vardefine:parent|{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#var:parent}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}}}{{#vardefine:parent|{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#var:parent}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}}}[[{{#var:parent}}]] → [[{{#var:parent}}]] → [[{{#var:parent}}]] → [[{{#var:parent}}]] →|/Class ([^\]]+)/|Class \1|\1}}

Implementation notes

  • 'Template:.class parents' does not use recursion because MediaWiki truncates recursive template calls. Instead it uses sub-templates which limits the maximum depth of the class tree to 5.
  • An implementation in php would be more efficient and could avoid this limit.
  • The proposed syntax for an implementation as a parser function is: {{#class:parents|Foo}}.