Jump to content

Extension:ArticlePlaceholder/Module:AboutTopic

From mediawiki.org


The ArticlePlaceholder extensions provides the option to override the functions used to render an entity to display it on a generated local page (placeholder).

The module Module:AboutTopic per default uses the entityRenderer provided by the ArticlePlaceholder extension. It is possible to use a custom entityRenderer or to overwrite each part of ArticlePlaceholder's entityRenderer separately.

The following diagram represents all available functions and their connections. The blue ovals are the functions provided by Wikibase Client's Lua Scribunto interface.

For every function in the graphic there are setters and getters. Following is the documentation of the default functions provided by the entityRenderer, the setter functions as well as a list of all getters. All setter functions take a function as parameter. The getter functions return a function.

Example

[edit]

In case that all top images should be exchanged with a certain kitten image the topImageRenderer (see Default functions) would be overwritten using the function setTopImageRenderer (see Setter functions) and the module Module:AboutTopic would look like the following:

local p = {}

p.showData = function(frame)
  entityRenderer = require( 'mw.ext.articlePlaceholder.entityRenderer' )

  -- new function for the topImageRenderer, that returns a static image with the appropriate CSS class
  local newTopImg = function()
    return '<div class="articleplaceholder-topimage">[[File:Cute_grey_kitten.jpg|thumb|right|300px]]</div>'
  end

  -- set the new function to override the default topImageRenderer
  entityRenderer.setTopImageRenderer( newTopImg )
  return entityRenderer.render( frame )
end

return p

Default functions

[edit]

The functions, that can be get and set in the Module:AboutTopic are depending on each other. Therefore it might be useful to read through the default functions' documentation when overwriting these.

  • The topImageRenderer( entity, propertyId, orientationImage ) renders the image on the top right (in left to right languages) and takes a table and two strings as arguments. It is one of the four functions the renderEntity() calls.
  • statementListRenderer( entity ): render a list of statements, takes a table as argument
  • identifierListRenderer( entity ): render a list of external identifier, takes a table as argument
  • descriptionRenderer( entity ): render the description of an item, takes an string as argument
  • bestStatementRenderer( entity, propertyId ): render the best (preferred rank if present, otherwise all normal rank) statement, takes a table and a string as argument
  • statementRenderer( statement ): render a given statement, takes a table as argument
  • imageStatementRenderer( imageStatement, orientationImage ): render a statement containing images, takes a table and a string as arguments
  • qualifierRenderer( qualifierSnak ): render the qualifier of a statement, takes a table as argument
  • referenceRenderer( references ): render the references of a statement, takes a table as argument
  • labelRenderer( entityId ): render the labels of entities, takes a string as argument
  • snaksRenderer( snaks ): render the snaks, takes a table as argument


Setter functions

[edit]
  • setTopImageRenderer( function )
  • setStatementListRenderer( function )
  • setIdentifierListRenderer( function )
  • setDescriptionRenderer( function )
  • setBestStatementRenderer( function )
  • setStatementRenderer( function )
  • setImageStatementRenderer( function )
  • setQualifierRenderer( function )
  • setReferenceRenderer( function )
  • setLabelRenderer( function )
  • setSnaksRenderer( function )

Getter functions

[edit]
  • getTopImageRenderer()
  • getStatementListRenderer()
  • getIdentifierListRenderer()
  • getDescriptionRenderer()
  • getBestStatementRenderer()
  • getStatementRenderer()
  • getImageStatementRenderer()
  • getQualifierRenderer()
  • getReferenceRenderer()
  • getLabelRenderer()
  • getSnaksRenderer()