User:Glycerine102/ratingbar.php

";		return $output;	} 	// IF THE USER WANTS TO DISPLAY WHO VOTED FOR ONE PAGE	if( isset( $argv['idpage'] ) && isset( $argv['displayvoters'] ))	{		$page_id=mysql_real_escape_string($argv['idpage']);		// Check if the user has the right to list all voters for one page		if ( !$allow_display_voters_for_one_page) return 'Sorry, you are not allowed to list the users who voted for this page. ';		// If a number of items is specified		if( isset( $argv['numberofitems'] ) )	{			$numberofitems = intval($argv['numberofitems']);		} else {			$numberofitems = 0;		}		// Check if we don't display more items than the maximum numbers of items allowed by the administrator.		if ( ( $max_items != 0 && $numberofitems > $max_items ) || $numberofitems <= 0) $numberofitems = $max_items;		// Check if there is a specified period of time		if( isset( $argv['numberofdays'] ) )	{			$numberofdays = intval($argv['numberofdays']); $starttime = time - ( $numberofdays * 24 * 60 * 60 ); } else { $starttime = 0; }		// Do query if ( $numberofitems > 0 ) $query = mysql_query("SELECT users.user_name, ratingbar.rating, ratingbar.time, users.user_id FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar, ".$ratingbar_dbname.".".$user_tablename." users WHERE page_id='".$page_id."' AND ratingbar.time >= ".$starttime." AND ratingbar.user_id = users.user_id GROUP BY ratingbar.user_id ORDER BY time DESC LIMIT 0, ".$numberofitems.";") or die("Error: ".mysql_error." on line ".__LINE__); else $query = mysql_query("SELECT users.user_name, ratingbar.rating, ratingbar.time, users.user_id FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar, ".$ratingbar_dbname.".".$user_tablename." users WHERE page_id='".$page_id."' AND ratingbar.time >= ".$starttime." AND ratingbar.user_id = users.user_id GROUP BY ratingbar.user_id ORDER BY time DESC ;") or die("Error: ".mysql_error." on line ".__LINE__); // Display the title $output = ""; if ( $displaytitle ) $output .= 'Voters for '.$page_id.''; // Display the table $output .= " "; return $output; } 	// IF THE USER WANTS TO DISPLAY THE TOP VOTERS if( isset( $argv['topvoters'] ) )	{ $topvoters = intval($argv['topvoters']); // Check if we don't display more items than the maximum numbers of items allowed by the administrator. if ( ( $max_items != 0 && $topvoters > $max_items ) || $topvoters <= 0) $topvoters = $max_items; // Check if there is a specified period of time if( isset( $argv['numberofdays'] ) )	{ $numberofdays = intval($argv['numberofdays']); $starttime = time - ( $numberofdays * 24 * 60 * 60 ); } else { $starttime = 0; }

