daily pastebin goal
25%
SHARE
TWEET

Untitled

JoshG Aug 2nd, 2011 16 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?PHP
  2. ini_set('display_errors', TRUE);
  3. /*
  4. ({{.*}}(?:\n.*?)*)(?:==.*?==)*
  5. */
  6.  
  7. require('../api/wapi.php');
  8. $b = new wikibot(FALSE);
  9. require_once('../msg.php');
  10. $b->login($user, $password);
  11. unset($password);
  12.  
  13. $cache = file_get_contents('uscotm.dat');
  14. $cache = unserialize($cache);
  15.  
  16. function findnextmonth() {
  17.         $now = date('F');
  18.         $next = $now;
  19.         $i = 1;
  20.         while($now == $next) {
  21.                 $next = date('F', time()+$i); // increase by one sec until we reach a new month
  22.                 $i++;
  23.         }
  24.         return $next;
  25. }
  26.  
  27. function ifdenybot($str) {
  28.         if (preg_match('/{{bots\|deny=[^}]*Project[ _]Messenger[ _]Bot[^}]*}}/', $str)) {
  29.                 return true;   
  30.         }
  31.         else {
  32.                 return false;  
  33.         }
  34. }
  35. function getsigtime() {
  36.         return date('H:i\, d F Y \(\U\T\C\)');
  37. }
  38.  
  39. $collabus = $b->getPage('Template:Collab-us');
  40. $collab = $b->getPage('Wikipedia:U.S._Wikipedians%27_notice_board/USCOTM');
  41. if (preg_match_all('/===\[\[(.*?)(?:\|.*)*\]\] (?:.*?)===/', $collab, $m)) {
  42.         foreach($m[1] as $nom) {
  43.                 if ($nom != 'Example' && $cache[$nom] != TRUE && !isset($cache[$nom])) {
  44.                         $nomtalk = 'Talk:'.$nom;
  45.                         $nomtalk = $b->getPage($nomtalk);
  46.                         if (!preg_match('/{{USnom}}/i', $nomtalk)) { // Check for and add {{USnom}} if needed
  47.                                 $nomtalk = '{{USnom}}'.PHP_EOL.$nomtalk;
  48.                                 $b->edit('Talk:'.$nom, $nomtalk, 'Adding {{USnom}}', NULL, TRUE, TRUE);
  49.                                 sleep(3);
  50.                         }
  51.                         if (preg_match_all('/{{(WikiProject [^\|]+).*}}/', $nomtalk, $wp)) { // Notify associated wikiprojects
  52.                                 foreach($wp[1] as $proj) {
  53.                                         if ($proj != 'WikiProject United States') {
  54.                                                 $proj = 'Wikipedia talk:'.$proj;
  55.                                                 $projp = $b->getPage($proj);
  56.                                                 if (ifdenybot($projp) == FALSE) {
  57.                                                         $notice = '=='.$nom.' has been nominated as the [[Wikipedia:U.S. Wikipedians\' notice board/USCOTM|United States Wikipedians\' Collaboration of the Month]] for next '.findnextmonth().' '.date('Y').'=='.PHP_EOL.'[['.$nom.']], an article within the scope of this project, has been nominated to be the [[Wikipedia:U.S. Wikipedians\' notice board/USCOTM|United States Wikipedians\' Collaboration of the Month]] for next '.findnextmonth().' '.date('Y').'. You can vote for this or other articles to be next months Collaboration of the Month [[Wikipedia:U.S. Wikipedians\' notice board/USCOTM|here]]. [[User:Project Messenger Bot|Project Messenger Bot]] '.getsigtime();
  58.                                                         if (!strpos($projp, $notice)) {
  59.                                                                 $projp .= PHP_EOL.PHP_EOL.$notice;
  60.                                                                 $b->edit($proj, $projp, 'Adding notice: '.$nom.' has been nominated for USCOTM.');
  61.                                                                 sleep(7);
  62.                                                         }
  63.                                                 }
  64.                                         }
  65.                                 }
  66.                         }
  67.                         $cache[$nom] = TRUE;
  68.                 }
  69.         }
  70. }
  71. $select = $b->getPage('Template:Collab-us');
  72. $select = preg_replace('/<noinclude>.*</noinclude>/s', NULL, $select); # strip the noinclude, just want article
  73. preg_match('/\[\[([^\]]+)\]\]/', $select, $selected);
  74. if($selected[1]) {
  75.         if (!isset($cache['s_'.$selected[1]])) {
  76.                 $selpage = 'Talk:'.$selected[1];
  77.                 $selpage = $b->getPage($selpage);
  78.                 if (preg_match_all('/{{(WikiProject [^\|]+).*}}/', $nomtalk, $wp)) { // Notify associated wikiprojects
  79.                         foreach ($wp[1] as $proj) {
  80.                                 $proj = 'Wikipedia talk:'.$proj;
  81.                                 $projp = $b->getPage($proj);
  82.                                 if (ifdenybot($projp)) {
  83.                                         $notice = '[['.$selected[1].']], an article within the scope of this project, has been selected as the [[Wikipedia:U.S. Wikipedians\' notice board/USCOTM|United States Wikipedians\' Collaboration of the Month]] for current month year. All editors interested in improving this article are encouraged to participate. You can also vote for next months article of the Month [[Wikipedia:U.S. Wikipedians\' notice board/USCOTM|here]]. [[User:Project Messenger Bot|Project Messenger Bot]] '.getsigtime();
  84.                                         if (!preg_match('/=='.$selected[1].' has been nominated .* for next '.date('F Y').'/', $projp)) {
  85.                                                 $projp = preg_replace('/(==.*==\n'.$selected[1].'.*has been selected as the.*USCOTM.*'.date('F Y').'.*)/', '$1\n'.$notice, $projp);
  86.                                         }
  87.                                         else {
  88.                                                 $projp .= PHP_EOL.$notice;
  89.                                         }
  90.                                         $b->edit($proj, $projp, 'Adding notice: '.$selected[1].' has been nominated as the USCOTM.');
  91.                                         sleep(7);
  92.                                 }
  93.                         }
  94.                 }
  95.                 $cache = array();
  96.                 $cache['s_'.$selected[1]] = TRUE;
  97.         }
  98. }
  99. else {
  100.         $b->noomlog('Warning, failed to detect the USCOTM selected article: no match returned.');
  101. }
  102.  
  103. $f = fopen('uscotm.dat', 'w');
  104. fwrite($f, serialize($cache));
  105. fclose($f);
  106.  
  107. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top