Inhoud |
NEWEST VERSION: WORKING FOR 1.10 and 1.11: http://www.leerwiki.nl/Ajax_script_for_Mediawiki_1.10
DO NOT USE THIS ONE IF YOU HAVE NEWEST VERSION
see for new update for versions >1.8.2 !!
See also How_to_get_rating_script_work if you do not have configured Nice-URL-Formating!!!
If you like the Unobtrusive AJAX Star Rating Bar of Masugadesign.com, and want to put it in MediaWiki, this manual will help you through the porting.
Download the AJAX Star Rating Bar script at Masugadesign.com
<?php
require('Ratings/_drawrating.php');
if ( ! defined( 'MEDIAWIKI' ) )
die();
$wgExtensionCredits['parserhook'][] = array(
'name' => 'AJAX RATING BAR',
'author' => 'B. Vahrmeijer',
'url' => 'http://www.leerwiki.nl',
'version' => 'MW versions < 1.6.7',
);
require_once("SpecialPage.php");
SpecialPage::AddPage(new UnlistedSpecialPage('RateArticle'));
$wgHooks['AfterArticleDisplayed'][] = array("wfRateArticleForm");
//for updates see http://www.leerwiki.nl
function wfRateArticleForm() {
global $wgArticle;
if ($wgArticle == null) return;
$page_id = $wgArticle->getID();
if ($page_id <= 0) return;
echo rating_bar($page_id,5); //HERE ARE YOUR STARS
echo('
<script type="text/javascript" language="javascript" src="Ratings/js/behavior.js">
</script>
<script type="text/javascript" language="javascript" src="Ratings/js/rating.js">
</script>
<link rel="stylesheet" type="text/css" href="Ratings/css/rating.css" />
');
}
?>
Put this file in the extensions directory at the root of the MediaWiki installation.
CREATE TABLE `ratings` ( `id` varchar(11) NOT NULL, `total_votes` int(11) NOT NULL default '0', `total_value` int(11) NOT NULL default '0', `used_ips` longtext, PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=3 ;
--> Add after: $ip = $_SERVER['REMOTE_ADDR'];
the following ie.:
$referer = 'http://yoururl.com'.$_REQUEST['url'].'&action=purge';
this purge is needed for cache clearing in MediaWiki!! Save the file to the FTP.
put the following code somewhere in _drawrating.php above: $numbers=mysql_fetch_assoc($query);
$LASTURL=$_SERVER['REQUEST_URI'];
if (mysql_num_rows($query)==0) {
$sql = "INSERT INTO $tableName (`id`,
`total_votes`, `total_value`, `used_ips`)
VALUES ('$id', '0', '0', '')";
$result = mysql_query($sql);
}
also change the following data:
<li><a href="db.php?j=<?php echo $ncount ?>&q
into:
<li><a href="extensions/Ratings/db.php?url=<?php echo $LASTURL;?>&j=<?php echo $ncount ?>&q
Change in Include/SkinTemplate the following code
function html( $str ) {
echo $this->data[$str];
}
into:
function html( $str ) {
global $wgTitle;
echo $this->data[$str];
$this->mTitle =& $wgTitle;
if ($str == 'bodytext' && $this->mTitle->getArticleID( GAID_FOR_UPDATE )>20) {
wfRunHooks( 'AfterArticleDisplayed');
}
}
Put the following code into LocalSettings.php
require_once("extensions/RateArticle.php");
Now you're finished. for star configurations:
with the following code you can now put stars
<?php rating_bar('1',5); ?> - makes a 5-star rater with ID of 1
<?php rating_bar('2',8); ?> - makes an 8-star rater with ID of 2
<?php rating_bar('4d'); ?> - makes 10-star (default) rater, ID of 4d
in example, for LeerWiki, I use:
<p><a href='http://www.leerwiki.nl
<?php if(substr_count($LASTURL,'action=purge')==0)
{
echo $LASTURL.'&'.'amp;amp;action=purge';
}
else
{
echo str_replace('&','&',$LASTURL);
}
?>
'>refresh</a><p/>