// Query if ( $category == "" ) { if ( $topvoters > 0 ) $query = mysql_query("SELECT users.user_name, avg(rating) average, count(*) cnt, users.user_id FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar, ".$ratingbar_dbname.".".$user_tablename." users WHERE ratingbar.time >= ".$starttime." AND ratingbar.user_id = users.user_id GROUP BY ratingbar.user_id ORDER BY count(rating) DESC LIMIT 0, ".$topvoters.";") or die("Error: ".mysql_error." on line ".__LINE__); else $query = mysql_query("SELECT users.user_name, avg(rating) average, count(*) cnt, users.user_id FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar, ".$ratingbar_dbname.".".$user_tablename." users WHERE ratingbar.time >= ".$starttime." AND ratingbar.user_id = users.user_id GROUP BY ratingbar.user_id ORDER BY count(rating) DESC ;") or die("Error: ".mysql_error." on line ".__LINE__); } else { if ( $topvoters > 0 ) $query = mysql_query("SELECT users.user_name, avg(rating) average, count(*) cnt, users.user_id FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar, ".$ratingbar_dbname.".".$user_tablename." users, ".$ratingbar_dbname.".".$categorylinks_tablename." categorylinks WHERE categorylinks.cl_to = '".$category."' AND categorylinks.cl_sortkey = ratingbar.page_id AND ratingbar.time >= ".$starttime." AND ratingbar.user_id = users.user_id GROUP BY ratingbar.user_id ORDER BY count(rating) DESC LIMIT 0, ".$topvoters.";") or die("Error: ".mysql_error." on line ".__LINE__); else $query = mysql_query("SELECT users.user_name, avg(rating) average, count(*) cnt, users.user_id FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar, ".$ratingbar_dbname.".".$user_tablename." users, ".$ratingbar_dbname.".".$categorylinks_tablename." categorylinks WHERE categorylinks.cl_to = '".$category."' AND categorylinks.cl_sortkey = ratingbar.page_id AND ratingbar.time >= ".$starttime." AND ratingbar.user_id = users.user_id GROUP BY ratingbar.user_id ORDER BY count(rating) DESC ;") or die("Error: ".mysql_error." on line ".__LINE__); }		// Display the title $output = ""; if ( $displaytitle ) { $output .= ''; if ( $topvoters > 0 ) $output .= 'Top '.$topvoters.' voters '; else $output .= 'Top voters '; if ( $starttime != 0 ) { if ( $numberofdays == 1 ) $output .= 'over the last 24 hours'; if ( $numberofdays > 1 ) $output .= 'over the last '.$numberofdays.' days'; } else { $output .= 'all time'; }			$output .= ''; }		// Display the table $output .= " "; return $output; } 	// IF THE USER WANTS TO DISPLAY THE TOP RATED PAGES if( isset( $argv['numberofitems'] ) and !isset( $argv['user'] ) )	{ $numberofitems = intval($argv['numberofitems']); // Check if we don't display more items than the maximum numbers of items allowed by the administrator. if ( ( $max_items != 0 && $numberofitems > $max_items ) || $numberofitems <= 0) $numberofitems = $max_items; // Check if there is a specified period of time if( isset( $argv['numberofdays'] ) && $argv['numberofdays'] > 0)	{ $numberofdays = intval($argv['numberofdays']); $starttime = time - ( $numberofdays * 24 * 60 * 60 ); } else { $starttime = 0; }		// Check if there is enough votes to display the votes if( isset( $argv['minimumvotenumber'] ) )	{ $minimumvotenumber = intval($argv['minimumvotenumber']); } else { $minimumvotenumber = 0; }		// Check if the user wants to display the number of votes if( isset( $argv['hidenumberofvotes'] ) )	{ $hidenumberofvotes = true; } else { $hidenumberofvotes = false; }		// Query if ( $category == "" ) $query = mysql_query("SELECT avg(rating) average, page_id, count(*) cnt FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` WHERE time >= ".$starttime." GROUP BY page_id HAVING count(*) >= ".$minimumvotenumber." ORDER BY avg(rating) DESC LIMIT 0, ".$numberofitems.";") or die("Error: ".mysql_error." on line ".__LINE__); else $query = mysql_query("SELECT avg(ratingbar.rating) average, ratingbar.page_id, count(*) cnt FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar, ".$ratingbar_dbname.".".$categorylinks_tablename." categorylinks WHERE categorylinks.cl_to = '".$category."' AND categorylinks.cl_sortkey = ratingbar.page_id AND ratingbar.time >= ".$starttime." GROUP BY ratingbar.page_id HAVING count(*) >= ".$minimumvotenumber." ORDER BY avg(ratingbar.rating) DESC LIMIT 0, ".$numberofitems.";") or die("Error: ".mysql_error." on line ".__LINE__); // Display the title $output = ""; if ( $displaytitle ) { $output .= ''; if ( $starttime != 0 ) { if ( $numberofdays == 1 ) $output .= 'Last 24 hours'; if ( $numberofdays > 1 ) $output .= 'Last '.$numberofdays.' days'; } else { $output .= 'All time'; }			$output .= ' (Top '.$numberofitems.')'; $output .= ''; }		// Display the table $output .= " "; return $output; } 	// IF THE USER WANTS TO DISPLAY A USER'S VOTES if( isset( $argv['user'] ) )	{ $user = $argv['user']; // If a number of items is specified if( isset( $argv['numberofitems'] ) )	{ $numberofitems = intval($argv['numberofitems']); } else { $numberofitems = 0; }		// Check if we don't display more items than the maximum numbers of items allowed by the administrator. if ( ( $max_items != 0 && $numberofitems > $max_items ) || $numberofitems <= 0) $numberofitems = $max_items; // If a number of items is specified if( isset( $argv['displaytimestamp'] ) )	{ $displaytimestamp = true; } else { $displaytimestamp = false; }		// Check if there is a specified period of time if( isset( $argv['numberofdays'] ) )	{ $numberofdays = intval($argv['numberofdays']); $starttime = time - ( $numberofdays * 24 * 60 * 60 ); } else { $starttime = 0; }		// Check if the administrator allows user vote listing. if ( !$allow_display_user_votes ) return 'Sorry, the administrator has disabled user\'s vote listing. ';		if ( $allow_display_user_own_votes_only && $user!= $user_name ) return 'Sorry, you are not allowed to see another user\'s votes. ';		$user_name = $user; // Does the user exist? $query = mysql_query("SELECT user_id FROM ".$ratingbar_dbname.".".$user_tablename." WHERE user_name='".$user_name."';") or die("Error: ".mysql_error." on line ".__LINE__); if ( mysql_num_rows($query) == 0 ) return 'The user '.$user_name.' doesn\'t exist.'; $line = mysql_fetch_array($query); $uid = $line[0]; // Query if ( $category == "" ) { if ( $numberofitems > 0 ) $query = mysql_query("SELECT ratingbar.page_id, ratingbar.rating, ratingbar.time, ratingbar.user_id FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar WHERE user_id=".$uid." AND time >= ".$starttime." ORDER BY rating DESC LIMIT 0, ".$numberofitems.";") or die("Error: ".mysql_error." on line ".__LINE__); else $query = mysql_query("SELECT page_id, rating, time, user_id FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar WHERE user_id=".$uid." AND time >= ".$starttime." ORDER BY rating DESC;") or die("Error: ".mysql_error." on line ".__LINE__); } else { if ( $numberofitems > 0 ) $query = mysql_query("SELECT ratingbar.page_id, ratingbar.rating FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar, ".$ratingbar_dbname.".".$categorylinks_tablename." categorylinks WHERE categorylinks.cl_to = '".$category."' AND categorylinks.cl_sortkey = ratingbar.page_id AND ratingbar.user_id=".$uid." AND ratingbar.time >= ".$starttime." ORDER BY ratingbar.rating DESC LIMIT 0, ".$numberofitems.";") or die("Error: ".mysql_error." on line ".__LINE__); else $query = mysql_query("SELECT ratingbar.page_id, ratingbar.rating, ratingbar.time, ratingbar.user_id FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` ratingbar, ".$ratingbar_dbname.".".$categorylinks_tablename." categorylinks WHERE categorylinks.cl_to = '".$category."' AND categorylinks.cl_sortkey = ratingbar.page_id AND ratingbar.user_id=".$uid." AND ratingbar.time >= ".$starttime." ORDER BY ratingbar.rating DESC;") or die("Error: ".mysql_error." on line ".__LINE__); }		// Display the title $output = ""; if ( $displaytitle ) { $output = MakeLinkUser($line['user_id'], $user_name); $output = "".$output."'s votes"; }		$output .= " "; return $output; } 	return 'Something\'s wrong is your parameters. '; }

