Wikistats/Update scripts

-->Wikistats->Update scripts

to be called from the commandline like

php update_wikipedias.php

Wikipedias
<?php
 * 1) Wikistats by mutante - 2006-02-08 - S23 Wiki - http://s23.org

ini_set('user_agent','http://s23.org/wikistats/ | http://meta.wikimedia.org/wiki/User:mutante | mutante@s23.org');
 * 1) set user agent

require_once("config.php");
 * 1) include config

mysql_connect("$dbhost", "$dbname", "$dbpass") or die(mysql_error); echo "Wikistats Updater by S23-mutante \n Connected to MySQL. \n";
 * 1) connect db

mysql_select_db("wikistats") or die(mysql_error); echo "Selected database 'wikistats' \n.";
 * 1) select db

$query = "select * from wikipedias order by good asc"; $result = mysql_query("$query") or die(mysql_error); echo "Sent query: '$query'.\n";
 * 1) select all ordered by good

while($row = mysql_fetch_array( $result )) { if ($row['prefix']!="") { $url="http://".$row['prefix'].".wikipedia.org/wiki/Special:Statistics?action=raw"; $remotefile=fopen("$url","r");
 * 1) main loop

if (!$remotefile) { echo "Unable to open remote file $url \n"; fclose ($remotefile); } else { echo "Ok opening $url \n"; $buffer = fgets($remotefile); echo "Buffer: $buffer"; $pieces = explode(";",$buffer); $total = explode("=",$pieces[0]); $total = $total[1]; $good = explode("=",$pieces[1]); $good = $good[1];

if ($good>2147483647) { $good=0; }
 * 1) bug protection

$views = explode("=",$pieces[2]); $views = $views[1]; $edits = explode("=",$pieces[3]); $edits = $edits[1]; $users = explode("=",$pieces[4]); $users = $users[1]; $admins = explode("=",$pieces[5]); $admins = $admins[1]; $admins = trim($admins); echo "Total: $total Good: $good Views: $views Edits: $edits Users: $users Admins: $admins \n"; $query2="update wikipedias set total=\"$total\",good=\"$good\",views=\"$views\",edits=\"$edits\",users=\"$users\",admins=\"$admins\",ts=NOW where id=\"".$row['id']."\";"; echo "Query: $query2 \n"; $result2 = mysql_query("$query2") or die(mysql_error); echo "Updated MySQL. Return Code: $result2 \n \n"; fclose ($remotefile); } } } mysql_close; echo "Done. Fnord."; ?>

Wikis
<?php ini_set('user_agent','http://s23.org/wikistats/ | http://meta.wikimedia.org/wiki/User:mutante | mutante@s23.org'); require_once("config.php"); mysql_connect("$dbhost", "$dbname", "$dbpass") or die(mysql_error); echo "Wikistats Updater by S23-mutante \n Connected to MySQL. \n";
 * 1) Wikistats by mutante - 2006-02-08 - S23 Wiki - http://s23.org
 * 2) set user agent
 * 1) set user agent
 * 1) connect db

mysql_select_db("wikistats") or die(mysql_error); echo "Selected database 'wikistats' \n."; $query = "select * from wikistats order by id desc";
 * 1) select all order by id descending

$result = mysql_query("$query") or die(mysql_error); echo "Sent query: '$query'.\n";

while($row = mysql_fetch_array( $result )) { if ($row['linktype']=="1") { $url=$row['url']."Special:Statistics&action=raw"; } else { $url=$row['url']."Special:Statistics?action=raw"; } $remotefile=fopen("$url","r");
 * 1) sort out non standard link types

if (!$remotefile) { echo "Unable to open remote file $url \n"; fclose ($remotefile); } else { echo "Ok opening $url \n"; $buffer = fgets($remotefile); echo "\n Buffer: $buffer \n"; $pieces = explode(";",$buffer); $total = explode("=",$pieces[0]); $total = $total[1]; $good = explode("=",$pieces[1]); $good = $good[1]; echo "\n GOOD $good \n"; if ($good>2147483647) { $good=0; } $views = explode("=",$pieces[2]); $views = $views[1]; $edits = explode("=",$pieces[3]); $edits = $edits[1]; $users = explode("=",$pieces[4]); $users = $users[1]; $admins = explode("=",$pieces[5]); $admins = $admins[1]; $admins = trim($admins); echo "Total: $total Good: $good Views: $views Edits: $edits Users: $users Admins: $admins \n"; $query2="update wikistats set total=\"$total\",good=\"$good\",views=\"$views\",edits=\"$edits\",users=\"$users\",admins=\"$admins\" where id=\"".$row['id']."\";"; echo "Query: $query2 \n"; $result2 = mysql_query("$query2") or die(mysql_error); echo "Updated MySQL. Return Code: $result2 \n \n"; fclose ($remotefile); } } mysql_close; echo "Done. Fnord."; ?>

Back to Wikistats