Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- ini_set('display_errors', TRUE);
- /*
- ({{.*}}(?:\n.*?)*)(?:==.*?==)*
- */
- require('../api/wapi.php');
- $b = new wikibot(FALSE);
- require_once('../msg.php');
- $b->login($user, $password);
- unset($password);
- $cache = file_get_contents('uscotm.dat');
- $cache = unserialize($cache);
- function findnextmonth() {
- $now = date('F');
- $next = $now;
- $i = 1;
- while($now == $next) {
- $next = date('F', time()+$i); // increase by one sec until we reach a new month
- $i++;
- }
- return $next;
- }
- function ifdenybot($str) {
- if (preg_match('/{{bots\|deny=[^}]*Project[ _]Messenger[ _]Bot[^}]*}}/', $str)) {
- return true;
- }
- else {
- return false;
- }
- }
- function getsigtime() {
- return date('H:i\, d F Y \(\U\T\C\)');
- }
- $collabus = $b->getPage('Template:Collab-us');
- $collab = $b->getPage('Wikipedia:U.S._Wikipedians%27_notice_board/USCOTM');
- if (preg_match_all('/===\[\[(.*?)(?:\|.*)*\]\] (?:.*?)===/', $collab, $m)) {
- foreach($m[1] as $nom) {
- if ($nom != 'Example' && $cache[$nom] != TRUE && !isset($cache[$nom])) {
- $nomtalk = 'Talk:'.$nom;
- $nomtalk = $b->getPage($nomtalk);
- if (!preg_match('/{{USnom}}/i', $nomtalk)) { // Check for and add {{USnom}} if needed
- $nomtalk = '{{USnom}}'.PHP_EOL.$nomtalk;
- $b->edit('Talk:'.$nom, $nomtalk, 'Adding {{USnom}}', NULL, TRUE, TRUE);
- sleep(3);
- }
- if (preg_match_all('/{{(WikiProject [^\|]+).*}}/', $nomtalk, $wp)) { // Notify associated wikiprojects
- foreach($wp[1] as $proj) {
- if ($proj != 'WikiProject United States') {
- $proj = 'Wikipedia talk:'.$proj;
- $projp = $b->getPage($proj);
- if (ifdenybot($projp) == FALSE) {
- $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();
- if (!strpos($projp, $notice)) {
- $projp .= PHP_EOL.PHP_EOL.$notice;
- $b->edit($proj, $projp, 'Adding notice: '.$nom.' has been nominated for USCOTM.');
- sleep(7);
- }
- }
- }
- }
- }
- $cache[$nom] = TRUE;
- }
- }
- }
- $select = $b->getPage('Template:Collab-us');
- $select = preg_replace('/<noinclude>.*</noinclude>/s', NULL, $select); # strip the noinclude, just want article
- preg_match('/\[\[([^\]]+)\]\]/', $select, $selected);
- if($selected[1]) {
- if (!isset($cache['s_'.$selected[1]])) {
- $selpage = 'Talk:'.$selected[1];
- $selpage = $b->getPage($selpage);
- if (preg_match_all('/{{(WikiProject [^\|]+).*}}/', $nomtalk, $wp)) { // Notify associated wikiprojects
- foreach ($wp[1] as $proj) {
- $proj = 'Wikipedia talk:'.$proj;
- $projp = $b->getPage($proj);
- if (ifdenybot($projp)) {
- $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();
- if (!preg_match('/=='.$selected[1].' has been nominated .* for next '.date('F Y').'/', $projp)) {
- $projp = preg_replace('/(==.*==\n'.$selected[1].'.*has been selected as the.*USCOTM.*'.date('F Y').'.*)/', '$1\n'.$notice, $projp);
- }
- else {
- $projp .= PHP_EOL.$notice;
- }
- $b->edit($proj, $projp, 'Adding notice: '.$selected[1].' has been nominated as the USCOTM.');
- sleep(7);
- }
- }
- }
- $cache = array();
- $cache['s_'.$selected[1]] = TRUE;
- }
- }
- else {
- $b->noomlog('Warning, failed to detect the USCOTM selected article: no match returned.');
- }
- $f = fopen('uscotm.dat', 'w');
- fwrite($f, serialize($cache));
- fclose($f);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement