Extension:W4G Rating Bar

From MediaWiki.org
Jump to navigation Jump to search
Other languages:Project:Language policy English  • français
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.svg
W4G Rating Bar

Release status:Extension status unmaintained

W4G Rating Bar - screenshot.png
ImplementationTemplate:Extension#type Parser function, Tag, Ajax, Special page, Database
DescriptionTemplate:Extension#description Lets users vote on pages, lists top pages (globally or by category), lists latest votes, etc.
Author(s)Template:Extension#username David and Franck Dernoncourt
Latest versionTemplate:Extension#version 2.1.2 (2011-05-21)
MediaWikiTemplate:Extension#mediawiki 1.16, 1.17, 1.18, 1.19, 1.20 (see compatibility table)
PHPTemplate:Extension#php 5.2, 5.3, 5.4 (see compatibility table)
LicenseTemplate:Extension#license Creative Commons Attribution Share Alike 4.0
Download Official page | Direct link
ExampleTemplate:Extension#example Syntax guide

$wgW4GRB_Path, $wgW4GRB_Settings['ajax-fresh-data'], $wgW4GRB_Settings['allow-unoptimized-queries'], $wgW4GRB_Settings['anonymous-voting-enabled'], $wgW4GRB_Settings['auto-include'], $wgW4GRB_Settings['default-items-per-list'], $wgW4GRB_Settings['fix-spaces'], $wgW4GRB_Settings['max-bars-per-page'], $wgW4GRB_Settings['max-items-per-list'], $wgW4GRB_Settings['max-lists-per-page'], $wgW4GRB_Settings['multivote-cooldown'], $wgW4GRB_Settings['show-voter-names']

Added rightsTemplate:Extension#rights


Hooks usedTemplate:Extension#hook

Translate the W4G Rating Bar extension if it is available at translatewiki.net

Check usage and version matrix.

Note: Though the original authors no longer contribute to the extension, the license has been changed to allow for GitHub upload and for someone else to take up the mantle. Seemingly, most instabilities at the current moment are due to incompatibilities with newer MediaWiki versions.

