PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/depreciated/task.mystats.php

https://github.com/Dispositif/addbot
PHP | 105 lines | 68 code | 14 blank | 23 comment | 3 complexity | 6eb849f20928e757007751da9f4c406d MD5 | raw file
  1. <?PHP
  2. require 'bot.login.php';
  3. global $wiki;
  4. $page = "User:Addbot/Stats";
  5. //Get the last run date
  6. $text = $wiki->getpage($page);
  7. preg_match("/\<!\-\- (.*) \-\-\>/i",$text,$timestamp);
  8. //$end = $timestamp[1];
  9. $end = "2008-01-01T00:00:00Z";
  10. $start = '';
  11. $done = false;
  12. $sum['AWB']['regex'] = "/((clean|fix) and tag|tagging and fixing|Maintenance tags)/i";
  13. $sum['sandbox']['regex'] = "/Restoring/i";
  14. $sum['message']['regex'] = "/Sending/i";
  15. $sum['badformat']['regex'] = "/Tagging PDF with \{\{BadFormat\}\}/i";
  16. $sum['usertalksubst']['regex'] = "/Substing/i";
  17. $sum['doubleredirects']['regex'] = "/Fixing double redirect/i";
  18. $sum['referencessection']['regex'] = "/Adding missing (\<references \/\>|\{\{reflist\}\}) tag/i";
  19. $sum['deorphan']['regex'] = "/(Removing orphan tag|No ?longer an Orphan|Successfully de\-orphaned)/i";
  20. $sum['orphan']['regex'] = "/(Adding Orphan Tag|Orphan page, add template)/i";
  21. $sum['deuncat']['regex'] = "/Removing Uncategorized (template|tag)/i";
  22. $sum['uncat']['regex'] = "/Adding uncategorized tag/i";
  23. $sum['deadend']['regex'] = "/Removing Deadend Tag/i";
  24. $sum['sections']['regex'] = "/Removing sections tag/i";
  25. $sum['unknown']['regex'] = "//";
  26. foreach ($sum as $type => $check)
  27. {
  28. $sum[$type]['count'] = 0;
  29. }
  30. while($done == false)
  31. {
  32. //Run the query
  33. sleep(60);
  34. $x = $wiki->query('?action=query&format=php&list=usercontribs&ucuser=Addbot&uclimit=5000&ucstart='.urlencode($start).'&ucend='.urlencode($end).'&ucprop=comment|timestamp|title');
  35. //If we are given a place to continue
  36. if(isset($x['query-continue']['usercontribs']['ucstart']))
  37. {
  38. //Get the query continue timestamp
  39. $start = $x['query-continue']['usercontribs']['ucstart'];
  40. $done = false;
  41. }
  42. else
  43. {
  44. //Looks like we are done for now, Need to get the timestamp for the next run
  45. $done = true;
  46. $start = $x['query']['usercontribs'][0]['timestamp'];
  47. }
  48. //Look at each contrib
  49. foreach ($x['query']['usercontribs'] as $usercontrib)
  50. {
  51. //Check the summary against regex
  52. foreach ($sum as $type => $check)
  53. {
  54. //Search for a match
  55. if(preg_match($check['regex'],$usercontrib['comment']))
  56. {
  57. echo $usercontrib['comment']."\n";
  58. $sum[$type]['count']++;
  59. break;
  60. }
  61. }
  62. }
  63. }
  64. /*
  65. //Now we need to parse the previous results
  66. preg_match_all('/\|\-\n! Task !! Count\n\|\-\n| (.*)\n\| ([0-9]+)/i',$text,$matches);
  67. foreach($matches[1] as $id => $cont)
  68. {
  69. if($id != 0)
  70. {
  71. //Add the values to those that we have calculated
  72. $sum[$cont]['count'] = $sum[$cont]['count'] + $matches[2][$id];
  73. }
  74. }
  75. */
  76. //Create the table
  77. $output = "<!-- $start -->\n";
  78. $output =$output.'{| class="wikitable"
  79. |-
  80. ! colspan="2" | Addbot statistics
  81. |-
  82. ! Task !! Count';
  83. //Add each value
  84. foreach ($sum as $type => $check)
  85. {
  86. $output = $output."\n|-\n| ".$type."\n| ".$sum[$type]['count'];
  87. }
  88. $output = $output."\n|}";
  89. echo $output;
  90. $wiki->edit($page,$output,"[[User:Addbot|Bot:]] Posting Stats",true);
  91. ?>