Help:Implementing a "Semantic Point System"

From semantic-mediawiki.org
Semantic extension(s): Semantic MediaWiki · Semantic Extra Special Properties
Further extension(s): ParserFunctions · Variables
Keyword(s): points · gameification · user engagement

Description:

My community using Semantic MediaWiki was looking for a point system that we could enable. The goal was to provide users with points for creating, editing and encouraging the contributions of others. I didn't want to use an extension, but thought I could instead use the data from the Extension "Semantic Extra Special Properties" extension to make it happen.

The planned point system[edit]

The community decided on a simple point system to start

  • 5 points for every page creation
  • 1 point for every 10 page edits
  • 5 points for each additional user who contributes to a page you created

The last piece: Points for each additional user who contributes to a page you created was the most complicated and I needed to use the Template Result format with intro and outro Templates to calculate that number.

Result Format Templates[edit]

You will need to create your result format templates first. The query format templates have variables inside them that will be referred to on the point system template itself:

Template "Query Format/Author count"
{{#vardefine:finalcount|{{#expr: {{#var:finalcount}} + {{{rank}}} }}}}
Template "Query Format/Author count intro"
{{#vardefine:finalcount|0}}
Template "Query Format/Author count outro"
{{#var: finalcount}}

Creating the Point Template Itself[edit]

The point template itself was designed to go on user pages, and will use the magic word BASEPAGENAME. It doesn't work when added to user subpages at this time. I broke the Template up into 3 sections, to better explain the process. The three sections of code below should be pasted one after the other.

The first thing the template does is define a set of variables used to calculate the user's points. Each variable is retrieved from the Extra Special Properties through either #ask or #show functions.

Create Template:User points with the following code

{{#vardefine:pagecreations|{{#ask:[[Page creator::User:{{BASEPAGENAME}}]] |format=count}}}}
{{#vardefine:pageedits|{{#expr: {{formatnum:{{#show: User:{{BASEPAGENAME}} |?User edit count}}|R}} / 10}}}}
{{#vardefine:pagecontributors|{{#ask:[[Page creator::User:{{BASEPAGENAME}}]] [[Page author::!User:{{BASEPAGENAME}}]] |format=count}}}}
{{#vardefine:contributorcounts|{{#ask:[[Page creator::User:{{BASEPAGENAME}}]] [[Page author::!User:{{BASEPAGENAME}}]] 
|?Page author |format=valuerank 
|link=none 
|headers=hide 
|mainlabel=- 
|searchlabel=... further results 
|template=Template:Query Format/Author count 
|introtemplate=Template:Query Format/Author count intro 
|outrotemplate=Template:Query Format/Author count outro 
|liststyle=none
}}}}

The next part of the Template executes the math based on the point system I defined above. If you want to make adjustments to the system to award different point values, you can swap out the whole numbers in the expressions for your own. Paste this immediately after the code above:

{{#vardefine:creationpoints |{{#expr: {{#var: pagecreations}} * 5}}}}
{{#vardefine:editpoints |{{#expr: trunc {{#var: pageedits}} }}}}
{{#vardefine:contributorpoints |{{#expr: ({{#var:finalcount}}-{{#var:pagecontributors}})*5}}}}

To display the points on the page, I went with a side box. Here's where you can feel free to be creative. I opted to go with a tiered point system that would display a different image at each level. I also added information into the display on how points are earned along with the final point count. I wanted to added a property for that point value so I could use it in queries to generate user leaderboards etc.

{{Side box
|text=
<div style="padding: 5px; background-color: #063; color: #fff;">'''User Level'''</div>
{{BASEPAGENAME}}<br>
{{#vardefine:finalpoints|{{#expr: {{#var: creationpoints}} + {{#var: editpoints}} + {{#var: contributorpoints}} }}}}
'''''{{#var: finalpoints}}''''' ''points''<br>
{{#ifexpr: {{#var: finalpoints}} < 16 | <span style="color: #066;">'''1st level'''</span> [[File:Status-1st-level.png|link=]]
|{{#ifexpr: {{#var: finalpoints}} < 101 | <span style="color: #d4640e;">'''2nd level'''</span> [[File:Status-2nd-level.png|link=]]
|{{#ifexpr: {{#var: finalpoints}} < 501 | <span style="color: #a68134;">'''3rd level'''</span> [[File:Status-3rd-level.png|link=]]
|{{#ifexpr: {{#var: finalpoints}} < 1501 | <span style="color: #5f6669;">'''4th level'''</span> [[File:Status-4th-level.png|link=]]
|{{#ifexpr: {{#var: finalpoints}} < 3001 | <span style="color: #fbC90e;">'''5th level'''</span> [[File:Status-5th-level.png|link=]]
|{{#ifexpr: {{#var: finalpoints}} < 5001 | <span style="color: #a8acae;">'''6th level'''</span> [[File:Status-6th-level.png|link=]]
|{{#ifexpr: {{#var: finalpoints}} > 5000 | <span style="color: #0c3;">'''7th level'''</span> [[File:Status-7th-level.png|link=]]
|You have 0 points.
}}
}}
}}
}}
}}
}}
}}
|style= border: 1px solid #063; margin-bottom:1%; background-color: #fafafa; text-align: center; font-size: 14px;
|below= {{Hidden
|''How points are earned''
|
*''5 points for every page creation''
*''1 point for every 10 page edits''
*''5 points for each additional user who contributes to a page you created''
|headerstyle= background-color:#fff; font-size: 12px; color: #333
|style= font-size: 10px; width: 30em; color: #063
}}}}
{{#set:User points={{#var: finalpoints}} }}


Hopefully, someone find this template useful or gets their own ideas from it.