How to port Unobtrusive AJAX Star Rating Bar to MediaWiki

Inleiding

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.

Stappen

Download the AJAX Star Rating Bar script at Masugadesign.com

  • FIRST: Create a file RateArticle.php and put the following text in:
 
<?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.

  • SECOND: Create a directory /Ratings in the extensions Directory. Put the downloaded files from Masugadesign.com in here.
  • THIRD: Put the following SQL query in PhpMyAdmin under the Sql tab, at your Database with the MediaWiki tables. Choose your prefix (in this example it is ratings, but for a clear database your can use for example LeerWikiRatings.)
 
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 ; 
  • FOURTH: Edit the db.php that you put in to Ratings directory.
  • -> 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.

  • FIFTH: Edit the_config-rating.php and put your database data in it. Dont forget to put in the right prefix for your database.
  • SIXTH AND ALMOST LAST:

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', <nowiki><i></nowiki>)"; </i>
$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 
  • SEVENTH

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'); 
} 
} 
  • EIGHT AND FINAL STEP

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 

Tips

  • When you want to renew the Rating on a Wikipage you have to clear the cache of a Wiki site. This is tricky, you have to use this commando after the URL: &action=purge which should be in HTML code: &action=purge

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/> 

Handige links


! Dit artikel is eigendom van de auteur Peter. Gebruik van deze informatie is niet toegestaan zonder toestemming van deze auteur. Raadpleeg onze Algemene Voorwaarden voor meer informatie of neem contact op met de auteur.
Antwoord niet gevonden?
Aangepast zoeken
Gerelateerde artikelen
Beoordelen
+
Beoordeling
  • Criterium:De mate waarin de informatie:
    • VolledigheidAntwoord geeft op titel en inleiding
    • BetrouwbaarheidCorrect en betrouwbaar is
    • DiepgangDetails en diepgang bevat
    • LeesbaarheidLogisch en overtuigend is gestructureerd
    • TaalgebruikLeesbaar en taaltechnisch correct is
    • DesignGrafisch mooi oogt
Uw
waardering
?
-
Reacties
#
01-01-1970
01:00
De reactie zal worden weergegeven na goedkeuring.
Er zijn nog geen reacties. Wij nodigen u graag uit op dit artikel te reageren.
Reageren
  • Velden met * zijn verplicht.
  • Uw emailadres zal niet openbaar worden gemaakt