Open main menu

Extension talk:AjaxRatingScript


Author B.VahrmeijerEdit

I've cleaned up the code by using standard hooks instead of manual hooks.

  1. It works for all versions
  2. The AJAX element works fine now.
  3. The script is now downloadable and working at and

if you have MW installed in a subsite like and the rating script does not work please read the manual at and the discussion site.

Developement And Expanding Features Of AjaxRatingEdit

i'm starting a mediawiki based rating and commenting semantic database currently i'm working on one division www.ratingstars/pl/ i will add comments system from open source but i need mediawiki rating script with a few settings. user should vote as many times he wants but his votes are counted as one medium vote. it will allow to display a trend chart or quality chart. join my project if you like it. it should have 10 stars like

Hello and thanks for your extensionEdit

I installed it on my site : It works fine but something doesn't: When a user clicks on a vote, then navigate on the site and go back to the voted page, the vote doesn't appear. To make it appear, i have to clear the mozilla cache, and then the vote appear. Strange no ?

No, this isnt strange.. please read the posts the discussion at

Thank you for your answer. I have read this forum, else i wouldn't have asked my question here, but didn't found the answer i wanted. I am going to read it again. Bye


I think installation steps are not enough.

I completed all of them and still do not know, do I have to edit some templates and where to put <?php rating_bar('1',5); ?>? 12:14, 7 April 2009 (UTC)


I also followed the installation instructions but it doesn't seem to work. Why is the installation so different then it was 2 months ago? No localsettings.php changes? And there should be an explenation, where to insert what to get the stars on your site, on the extension site. AndiRay 11:26, 4 May 2009 (UTC)
To install you must add require_once("$IP/extensions/RateArticle.php"); to the LocalSettings.php file. When I finally find out how to install this I will write what steps are missing or are confusing AndiRay 14:18, 5 May 2009 (UTC)


The extension looks nice however I don't understand why we have to predefine the Database Settings in _config-rating.php like dbhost, dbuser, dbpass and etc. Can we just take advantage of LocalSettings.php? In the way is it now we have to update this file every time if we change our database settings. I also wanted to include wfLogDBError wfDebug in rpc.php. Seem like the file loads directly via javascript and doesn't have access to the global mediawiki functions. Is there any way that this can be fixed? Thanks

You have your wiki build up like this: this has consequences for the script codeEdit

to emphasize the 5! different paths which are important:

  • RateArticle.php: path to js/behavior.js
  • RateArticle.php: path to js/rating.js
  • RateArticle.php: path to css/rating.css
  • Ratings/drawrating.php: path to db.php
  • Ratings/js/rating.js: path to rpc.php

good luck

Yes, thanks, we finally found it, and made redirection in LocalSettings.php towards And now it works. Thank you.

Good job: put your wiki on the first page plz thnx

Limit to Specific PagesEdit

Hi, this extension is very good, but I would like to use this only on pages which I want and where I want by using some tag. Is it possible? I think that many users of mediawiki would welcome such alteration.--Sevela.p 13:22, 14 December 2007 (UTC)

Yes you can. Edit RateArticle.php and change the line (~44) that looks like this:
if ($wgArticle->getTitle()->mNamespace != 0) return $out;
You can make the logic whatever you like. You can have it only apply to pages in a specific namespace like this:
$myImportantNamespace = 102;
if ($wgArticle->getTitle()->getNamespace() != $myImportantNamespace) return $out;
Or you can make it match a specific set of titles like this:
$pagesToRate = array('Main Page', 'My Page 1', 'Sandbox');
if (!in_array($wgArticle->getTitle()->getText(), $pagesToRate)) return $out;
There are better ways to do it but this should get you started. --Christian 17:29, 26 December 2007 (UTC)
I use an adaptation of the $myImportantNamespace tweak. It works partly, because the rating do not appears on classical page and do on the allowed namespaces, but it also appears on the Category and Help Namespaces... Any ideas ? --Rmatt 23:58, 21 March 2008 (UTC)


I have not included a parser hook yet


This is a very nice extension. However, I would like to say, wouldn't it be nice if visitors could remove their votes then revote? As the pages are increasing in quality, the person may wish to change their opinion of the page. Just a tip. --NorthStar 18:06, 5 January 2008 (UTC)

I think it would be good to configure an option to delete the ratings after a certain number of days. I personally think that a vote should not be valable more than one year on a wiki. This would be a good improvement ! Rmatt, 20 March 2008

After using the AjaxRating, I have some suggestion:

  • Rerating, better if the same user can rerating after some period of time.
  • Rating base, better if rating based on login user(if login) otherwise based on ip address, not ip address only
  • Rating history, record rating history will be much better.

