PageRenderTime 90ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/depreciated/task.sections.remove.php

https://github.com/Dispositif/addbot
PHP | 93 lines | 75 code | 10 blank | 8 comment | 14 complexity | 7269f0a347b85c45d124fcaa6dea8f9e MD5 | raw file
  1. <?PHP
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', '1');
  4. require 'bot.login.php';
  5. global $wiki;
  6. $list = $wiki->categorymembers("Category:All_articles_needing_sections",true);
  7. $log = "";
  8. $logcount = 0;
  9. foreach($list as $page)
  10. {
  11. $largestsection = 0;
  12. $sectioncount = 0;
  13. //Make sure we are working in the mainspace
  14. if (preg_match('/:/',$page) == FALSE )
  15. {
  16. echo "checking $page\n";
  17. sleep(2);
  18. $text = $wiki->getpage($page);
  19. //Make sure our tag is not below a section
  20. if(preg_match('/==.*?\{\{((cleanup|needs ?)?Sections)(\| ?(date) ?(= ?(January|February|March|April|May|June|July|August|September|October|November|December) ?20[0-9][0-9])? ?){0,1}\}\}(\r\n|\n\n){0,2}/is',$text) != 0)
  21. {
  22. $text = preg_replace("/\{\{((cleanup|needs ?)?Sections)/i","{{Sub-sections",$text);
  23. $wiki->edit($page,$text,"[[User:Addbot|Bot:]] Removing Sections Tag, Replacing with Sub-Sections tag ([[User_talk:Addbot|Report Errors]])",true);
  24. echo "Change to subsections";
  25. sleep(15);
  26. break;
  27. }
  28. //Match each of the sections
  29. preg_match_all('/\n==(=)? ?.* ?===?/i',$text, $sections, PREG_PATTERN_ORDER);
  30. $split = preg_split('/\n==(=)? ?.* ?===?/i',$text);
  31. //$largestsection = 0;
  32. foreach($split as $id => $section)
  33. {
  34. echo "ID = ".$id."\n";
  35. //if it is the main section
  36. if($id == 0)
  37. {
  38. $largestsection = strlen($section);
  39. $sectioncount++;
  40. }
  41. else
  42. {
  43. if (preg_match('/See ?also|(external( links)?|references|notes|bibliography|further( reading)?)/i',$sections[0][$id-1]) == 0)
  44. {
  45. echo "-- IS a valid section per ".$sections[0][$id-1]." \n";
  46. if(strlen($section) > $largestsection)
  47. {
  48. $largestsection = strlen($section);
  49. }
  50. $sectioncount++;
  51. }
  52. }
  53. }
  54. //Has enough sections to remove the tag
  55. if($sectioncount >= 4 && $largestsection <= 5000)//was 2750 for AVG
  56. {
  57. echo "CAN REMOVE TAG on $page\n";
  58. $text = preg_replace("/\{\{((cleanup|needs ?)?Sections)(\| ?(date) ?(= ?(January|February|March|April|May|June|July|August|September|October|November|December) ?20[0-9][0-9])? ?){0,1} *\}\}(\r\n|\n\n){0,3}/i","",$text);
  59. if($text != "")
  60. {
  61. $wiki->edit($page,$text,"[[User:Addbot|Bot:]] Removing Sections Tag - $sectioncount sections with a max size of $largestsection",true);
  62. sleep(15);
  63. }
  64. }
  65. //now 4 as we include the lead
  66. elseif($sectioncount >= 4 && $largestsection <= 10000)
  67. {
  68. echo "If it is close then add to a list\n";
  69. $logcount++;
  70. $log = $log."|row".$logcount."=[[$page]]{{!!}}$sectioncount{{!!}}".strlen($text)."{{!!}}".strlen($text)/$sectioncount."\n";
  71. }
  72. }
  73. }
  74. //Add the table to the log
  75. echo "Post the final list\n";
  76. $log = '{{Table
  77. |type=class="wikitable sortable"
  78. |title=Borderline {{tl|Sections}} removals not done by [[User:Addbot]] (4 sections, largest is 10,000)
  79. |hdrs=Article!!Distinct Sections!!Page Size!!Average Size!!Largest Size'."\n".$log;
  80. $log = $log."\n}}";
  81. sleep(15);
  82. $wiki->edit("User:Addbot/log/sections",$log,"[[User:Addbot|Bot:]] Posting Analysis Results",true);
  83. ?>