×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    Wikistats/Update scripts

    -->Wikistats->Update scripts


    to be called from the commandline like

    php update_wikipedias.php 
    

    Wikipedias[edit]

    <?php
    # Wikistats by mutante - 2006-02-08 - S23 Wiki - http://s23.org
    #
    
    # set user agent
    ini_set('user_agent','http://s23.org/wikistats/ | http://meta.wikimedia.org/wiki/User:mutante | [email protected]');
    
    # include config
    require_once("config.php");
    
    # connect db
    mysql_connect("$dbhost", "$dbname", "$dbpass") or die(mysql_error());
    echo "Wikistats Updater by S23-mutante \n Connected to MySQL. \n";
    
    # select db
    mysql_select_db("wikistats") or die(mysql_error());
    echo "Selected database 'wikistats' \n.";
    
    # select all ordered by good
    $query = "select * from wikipedias order by good asc";
    $result = mysql_query("$query") or die(mysql_error());
    echo "Sent query: '$query'.\n";
    
    # main loop
    while($row = mysql_fetch_array( $result )) {
    if ($row['prefix']!="") {
    $url="http://".$row['prefix'].".wikipedia.org/wiki/Special:Statistics?action=raw";
    $remotefile=fopen("$url","r");
    
    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];
    
    # bug protection
    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 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[edit]

    <?php
    # Wikistats by mutante - 2006-02-08 - S23 Wiki - http://s23.org
    #
    # set user agent
    ini_set('user_agent','http://s23.org/wikistats/ | http://meta.wikimedia.org/wiki/User:mutante | [email protected]');
    # connect db
    require_once("config.php");
    mysql_connect("$dbhost", "$dbname", "$dbpass") or die(mysql_error());
    echo "Wikistats Updater by S23-mutante \n Connected to MySQL. \n";
    
    mysql_select_db("wikistats") or die(mysql_error());
    echo "Selected database 'wikistats' \n.";
    # select all order by id descending
    $query = "select * from wikistats order by id desc";
    
    $result = mysql_query("$query") or die(mysql_error());
    echo "Sent query: '$query'.\n";
    
    # sort out non standard link types 
    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");
    
    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

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.

    Recent changes

  • BruderSpektrum • 3 months ago
  • BruderSpektrum • 3 months ago
  • BruderSpektrum • 3 months ago
  • BruderSpektrum • 3 months ago
  • Cookies help us deliver our services. By using our services, you agree to our use of cookies.