Robson » Code » PHP » Wikipedias By Edits Per Article Updater

 
<?
 
   // this script is used to update the "List of Wikipedias by edits per article" article, located here:
   //     http://meta.wikimedia.org/wiki/List_of_Wikipedias_by_edits_per_article
   // latest version and license info:
   //     http://iceyboard.no-ip.org/projects/code/php/wikipedias_by_edits_per_article_updater/
   // the data file is created by a third-party and is located here:
   //     http://s23.org/wikistats/wikipedias_csv.php
   // if you want to discuss or make suggestions about this script, use my talk page on wikipedia:
   //     http://en.wikipedia.org/wiki/User_talk:Icey
 
   // change log
   // 1.0.0 - First version. Dodgy scripting, because I haven't written any PHP for a while
   // 1.1.0 - Improved the language links
   // 1.2.0 - Added 'users per article' to the output
 
   // obtain list of wikipedias, it's in comma deliminated format
   $wikipedias = file('wikipedias.csv');
 
   $date = explode(',', $wikipedias[1]);
   $date = explode(' ', $date[10]);
   $date = explode('-', $date[0]);
   $months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
   $date = $date[2] . ' ' . $months[$date[1]-1] . ' ' . $date[0];
 
?><pre>These tables were generated automatically from [http://s23.org/wikistats/wikipedias_csv.php this data file] on <? echo $date; ?>.
 
<?
   $headings = array(1000000, 100000, 10000, 1000, 100);
 
   // loop through each item, they are sorted by article count
   for ($n = 1; $n < count($wikipedias); $n++)
   {
       $wikipedias[$n] = str_replace('"', '', $wikipedias[$n]);
       $wikipedias[$n] = explode(',', $wikipedias[$n]);
       for ($index = -1, $c = 0; $c < count($headings); $c++)
       {
           if ($wikipedias[$n][4] >= $headings[$c])
           {
               break;
           }
       }
       $index = $c;
 
       if ($index >= 0 && $index < count($headings))
       {
           $notable[$index][count($notable[$index])+1]['edit_article'] = number_format($wikipedias[$n][6] / $wikipedias[$n][4], 2);
           $notable[$index][count($notable[$index])]['total_article'] = number_format($wikipedias[$n][5] / $wikipedias[$n][4], 2);
           $notable[$index][count($notable[$index])]['users_article'] = number_format($wikipedias[$n][9] / $wikipedias[$n][4], 2);
           $notable[$index][count($notable[$index])]['lang_code'] = $wikipedias[$n][2];
           $notable[$index][count($notable[$index])]['lang'] = $wikipedias[$n][3];
           $notable[$index][count($notable[$index])]['articles'] = $wikipedias[$n][4];
           $notable[$index][count($notable[$index])]['total'] = $wikipedias[$n][5];
           $notable[$index][count($notable[$index])]['edits'] = $wikipedias[$n][6];
       }
   }
 
   for ($a = 0; $a < count($headings); $a++)
   {
       array_multisort($notable[$a], SORT_DESC);
       echo '=== ' . number_format($headings[$a]) . '+ articles ===' . "\n";
?>
{| class="wikitable"
|-
!Rank||Language||Wiki||Edits / article||Total / article||Users / article||Articles||Total Pages||Edits
<?
       for ($b = 0; $b < count($notable[$a]); $b++)
       {
           echo '|-' . "\n" . '|' . ($b+1) . "\n" .
                   '|[[{{N wiki article|' . $notable[$a][$b]['lang_code'] . '}}|{{N en|' . $notable[$a][$b]['lang_code'] . '}}]]' . "\n" .
                   '|[[:' . $notable[$a][$b]['lang_code'] . ':|' . $notable[$a][$b]['lang_code'] . ']]' . "\n" .
                   '|' . $notable[$a][$b]['edit_article'] . "\n" .
                   '|' . $notable[$a][$b]['total_article'] . "\n" .
                   '|' . $notable[$a][$b]['users_article'] . "\n" .
                   '|[{{fullurl:' . $notable[$a][$b]['lang_code'] . ':Special:Statistics|action=raw}} ' . $notable[$a][$b]['articles'] . "]" . "\n" .
                   '|' . $notable[$a][$b]['total'] . "\n" .
                   '|[[:' . $notable[$a][$b]['lang_code'] . ':Special:Statistics|' . $notable[$a][$b]['edits'] . "]]\n";
       }
?>
|}
<?
   }
?>
</pre>
 
© 2004-17 robson | cc unless stated