--Mints 07:23, 15 May 2009 (UTC)

Problem with installationEdit

Hi, this extension is great and it works fine, but when I start a new Page on the edit window I have the rating stars for this Topic. Is there any possibillity to hide the rating stars in the edit mode?

lol same here. cannot add new pages :D Man this extension has so many bugs and installation requires so many tweaks, the status shouldn't be stable. --Subfader 14:29, 30 March 2008 (UTC)

i cant get it to workEdit

i have the version 1.12 of mediawiki this is my be the problem? 08:50, 10 May 2008 (UTC)

How can I add the rating in specific pages?Edit

I already read the comment before that talks about it but my question is:

How i can add the rating thing in certain pages by just add some tags to the page like:


i mean to add that tags in every pages which i want the users to rate. thank u.

I would also be interested in knowing the answer to this question as I'm using the Rating Script for some of product ratings on our Wiki.

Script Error "viewer has no properties"Edit

First, thanks for the extension. It work's so far on my site But only after a manual purge of each single page (.../index.php?title=testpage&action=purge).

Without manual purge it gives a Javascript error in rating.js ("viewer has no properties"). It seems that the rating div isn't included in the cached content. I tried purging all pages with a script, But this doesn't work either. The site runs on MediaWiki 1.11.1 with AJAX RATING BAR V2 14-07-2007. I also used the newer script V2.5: same result. The site is working with URLs like --piggy 09:03, 28 May 2008 (UTC)

I answer my own question: to make it work i changed 'extension/Ratings/rpc.php' to '/extension/Ratings/rpc.php' in ratings.js (line 65)

--piggy 23:13, 8 June 2008 (UTC)

how can i translate this rating thingEdit

which file i need to edit?

you have to change RateArticle.php (v2.5 '$wgMessageCache' Special Page)

_drawrating.php: $tense, $rater

rpc.php: $tense, $new_back

maybe there are more strings. Try 'find' in your text editor.

--piggy 23:20, 8 June 2008 (UTC)

Rating SpecialPage and placementEdit

I think it would be nice to have a Rating page that showed top Rated articles, that would be available in the Special Pages section.

Also, I think it would be better if you could allow customizeable placement of the rating section (e.g. if the stars showed up in the upper right of the article, next to the title)

Using it to simply vote for an article (kind of digg-like)Edit

We're going to have some proposals for people to vote on, each of which will be on a page potentially. According to docs, it sounds like you can't vote only 1 star - but that's what we'd like to do: 1 star (=yes), or don't vote (0 stars). Is this possible to modify? Also, does this let people vote only once? Thanks. --Charlener 19:32, 27 August 2008 (UTC)

Non valide chez moi !Edit

line 258 column 317 - Erreur: document type does not allow element "link" here

V2 in MediaWiki 1.6.12Edit

I get this: unexpected T_OBJECT_OPERATOR in RateArticle.php on line 21:
if $wgArticle->getTitle()->mNamespace != 0) return $out; Razool 09:11, 30 March 2009 (UTC)

Are you missing one "(" and the "{" "}" ? (I have no clue what T_OBJECT_OPERATOR means)
if ($wgArticle->getTitle()->mNamespace != 0) {return $out; } AndiRay 11:34, 4 May 2009 (UTC)

Display errorEdit

It is almost not possible to install the extension with the explainations given on this site or leerwiki...
I only managed that it displays something ,not working, that looks like this:

Currently 0.00/5
1536 Rating: 0.0/5 (0 votes cast)

If anyone knows how to fully install this extension I would be glad to read it.

It might be an Ajax problem check out for ajax.js in your browser's view source. what MW version are you using? or maybe it cannot find the images.Razool 11:58, 8 May 2009 (UTC)
It worked for me on MW 1.14. I don't know what else to say. Try deactivating all other extensions and leave only this one to exclude any interferences. Have you set the $pathtoratings function to point to your Ratings folder in ratearticle.php??And clear your browser's cache and cookies!! It might helpRazool 18:17, 10 May 2009 (UTC)
I had this problem too. The problem is that the path to the Ratings.css is not set correctly. Make sure that $pathToRating in RateArticle.php is set correctly so that the css is accessed. Renareich 20:48, 18 January 2010 (UTC)

I am using 1.13 and I found out how to make it work (when you klick 1 2 3) its in the line 80 from the _drawrating.php (I guess they use a Richeditor, there i had the same problem with the & sign)