W4G Rating Bar provides a page rating system. The rating bar can be either manually included on pages, using a parser function ({{#w4grb_rate}}), or automatically added at the bottom of all pages, by setting $wgW4GRB_Settings['auto-include'] to true. Various top-lists can then be generated.
W4G Rating Bar is a total rewrite of Extension:Rating Bar, which it replaces.

Functionality overview[edit]

  • {{#w4grb_rate:[page name]}} displays a rating bar for [page name], scaled from 0 to 100%. (NB: to use it for the current page, you can omit [page name] but not the colon, i.e.: {{#w4grb_rate:}} but not {{#w4grb_rate}})
  • {{#w4grb_rawrating:[page name]}} displays the rating of [page name].
  • <w4grb_ratinglist/> can display many kinds of list:
    • Top rated pages (globally, for a category, during the last X days, among pages with at least Y votes)
    • Top voters (by amount of votes, within a category, during the last X days)
    • Latest votes for: a page, a category, or globally
    • Latest votes by a specific user

For your users' privacy, the $wgW4GRB_Settings['show-voter-names'] setting (boolean) can be used to enable or disable the functions which link a user to their ratings.

Features removed compared to the previous version[edit]

  • Anonymous voting added back in version 2.1.0.
  • Star-style bar.
  • Maximum rating configuration (always 100 now).

Upgrading from 2.0.1 to 2.1.0[edit]

To support anonymous voting, the database was slightly edited: you need to run the following query to update it:

ADD PRIMARY KEY (  `uid` ,  `pid` ,  `ip` );
NB: don't forget to add your table prefix if applicable.


From scratch[edit]

1. Create a new folder in your wiki-install-folder/extensions/ folder.
2. Download the source code archive and extract it in this new folder.
3. Run the following SQL query to create additional tables in your wiki's database:
  `uid` int(11) unsigned NOT NULL,
  `pid` int(11) unsigned NOT NULL,
  `vote` tinyint(4) unsigned NOT NULL,
  `ip` varbinary(39) NOT NULL,
  `time` int(11) unsigned NOT NULL,
  PRIMARY KEY  (`uid`,`pid`,`ip`)

  `pid` int(10) unsigned NOT NULL,
  `avg` float unsigned NOT NULL,
  `n` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`pid`)
NB: don't forget to add your table prefix if applicable.
4. Add the following code at the end of LocalSettings.php:
require_once( "$IP/extensions/[the folder you created]/w4g_rb.php");
$wgW4GRB_Path = "/extensions/[the folder you created]";
(replace, of course, with the proper path!)
3. This is a PostgreSQL version from Thomas Bayen:
drop table if exists w4grb_votes;
drop table if exists w4grb_avg;

CREATE TABLE w4grb_votes (
  uid numeric(11) NOT NULL,
  pid numeric(11) NOT NULL,
  vote numeric(4) NOT NULL,
  ip bytea NOT NULL,
  time numeric(11) NOT NULL,
  PRIMARY KEY  (uid,pid,ip)
ALTER TABLE w4grb_votes OWNER TO wikiuser;

CREATE TABLE w4grb_avg (
  pid numeric(10) NOT NULL,
  avg real NOT NULL,
  n numeric(10) NOT NULL,
  PRIMARY KEY  (pid)
ALTER TABLE w4grb_avg OWNER TO wikiuser;

As you installed PostgreSQL you know that your user table can not be called "user" and you eventually changed the name to something like "mwuser". If you use a prefix everything will be ok but if not you have to change the source to fit your table name.

Upgrading from Rating Bar v1.1[edit]

If you're currently using the old Rating Bar 1.1 extension, you'll need to convert the database to the new scheme. A migration tool is available starting with version 2.0-b2. This migration tool is not (and won't be) able to merge old data with new data. Also, since this version doesn't support anonymous voting, the tool won't import anonymous votes Starting with version 2.1.0 the tool will import anonymous votes (but it needs to be configured to do so, see step 2 below). To upgrade from Rating Bar v1.1:

1. Follow the #From scratch instructions above.
2. Go to the extension's folder and edit the parameters on lines 25-32 of SpecialW4GRBMigrate.php.
3. Add require_once( $IP.'/extensions/[the folder you created]/SpecialW4GRBMigrate.php'); in LocalSettings.php just after require_once( $IP.'/extensions/[the folder you created]/w4g_rb.php');
4. Go to your wiki's special page Special:W4GRBMigrate. The migration will run automatically.
5. Remove require_once( $IP.'/extensions/[the folder you created]/SpecialW4GRBMigrate.php'); from LocalSettings.php and (optionally and after checking everything worked fine) delete the old ratingbar table.
6. ... and don't forget to update the pages which use the extension: the new extension uses different tags.

Compatibility table[edit]

MW 1.15 MW 1.16 MW 1.17 MW 1.20
PHP 5.2 No 2.0-2.0.1 2.1.0-2.1.2 2.0-2.1.2 2.0-2.1.2
PHP 5.3 No 2.0-2.0.1 2.1.0-2.1.2 2.0-2.1.1 2.1.2 2.0-2.1.2
PHP 5.4 No 2.0-2.1.2 2.0-2.1.2 2.0-2.1.1 2.1.2
Doesn't work Might work Should work (but not tested) Tested and working


You can edit the following settings in LocalSettings.php (add them after the line which includes the extension):

Setting Description Default
$wgW4GRB_Settings['ajax-fresh-data'] boolean, whether or not you want to use AJAX to display an uncached rating to visitor. Set to false if you need to restrict database queries (only affects slave databases). true
$wgW4GRB_Settings['allow-unoptimized-queries'] boolean, whether or not to allow queries which need some extra calculations in MySQL. They're not that terrible, this thing is just here as an emergency switch in case someone keeps running demanding queries on a very large database. true
$wgW4GRB_Settings['anonymous-voting-enabled'] boolean, whether or not anonymous (=not logged-in user) voting is enabled. false
$wgW4GRB_Settings['auto-include'] boolean, whether or not to automatically include the rating bar at the bottom of every page. false
$wgW4GRB_Settings['default-items-per-list'] default amount of items that will be displayed in a top list (NB: this CAN be higher than max-items-per-list by design). not fixed, may change
$wgW4GRB_Settings['fix-spaces'] boolean, whether or not you want to enable auto replacing of spaces with underscore (and vice versa) when needed in page/category name input, so that spaces and underscores can be used indifferently (otherwise the user must sometimes write underscores, and sometimes not - a bit annoying indeed). true
$wgW4GRB_Settings['max-bars-per-page'] maximum amount of bars that can be included within one page (this doesn't count the auto-included bar). not fixed, may change
$wgW4GRB_Settings['max-items-per-list'] maximum amount of items that can be displayed in a top list. not fixed, may change
$wgW4GRB_Settings['max-lists-per-page'] maximum amount of lists that can be displayed in a single page. not fixed, may change
$wgW4GRB_Settings['multivote-cooldown'] time, in seconds, to consider that the same IP = the same person to prevent multivote. 36000*24*7 (1 week)
$wgW4GRB_Settings['show-mismatching-bar'] boolean, whether or not to display the name of the page being voted on if it's not the same as the page on which the bar is displayed. true
$wgW4GRB_Settings['show-voter-names'] boolean, whether or not it's possible to publicly link user names to their ratings. false



Finally, you can also control who can vote with the w4g_rb-canvote right. The default values are:

$wgGroupPermissions['*']['w4g_rb-canvote'] = false;
$wgGroupPermissions['user']['w4g_rb-canvote'] = true;
$wgGroupPermissions['autoconfirmed']['w4g_rb-canvote'] = true;
$wgGroupPermissions['bot']['w4g_rb-canvote'] = false;
$wgGroupPermissions['sysop']['w4g_rb-canvote'] = true;
$wgGroupPermissions['bureaucrat']['w4g_rb-canvote'] = true;


A list of functions and parameters as well as syntax examples are available here: http://www.wiki4games.com/Wiki4Games:W4G_Rating_Bar/syntax.

Who's using it?[edit]

(Please add your URL to the bottom of the list.)

Other languages:Project:Language policy English  • français