// The callback function for converting the input text to HTML output function render_w4g_ratingbar( $input, $argv, $parser ) { // Check if there isn't any other rating bar on the same page global $alreadyratingbar; if ( $alreadyratingbar ) return 'You can\'t display over 1 rating bar on the same page. ';	$alreadyratingbar = true; // Global object variables global $wgUser;		// For $wgUser->getID; global $wgOut;		// For $wgOut->getPageTitle; global $wgScriptPath; /* sdc 14 Apr 2009 */ // Get some variables require ( dirname( __FILE__ ) . '/config.php'); // Add CSS and Javscript $parser->mOutput->addHeadItem(''); /* sdc 14 Apr 2009 */ $parser->mOutput->addHeadItem(''); $parser->mOutput->addHeadItem(' '); /* sdc 14 Apr 2009 */ // Gets $page_id if( isset( $argv['idpage'] ) && '' != $argv['idpage'] )	{ $page_id = $argv['idpage']; } else { $page_id = $parser->getTitle; }	// Cleans $page_id for not breaking GET queries $page_id_js=str_replace("U","Ux55",$page_id); $page_id_js=mysql_real_escape_string(str_replace($stupid_characters,$stupid_characters_codes,$page_id_js)); // Cleans $page_id for use in MySQL queries - DO NOT confuse with $page_id_js afterwards! $page_id=mysql_real_escape_string($page_id); // Get rating bar style $w4g_rb_bar_styles = isset($w4g_rb_bar_styles) ? $w4g_rb_bar_styles : array("gradbar", "stars"); $w4g_rb_barstyle = (isset($argv['style'])) ? mysql_real_escape_string($argv['style']) : "gradbar"; if( !in_array($w4g_rb_barstyle, $w4g_rb_bar_styles) ) $w4g_rb_barstyle = $w4g_rb_bar_styles[0]; // === TEMPORARY: DISABLE stars STYLE === //$w4g_rb_barstyle = "gradbar"; // Initiating some variables $output=""; $user_rating=0; $ip = $_SERVER['REMOTE_ADDR']; // What's the current rating? $query = mysql_query("SELECT AVG(rating) FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` WHERE page_id='".$page_id."';") or die("Error: ".mysql_error." on line ".__LINE__); $line = mysql_fetch_array($query); $average_rating = intval($line[0]); $output .= ''; // Open the AJAX field $output .= 'Current user rating: '.$average_rating.'% '; // How many users voted? $query = mysql_query("SELECT count(*) FROM `".$ratingbar_dbname."`.`".$ratingbar_tablename."` WHERE page_id='".$page_id."';") or die("Error: ".mysql_error." on line ".__LINE__); $line = mysql_fetch_array($query); $output .= '('.$line[0].' votes) '; $output .= ' '; // Close the AJAX field // You MUST leave the line breaks in $output as they are, otherwise MediaWiki won't be able to display the rating bar in a table. (Parsing error: a tag will otherwise be added AFTER , causing trouble) $output .= '  //<![CDATA[ var average_rating='.$average_rating.'; var user_rating=0; var pid="'.$page_id_js.'"; var base_query_url="'.$wgScriptPath.'/extensions/RatingBar/doqueries.php";  /* sdc 14 Apr 2009 */ query2page(base_query_url+"?act=load\x26pid="+pid,"w4g_rb_area",2,"'.$w4g_rb_barstyle.'"); var query_url = base_query_url+"?pid="+pid; //]]> ';

