query->pages->page; if ($page['ns']=="6") { $link = $page->imageinfo->ii['thumburl']; $description=$page->imageinfo->ii['descriptionurl']; $file_added=TRUE; $sql = "INSERT INTO test_images (name, link, description, score) VALUES ('$name','$link','$description',0)"; if (!mysql_query($sql,$db_connection)){} } } } //SQL code to pick a random image $sql = "SELECT * FROM test_images AS r1 JOIN (SELECT (RAND() * (SELECT MAX(id) FROM test_images)) AS id) AS r2 WHERE r1.id >= r2.id ORDER BY r1.id ASC LIMIT 1"; //The two images $image1 = array('id'=>0,'name'=>"",'link'=>"",'description'=>"",'live'=>0); $image2 = array('id'=>0,'name'=>"",'link'=>"",'description'=>"",'live'=>0); //Loop until a image is found that is "live". while($image1['live']==0){ if (!$result1=mysql_query($sql,$db_connection)){} while($row = mysql_fetch_array($result1)){ $image1['id']=floor($row['id'])+1; $image1['name']=$row['name']; $image1['link']=$row['link']; $image1['description']=$row['description']; $image1['live']=$row['live']; } } //Loop until a secont image is found that is different from the first one and also "live" while($image1['id']==$image2['id'] OR $image2['live']==0){ if (!$result2=mysql_query($sql,$db_connection)){} while($row = mysql_fetch_array($result2)){ $image2['id']=floor($row['id'])+1; $image2['name']=$row['name']; $image2['link']=$row['link']; $image2['description']=$row['description']; $image2['live']=$row['live']; } } //Generate a random key for this vote $key = randomString(); //Add this vote to the db $sql = "INSERT INTO `test_votes` (`key`, `image1`, `image2`) VALUES ('$key',$image1[id],$image2[id])"; if (!$result2=mysql_query($sql,$db_connection)){ if ($debug_mode) {die('Error: ' . mysql_error());} } //Find out if this is a report if ($_GET[report]){ $old_key = trim($_GET[key]); $report = trim($_GET[report]); //Find the images voted on $sql = "SELECT * FROM test_votes WHERE `key`='$old_key'"; if (!$result=mysql_query($sql,$db_connection)){} while($row = mysql_fetch_array($result)){ $image1_id=$row['image1']; $image2_id=$row['image2']; } if ($report==1) { $sql = "INSERT INTO `test_reports` (`image`, `reason`) VALUES ('$image1_id',1)"; if (!$result2=mysql_query($sql,$db_connection)){ if ($debug_mode) {die('Error: ' . mysql_error());} } } if ($report==2) { $sql = "INSERT INTO `test_reports` (`image`, `reason`) VALUES ('$image2_id',1)"; if (!$result2=mysql_query($sql,$db_connection)){ if ($debug_mode) {die('Error: ' . mysql_error());} } } } //Find out if this is a vote if ($_GET[vote]){ $old_key = trim($_GET[key]); $vote = trim($_GET[vote]); //Find the images voted on $sql = "SELECT * FROM test_votes WHERE `key`='$old_key'"; if (!$result=mysql_query($sql,$db_connection)){} while($row = mysql_fetch_array($result)){ $image1_id=$row['image1']; $image2_id=$row['image2']; } //Find the scores of those images $sql = "SELECT * FROM test_images WHERE `id`=$image1_id"; if (!$result=mysql_query($sql,$db_connection)){} while($row = mysql_fetch_array($result)){ $image1_score=$row['score']; } $sql = "SELECT * FROM test_images WHERE `id`=$image2_id"; if (!$result=mysql_query($sql,$db_connection)){} while($row = mysql_fetch_array($result)){ $image2_score=$row['score']; } //Calculate expected scores: $image1_expectation = 1/(1+pow(10,$image2_score-$image1_score)); $image2_expectation = 1 - $image1_expectation; //adjust scores if($vote == 1) { $image1_score += $kFactor*(1-$image1_expectation); $image2_score -= $kFactor*$image2_expectation; $sql = "UPDATE `test_stats` SET `left`=`left`+1 WHERE `votes`=1"; if (!$result=mysql_query($sql,$db_connection)){} } if($vote == 2) { $image2_score += $kFactor*(1-$image2_expectation); $image1_score -= $kFactor*$image1_expectation; $sql = "UPDATE `test_stats` SET `right`=`right`+1 WHERE `votes`=1"; if (!$result=mysql_query($sql,$db_connection)){} } //Update scores $sql = "UPDATE `test_images` SET `score`=$image1_score WHERE `id`=$image1_id"; if (!$result=mysql_query($sql,$db_connection)){} $sql = "UPDATE `test_images` SET `score`=$image2_score WHERE `id`=$image2_id"; if (!$result=mysql_query($sql,$db_connection)){} //remove this vote $sql = "DELETE FROM test_votes WHERE `key`='$old_key' OR `time` < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 HOUR)"; if (!mysql_query($sql,$db_connection)){} } ?>
Click on the photo you think is the best one.
'; echo '' . "\n"; ?> '; echo 'SKIP
VOTE' . "\n"; ?>
'; echo '' . "\n"; ?>
Photo description:
' . $image1['name'] . "\n"; ?>
Photo description:
' . $image2['name'] . "\n"; ?>

Succes, added: ' . $name . '
'; } ?>
Add more entries from wikimedia commons:
File name (Including 'File:'):
The Math:
This rating system uses the ELO rating system where for each pair of images an expected score is calculated. The formula for the expected score is 1/(1+10^(image2_score-image1_score)). Then that score is adjusted with a factor and added or subtracted to the winner/loser respectively. The factor used here is .

Problems:
If any photo doesn't show up correctly then please click on the little red triangle next to it and I'll look into it.

Add more photos:
Please do! Just copypaste its filename including the File: part and it'll be automagically added and can be voted for (or against).

Statistics:
Votes:
Images:

Changelog:
Feb 14: Reset db!


' . "\n";; } ?>
Current top five photos:

Contact:
Web site: http://averater.se/
Email: g@averater.se
Facebook: averater
Commons: Averater
Source code:
index.txt functions.txt user_settings.txt
Rename into *.php and change content of the user_settings file.
Database tables: databases.txt