ELSERVER.COM
Acceso a clientes

LegalesLegales

MediaWiki Extension: AJAX Rating


English | Español

This extension was inspired on AjaxRatingScript, found on MediaWiki Extension Matrix. The extension is so horribly implemented that after wasting several hours trying to make it work, I decided to make a new, clean and correct implementation, using MediaWiki hooks instead of hacking the core code.

You can find a working demo at the bottom of this page.

Tabla de contenidos

[editar] Things you’ll need

Spanish wiki users can also get our own spanish version of Ajax Star Rating script, adapted to work on /mediawiki/extensions/Ratings directory.

[editar] Create the table

Create this table on any database.

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;

[editar] Download the script

Download and unpack Ajax rating script into a folder named /extensions/Ratings.

The script's code is not prepared to be invoked from any other directory than where it is placed, so you'll need to adjust some values to make it work on your MediaWiki implementation transparently:

  1. _config-rating.php: Update your MySQL connection info.
  2. _drawrating.php: Prefix your MW full path to db.php. In my case, it would be /mediawiki/extensions/Ratings/db.php
  3. js/rating.js: Prefix your MW full path to rpc.php. In my case, /mediawiki/extensions/Ratings/rpc.php

In order to translate the script to other language you'll have to work with: _drawrating.php, js/rating.js, db.php and rpc.php.

[editar] MediaWiki Extension

Create a file named AjaxRating.php in your /extensions MW directory:

<?
 
# Config
$mwRatingsPath = '/mediawiki/extensions/Ratings/';
 
# Credits
$wgExtensionCredits['parserhook'][] = array(
    'name'=>'AJAX Rating Script (corrected and really unobtrusive)',
    'author'=>'Nicol&aacute;s Alen - nicolas.alen@elserver.com',
    'url'=>'http://www.elserver.com/wiki/MediaWiki_Extension_AJAX_Rating',
    'description'=>'Adds .',
    'version'=>'0.1.1'
);
 
$wgHooks['ParserBeforeTidy'][] = 'myParserBeforeTidy';
function myParserBeforeTidy(&$parser, &$text )
{
	global $action, $mwRatingsPath;
	if ($parser->getTitle()->mNamespace != 0 || $action != "view")
		return;
 
	require_once("Ratings/_drawrating.php");
 
	// Rating HTML
	ob_start();
	?>
	<script type="text/javascript" language="javascript" src="<?=$mwRatingsPath?>js/behavior.js"></script>
	<script type="text/javascript" language="javascript" src="<?=$mwRatingsPath?>js/rating.js"></script>
	<link rel="stylesheet" type="text/css" href="<?=$mwRatingsPath?>css/rating.css" />
	<?=rating_bar($parser->getTitle()->mArticleID,'5','',$mwRatingsPath)?>
	<?
 
	$out = ob_get_contents();
	ob_end_clean();
 
	// Append HTML to pre-tidy wiki HTML
	$text .= $out;
}
 
?>

Change your full path to your MW instalation in:

$mwRatingsPath = '/mediawiki/extensions/Ratings/';

Finally, activate the extension by adding this code in your LocalSettings.php file:

require_once("$IP/extensions/AjaxRating.php");

¿Qué te pareció este artículo?

Esta página fue modificada por última vez el 10:22, 6 jul 2007.

Esta página ha sido visitada 574 veces.

¿Qué te pareció este artículo?