Extension:W4G Rating Bar

From MediaWiki.org
Jump to: navigation, search
Language: English  • français
MediaWiki extensions manual - list
Crystal Clear action run.png
W4G Rating Bar

Release status: stable

W4G Rating Bar - screenshot.png
Implementation Parser function, Tag, Ajax, Special page, Database
Description Lets users vote on pages, lists top pages (globally or by category), lists latest votes, etc.
Author(s) David and Franck Dernoncourt
Last version 2.1.2 (2011-05-21)
MediaWiki 1.16, 1.17, 1.18, 1.19, 1.20 (see compatibility table)
PHP 5.2, 5.3, 5.4 (see compatibility table)
License CC-BY-NC-SA (NOT for commercial purposes!)
Download Official page | Direct link
Example Syntax guide
Parameters

$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']

Tags
<w4grb_ratinglist/>
Added rights

w4g_rb-canvote

Hooks used
ParserFirstCallInit

LanguageGetMagic
BeforePageDisplay

Check usage and version matrix

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.

Contents

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 column, 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:

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

Installation [edit]

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:
CREATE TABLE IF NOT EXISTS `w4grb_votes` (
  `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`)
) ENGINE=InnoDB DEFAULT CHARSET=binary;

CREATE TABLE IF NOT EXISTS `w4grb_avg` (
  `pid` int(10) unsigned NOT NULL,
  `avg` float unsigned NOT NULL,
  `n` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`pid`)
) ENGINE=InnoDB DEFAULT CHARSET=binary;
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!)

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

Configuration [edit]

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

Example:

$wgW4GRB_Settings['ajax-fresh-data']=true;
$wgW4GRB_Settings['allow-unoptimized-queries']=true;
$wgW4GRB_Settings['auto-include']=false;
$wgW4GRB_Settings['fix-spaces']=true;
$wgW4GRB_Settings['max-bars-per-page']=1;
$wgW4GRB_Settings['max-items-per-list']=200;
$wgW4GRB_Settings['default-items-per-list']=30;
$wgW4GRB_Settings['max-lists-per-page']=5;
$wgW4GRB_Settings['show-voter-names']=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;

Usage [edit]

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.)

Language: English  • français