$rater.='<li><a href="db.php?j='.$ncount.'&amp;q='.$id.'&amp;t='.$ip.'&amp;c='.$units.'" title="'.$ncount.' out of '.$units.'" class="r'.$ncount.'-unit rater" rel="nofollow">'.$ncount.'</a></li>';

//original line

$rater.='<li><a href="extensions/Ratings/db.php?j='.$ncount.'&q='.$id.'&t='.$ip.'&c='.$units.'" title="'.$ncount.' out of '.$units.'" class="r'.$ncount.'-unit rater" rel="nofollow">'.$ncount.'</a></li>';

//changed line

But still no stars are displayed, so maybe its the $pathToRating as you said (or more & problems in the code). I tryed following without any effect:


And another big problem occured that I can't access my Spezial page anymore, but I dont know after which step this happened :) and how do I clear the cache? AndiRay 07:28, 11 May 2009 (UTC)

I fixed the special page problem and also managed to display the extension on the sites I want, see below. But still no stars :( AndiRay 08:47, 11 May 2009 (UTC)
Does nobody else have this problem? Maybe its a css problem, but i have no idea what exactly. I guess most people dont look in the discussion page of a WikiExtension if they installed it successfully :( AndiRay 07:39, 15 May 2009 (UTC)

There is a hard-coded path near the top of RateArticle.php which looks something like:


That line has to be changed to match the URL you present to your users, or you will not be seeing stars. This is in addition to all of the other hard-coded paths in this extension which are already documented somewhere. --Carlb 06:45, 14 September 2009 (UTC)

I have a similar problem, i tried all above said but does not seem to display the stars. Could anyone tell me how to fix this?

Displaying Ajax on Every site except from...Edit

If you want to display the Ratingstars on every site except from some specific ones and all sites that have 'Diskussion' in the link then look at this ^^
All changes are made in the RateArticle.php in the wfRateArticleForm function.

function wfRateArticleForm(&$out) {
	global $wgArticle,$pathToRating;
	if ($wgArticle == null) return $out;	
	$pagesToRate = array(NS_MAIN,100,102,104,106,108,110,112,114,2);//NamespaceID's where to display the RatingStars
	if (!in_array($wgArticle->getTitle()->getText(), $pagesToRate)) return $out;
	$out->mBodytext.='<script type="text/javascript" language="javascript" src="'.$pathToRating.'js/behavior.js"></script>';
	$out->mBodytext.='<script type="text/javascript" language="javascript" src="'.$pathToRating.'js/rating.js"></script>';
	$out->mBodytext.='<link rel="stylesheet" type="text/css" href="'.$pathToRating.'css/rating.css" />';

 # Checking if action=edit... so that it doesn't show on edit pages
    global $wgRequest;
    if ($wgRequest->getVal('action')!='edit') $action = false;

# Use wgTitle if title is not specified
    if ($title==null) {
        global $wgTitle;
        $title = $wgTitle;

#Needed to search trough the link
    $mystring = $wgTitle;
    $findme1 = 'Diskussion';
    $findme2 = 'talk';
    $pos1 = strpos($mystring, $findme1);//here the programm checks if 'Diskussion' is found in the link... if not the value is set to false
    $pos2 = strpos($mystring, $findme2);

#$wgTitle != 'Hauptseite' //defines that it should NOT display on the site with the name 'Hauptseite'
if($wgTitle != 'Hauptseite' && $wgTitle != 'Unternehmen:Portal'
				    && $wgTitle != 'PM:PM-Portal'
				    && $wgTitle != 'Marketing:Marketing-Portal'
				    && $wgTitle != 'Vertrieb:Vertriebs-Portal'
				    && $wgTitle != 'Marketing:Leistungsbeschreibungen') 	
     if ($pos1 === false && $pos2 === false && $action === false){//if the value is false then it displays the Ratingstars, if it's true then it won't
return $out;


If I forgot something or whatever please ask. PS: everything that is german you can change of course ^^ AndiRay 09:17, 11 May 2009 (UTC)

which is the code to enter if I do not want the stars appear on the Mainpage? 12:32, 12 aug 2010 (UTC)

Ratings not refreshingEdit

Similar to #Hello and thanks for your extension above, I was able to install this after fixing all the things that are not mentioned in the instructions but which this page helps fix, but after rating a page on my wiki (on an intranet), revisting that page does not show the updated rating (i.e. it shows 0 votes). I can "work around" this by adding ?action=purge to the end of the URL to purge the cache, but is there some way to do this automatically when a vote occurs? I can't expect my users to know how to do this. A response refers to a forum, but the site is not in English, so I don't know how to find the answer. --DavidBiesack 19:26, 26 May 2009 (UTC)

This is buggy...Edit

Tried this extension on a MW1.16alpha site, Special:RatingOverview quickly looks like:

Position	Title	Value	Total Votes
1	Object id #132	0	0
2	Object id #130	0	0
3	Object id #132	0	0
4	Object id #130	0	0
5	Object id #132	0	0
275	Object id #130	0	0

The titles are all rubbish "Object id #130, 132" values and the database is rapidly flooded with hundreds of `ratings` entries for every page viewed, even if they never received even one vote up or down. Aesthetically, the data could've been displayed much less obtrusively on the individual pages too (this should be in the sidebar, with much smaller symbols for the stars, instead of 'kludged' onto the bottom of each page).

As there is no pagination and no means of limiting the number of table entries displayed at once on the Special:RatingOverview page (as currently implemented) it very rapidly grows very long... especially since there is one entry for every unique page to have ever been viewed since the extension was installed, votes or no votes. On a large wiki, one can rack up several thousand lines of naughts in short order and for no good end.

I also don't like that this is making database writes for every page view - even for anon-IP visitors, even if nothing is changed and no vote is cast. For large sites, a database write costs far more than a read, as it must wait for other writes in progress to complete and as any site large enough to have master/slave MySQL servers can read from any but must write (via the master) to all to update any database record. --Carlb 08:02, 14 September 2009 (UTC)

Once an page has been voted on, another user cannot vote on itEdit

I think I've set up the extension properly, but whenever a page is voted on by one user, other users can no longer vote for it. Has anybody else experienced this issue? If so, how do you fix it?-- 20:00, 13 August 2009 (UTC)

Is your wiki behind a Squid, Varnish or other reverse cache? If so, the extension may be seeing the address of your server's cache instead of the X-Forwarded-For IP of the actual user - so everyone appears to be coming from the same address(es). The extension, instead of being called from MediaWiki code (which would have checked $wgSquidServers to remove the addresses of your server's reverse proxies) is run directly from the target page, obtaining the "remote IP" at various points using
Similar codes exist in all of db.php, rpc.php and _drawrating.php; any fix would require patching every one of these files.




else if (isset($_SERVER["HTTP_CLIENT_IP"]))
    $ip = $_SERVER["HTTP_CLIENT_IP"];
    $ip = $_SERVER["REMOTE_ADDR"];

Don't do this unless your server configuration requires it - if you're not behind a server-side reverse proxy, the patch will only make it easier to falsify the IP address by submitting nonsense in the X-forwarded_for header. This code does not distinguish between a trusted local proxy (as listed in $wgSquidServers or $wgSquidServersNoPurge) and an untrusted external server.

Nonetheless, without the patch I'm seeing *everything* come in from, the non-routeable address of a local Varnish cache on one of the web servers. That sort of error could be a serious bug for all but the smallest sites. :( --Carlb 06:49, 14 September 2009 (UTC)

This is everything, but not stable.Edit

Is not stable, period.

Installation is a hassle if it works at all.

Tried hard on Mediawiki 1.15 but gave up, even after recoding some lines... 17:12, 12 October 2009 (UTC)

Control rating on per registered wiki userEdit

A very good extension! However, I have one question. Similar to #Once an page has been voted on, another user cannot vote on it. Any way to control rating on per registered wiki user? I have disable anonymous access to my wiki which everyone required to login to view any page (except login page). Thanks! --Kevin

If it has a display errorEdit

Try to load RatingArticle.php after all other extensions were loaded. In other words, put require_once("extensions/Ratings/RateArticle.php") after all similar require_once(). it works on me. --Dullmau 20:43, 9 June 2010 (UTC)

Database DesignEdit

What field needs to be auto incremented? Tell me it's not the 'id', because you can't auto increment a VARCHAR field. I'm under the assumption that it is none , and notation needs to be removed.

Also for MySQL the "TYPE" should be replaced with "ENGINE"?

The table(s) prefix, if exists, needs to be added here and in the code.

CREATE TABLE `ratings` (
`total_votes` INT(11) NOT NULL DEFAULT '0',
`total_value` INT(11) NOT NULL DEFAULT '0',
`used_ips` longtext,

-- ixasilent 19:53, 10 June 2011 (UTC)

How many ratings per page are possible?Edit

How many ratings per page are possible? Maybe if i try to rate several things on one page oder different "parts" of the article. -- 14:22, 1 August 2011 (UTC)

Moving the Rating BarEdit

Any way to move it to a specific spot on a page? Having it at the very bottom is inconvenient.

Return to "AjaxRatingScript" page.