PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/depreciated/peach.uncat.remove.php

https://github.com/Dispositif/addbot
PHP | 89 lines | 69 code | 16 blank | 4 comment | 7 complexity | e5153fc058f763de0dc52f9d49c3167b MD5 | raw file
  1. <?php
  2. ini_set('memory_limit','16M');
  3. require_once( '/home/addshore/addbot/Peachy/Init.php' );
  4. $site = Peachy::newWiki( "addbot" );
  5. $ignorelist = array(
  6. 'Articles lacking sources (Erik9bot)',
  7. 'Articles created via the Article Wizard',
  8. 'Unreviewed new articles',
  9. 'Article Feedback 5',
  10. );
  11. //$p = $template->embeddedin( array(0) );
  12. //change the above to the below list
  13. //http://toolserver.org/~jason/categorized_articles.php
  14. //http://toolserver.org/~jason/data/categorized_articles_list.txt
  15. file_get_contents('http://toolserver.org/~dpl/data/trigger_cat_file.php');
  16. echo "Sleeping for 5";
  17. sleep(5);
  18. $p = file_get_contents('http://toolserver.org/~dpl/data/categorized_articles_list.txt');
  19. $p = str_replace(']]','',$p);
  20. $p = str_replace('[[','',$p);
  21. $p = explode("\n",$p);
  22. $c = 1;
  23. $tofind = array(
  24. 'Classify',
  25. 'CatNeeded',
  26. 'Uncategorised',
  27. 'Uncat',
  28. 'Categorize',
  29. 'Categories needed',
  30. 'Categoryneeded',
  31. 'Category needed',
  32. 'Category requested',
  33. 'Categories requested',
  34. 'Nocats',
  35. 'Categorise',
  36. 'Nocat',
  37. 'Uncat-date',
  38. 'Uncategorized-date',
  39. 'Needs cat',
  40. 'Needs cats',
  41. 'Cat needed',
  42. 'Cats needed',
  43. );
  44. foreach ($p as $pg) {
  45. sleep(1);
  46. if( $c > 100 ) break;
  47. $page = initPage($pg);
  48. $text = $page->get_text();
  49. preg_match_all('/\[\[Category:(.*?)(\|(.*?))?\]\]/Si', $text, $cats);
  50. if( $cats ) {
  51. $cats = $cats[1];
  52. $remove = 'no';
  53. foreach( $cats as $cat ) {
  54. if( in_array( $cat, $ignorelist ) ) {
  55. continue;
  56. }
  57. $tmp = initPage( 'Category:'.$cat );
  58. if( $tmp->get_exists() ) {
  59. $remove = 'yes';
  60. break;
  61. }
  62. }
  63. if( $remove == 'yes' ) {
  64. $newtext = preg_replace('/\{\{('.implode('|',$tofind).')(.*?)\}\}/i', '', $text);
  65. $diff = getTextDiff('unified', $text, $newtext);
  66. echo $diff;
  67. $page->edit($newtext,"[[User:Addbot|Bot:]] Removing Uncategorized template",true);
  68. $c++;
  69. sleep(45);
  70. }
  71. }
  72. }
  73. ?>