Extension:Semantic Rating

The Semantic Rating extension adds a Semantic Forms input type to allow users to enter a star rating in a form by clicking on the stars. It also adds a parser function to display a star rating. The parser function is capable of displaying empty (gray), full (yellow), and half stars.

Special thanks to Bernadette Clemente for the original idea that inspired this extension and to Kelly Hatfield for an early implementation of this extension.

Installation
This extension requires Semantic MediaWiki and Semantic Forms to be installed first.

Configuration
There is a single configuration variable that may be set,. It holds the default value for the maximum value of a rating (that is, the total number of stars that will be displayed). If the maximum value is not explicitly set in a form field or parser function invocation,  will be used. If  is also not set, 5 will be used.

Defining a Field in a Semantic Form
The following will add an input field with the default maximum number of stars:

The maximum number of stars can be set explicitly with the max parameter:

Displaying a Rating
The following displays a 3 star rating using the default maximum number of stars:

If the default maximum is 5, it will display 3 yellow stars and 2 gray stars. If the default maximum is 10, it will display 3 yellow stars and 7 gray stars.

To explicitly set the maximum number of stars to 10, use the following:

Displaying a Rating Using a Template Parameter
For the form field defined in the example above, the value of the rating will be passed into the template associated with the form field as a named paramter. Because the form field is given the name Rating, that will be the name of the paramter as well. Therefore, in the template, the rating can be displayed as:

Displaying the Result of a Semantic Query as a Five Star Rating
Below are several more advanced examples that illustrate how this extension can be used.

Consider the case where users can review a wiki page. In this example, each review is itself a wiki page in category Reviews. Each review page has a property, Item, that is a link to the page being reviewed. Each review page also has a property, Rating, that has a value between 1 and 5 (with 0 being reserved for the case where no rating is assigned).

On the page being reviewed, the page's average rating can be displayed by the following query:

Further, assume that each page being reviewed has a property, Author, pointing to a page for the author of the page being reviewed. On the author's page, using the ParserFunctions and Arrays extensions, the average rating for all pages authored by that author (an average of the average page ratings) can be displayed by the following: