How to get rating script work

Inleiding

This manual will guide you shortly through getting the Ajax Script to work in Mediawiki 1.10.0

reference How to port Unobtrusive AJAX Star Rating Bar to MediaWiki

Download the AJAX Star Rating Bar script at Masugadesign.com

Stappen

Install Xampp

I used the latest Xampp Version from at apachefriends.org

Install MediaWiki

I used the latest MediaWiki Version from at mediawiki.org

I used for Installation folder wiki directly in the htdocs folder.

Prepare Database

Create the Database table ratings in the mediawiki database as explained at this wiki.

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 ;

For each rating a row will be created in this database.

Customize in includes/Skintemplate.php

To show the rating bar, replace the following code:

$tpl->set( 'bottomscripts', $this->bottomScripts() ); 
$printfooter = "<div>\n" . $this->printSource() . "</div>\n";
<p>$out->mBodytext .= $printfooter&#160;;
</p>

with

$tpl->set( 'bottomscripts', $this->bottomScripts() ); 
//### START RATING ###############
if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0&#160;!= $wgArticle->getID() ) 
{	
$AID=$wgArticle->getID();	
wfRunHooks( 'AfterArticleDisplayed', array( &$DIVRATING,&$AID));
}
else
{
$DIVRATING=<i>;}$printfooter =  $DIVRATING."<div>\n" . $this->printSource() . "</div>\n";</i>
<p>//#### END RATING ################
$out->mBodytext .= $printfooter&#160;;
</p>

to include the rating bar.

Customization of the rating bar Script files

in RateArticle.php ...

you should customize the rating script to local language installation of your wiki. The following Array describes the pages where the rating bar Script don't appear:

<?php
require('Ratings/_drawrating.php'); 
if (&#160;! defined( 'MEDIAWIKI' ) )
	die();

$wgExtensionCredits['other'][] = array(
'name' => 'AJAX RATING BAR',
'author' => 'Boudewijn Vahrmeijer',
'url' => 'http://www.leerwiki.nl',
'version' => 'for 1.9.3/1.9.2/1.8.2',
);

if ($DisableCache) {
        global $wgVersion;

        $dbr =& wfGetDB( DB_SLAVE );

        # Do not cache this wiki page.
        # for details see http://public.kitware.com/Wiki/User:Barre/MediaWiki/Extensions
        global $wgTitle, $wgDBprefix;
        $ts = mktime();
        $now = gmdate("YmdHis", $ts +120);
        $ns = $wgTitle->getNamespace();
        $ti = $dbr->addQuotes($wgTitle->getDBkey());

        $version = preg_replace("/^([1-9]).([1-9]).*/", "\\1\\2", $wgVersion);
        $sql = "UPDATE $wgDBprefix" . "page SET page_touched='$now' WHERE page_namespace=$ns AND page_title=$ti";

        $dbr->query($sql, __METHOD__);
}
    
$wgHooks['AfterArticleDisplayed'][] = array("wfRateArticleForm");
function wfRateArticleForm($DIVRATING,$AID) {
	global $wgArticle, $out;
	 global $wgVersion;

        $dbr =& wfGetDB( DB_SLAVE );

        # Do not cache this wiki page.
        # for details see http://public.kitware.com/Wiki/User:Barre/MediaWiki/Extensions
        global $wgTitle, $wgDBprefix;
        $ts = mktime();
        $now = gmdate("YmdHis", $ts +120);
        $ns = $wgTitle->getNamespace();
        $ti = $dbr->addQuotes($wgTitle->getDBkey());

        $version = preg_replace("/^([1-9]).([1-9]).*/", "\\1\\2", $wgVersion);
        $sql = "UPDATE $wgDBprefix" . "page SET page_touched='$now' WHERE page_namespace=$ns AND page_title=$ti";

        $dbr->query($sql, __METHOD__);

	if ($wgArticle==null) return;	
	$URLRIGHTPART= $_SERVER['REQUEST_URI'];
	$Exceptions=array(Template,Discussion,Sidebar,Category,Mainpage,Help,'action=edit');|
	$tot=0;
	for($i=1;$i<count($Exceptions);$i++){
	if(substr_count($URLRIGHTPART,$Exceptions[$i])==1){$tot=1;break;};
	}

	if($tot==0)
	{
	$DIVRATING=rating_bar($AID,5);
	}
	

}
?>

in _config-rating.php ...

you have to fill in the database connection information, which can also be found in the LocalSettings.php

in _drawrating.php ...

you have to customize the refresh-function to your Servers (IP)address and the rating request for the user, shown above the rating bar:

<?php
/*
Page:           _drawrating.php
Created:        Aug 2006
The function that draws the rating bar.	
<hr /> 
<p>ryan masuga, masugadesign.com
ryan@masugadesign.com 
</p>
<hr /> */
<p>function rating_bar($id,$units=<i>) { </i>
</p><p>require('_config-rating.php'); // get the db connection info
</p><p>//set some variables
$ip = $_SERVER['REMOTE_ADDR'];
if (!$units) {$units = 10;}
</p><p>$query=mysql_query("SELECT total_votes, total_value, used_ips FROM $tableName WHERE id='$id' ")or die(" Error: ".mysql_error());
$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', <i>)";</i>
$result = mysql_query($sql);
}
</p><p>$numbers=mysql_fetch_assoc($query);
$count=$numbers['total_votes']; //how many votes total
$current_rating=$numbers['total_value']; //total number of rating added together and stored
$tense=($count==1)&#160;? "vote"&#160;: "votes"; //plural form votes/vote
</p><p>// determine whether the user has voted, so we know how to draw the ul/li
$voted=mysql_num_rows(mysql_query("SELECT used_ips FROM $tableName WHERE used_ips LIKE '%".$ip."%' AND id='".$id."' ")); 
</p><p>// now draw the rating bar
</p><p>//$RatOP='<script type="text/javascript" language="javascript" src="extensions/Ratings/js/behavior.js"></script>';
//$RatOP.='<script type="text/javascript" language="javascript" src="extensions/Ratings/js/rating.js"></script>';
</p>
$RatOP.='<link rel="stylesheet" type="text/css" href="extensions/Ratings/css/rating.css" />';
$RatOP.='<div class="ratingblock"><div id="unit_long.27.3B_.24RatOP..3D.24id.3B_.23Change_message_to_your_language:_.24RatOP..3D.27"><h2>Vote for the Quality of this article!</h2><ul id="unit_ul.27.3B_.24RatOP..3D.24id.3B_.24RatOP..3D.27" class="unit-rating" style="width:&#039;; $RatOP.=$unitwidth*$units; $RatOP.=&#039;px;"><li class="current-rating" style="width:&#039;; $RatOP.=@number_format($current_rating/$count,2)*$unitwidth; $RatOP.=&#039;px;">Currently'; 
<p>$RatOP.=@number_format($current_rating/$count,2); 
$RatOP.='/';
$RatOP.=$units;
</p>
$RatOP.='</li>';
<p>for ($ncount = 1; $ncount <= $units; $ncount++) { // loop from 1 to the number of units
		if(!$voted) { // if the user hasn't yet voted, draw the voting stars 
</p>
$RatOP.='<li><a href="javascript:location.replace(\'extensions/Ratings/db.php?url=';
$RatOP.=$LASTURL;
$RatOP.='&j=';
$RatOP.=$ncount;
$RatOP.='&q=';
$RatOP.=$id;
$RatOP.='&t=';
$RatOP.=$ip;
$RatOP.='&c=';
$RatOP.=$units;
$RatOP.='\')" title="';
$RatOP.=$ncount;
$RatOP.='out of ';
$RatOP.=$units;
$RatOP.='" class="r';
$RatOP.=$ncount;
$RatOP.='-unit rater">';
$RatOP.=$ncount;
$RatOP.='</a></li>';
<p>	 } 
  }
	$ncount=0; // resets the count
</p>
$RatOP.='</ul><p>';
<p>$RatOP.='<strong> ';
$RatOP.=@number_format($current_rating/$count,1);
$RatOP.='</strong>/';
$RatOP.=$units;
$RatOP.=' (';
$RatOP.=$count.' '.$tense;
</p>
<ol><li>Change to your own Adress:
</li></ol>
$RatOP.= ' cast)</p><a href="http://www.leerwiki.nl';
<p>if(substr_count($LASTURL,'action=purge')==0){
$RatOP.=$LASTURL.'&'.'amp;amp;action=purge';
} 
else {
$RatOP.=str_replace('&','&amp;',$LASTURL);
}
</p>
$RatOP.='">refresh</a></div></div>';
<p>return($RatOP);
</p><p>}
</p><p>?>
</p>

Customization in LocalSettings.php

Using the default installation settings in this example it is important to use for the short url $wgArticlePath = "$wgScript?title=$1";.

Probably the Xampp module runs PHP as CGI Module as in the LocalSettings.php from lower mediawiki Installation is explained.

## The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
$wgScriptPath       = "/wiki";
$wgScript = "$wgScriptPath/index.php";
		
## For more information on customizing the URLs please see:
## http://www.mediawiki.org/wiki/Manual:Short_URL
$wgArticlePath = "$wgScript?title=$1";

Using $wgArticlePath = "$wgScript?$1"; the rating Script won't work. The pages are not shown. Because the index.php file is not loaded automatically.

To use the Code as explained in other articles in this wiki you have to configure your apache for short url. Several configurations are explained at wikimedia.org

Reacties (0)

Reageer
Geen resultaten gevonden