User:LivingBot/Source/3

From Wikipedia, the free encyclopedia
<?php
  //grab class
  include('BasicBot.php5');
  //create bot
  $LivingBot = new phpwikibot("LivingBot", $password, "en", "5", "5");
  $handle = fopen("livingbot_targets_grammar.txt", 'r') or die("can't open file");
  while (!feof($handle)) {
      $targets[] = trim(fgets($handle));
  }
  fclose($handle);
  for ($i = 0; $i < count($targets); $i++) {
     if(stripos($LivingBot->get_page("User:LivingBot/shutoff"),"<!--Emergency shutoff-->") === false){
      echo "Bot shut down.<br />";
      break;
     }
     echo "Editing page [[$targets[$i]]].<br />";
      $page = $LivingBot->get_page($targets[$i]);
      if (stripos(str_replace(" ","",$page), "{{grammar") === false) {
          //Already done, or some other mistake, either way:
          continue;
      }
     preg_match_all("/\{\{[ ]*grammar([^\}]*)\}\}/i",$page,$temp);
     //Store any extra parameters such as date, and the section keyword
     $extra = $temp[1][0];
     //Replace old with new
     $newpage = str_ireplace($temp[0][0],"{{copyedit$extra|for=grammar}}",$page);
     //Edit
     $LivingBot->edit_page($targets[$i], $newpage, "Bot replacing defunct {{grammar}} template with {{copyedit|for=grammar}}. [[User_talk:LivingBot|Incorrect?]]");
  }
?>