switch ($w4g_rb_barstyle) {	case "stars": $output .= ' <span class="w4g_rb_nojs"> You need to enable Javascript to vote <script type="text/javascript"> //<![CDATA[ loadStars("w4g_rb_starbox1"); updateStars("w4g_rb_starbox1",average_rating); //]]> ';		break; case "stars_old": $output .=' <div id="unit_long1"> <ul id="unit_ul1" class="unit-rating" style="width:150px;"> <li class="current-rating" style="width:109px;">Currently 3.64/5</li>'; for($i=1;$i<=5;$i++) {		$output.='<li><a onclick="user_rating='.intval($i*20).';query2page(\''.$path_to_w4g_rb.'doqueries.php?pid='.$page_id_js.'&vote='.intval($i*20).'\',\'w4g_rb_area\')" title="'.$i.' out of 5" class="r'.$i.'-unit rater" rel="nofollow">'.$i.'</a></li>'; }	$output .='</ul> ';		break; default: case "gradbar": $output .=' <div id="rating_box"> <div id="rating_target" onmouseout="updatebox(\'rating_target\',user_rating)"><span class="w4g_rb_nojs"> You need to enable Javascript to vote <div id="rating_text"> <script type="text/javascript"> //<![CDATA[ loadbox("rating_target"); updatebox("rating_target",average_rating); //]]> ';		break; }

return $output; } ?>