User:ClueBot VI/Source

From Wikipedia, the free encyclopedia

The following is automatically generated by ClueBot VI.


  • wikibot.classes.php is here.


[edit] Source to ClueBot VI

<?PHP
        function addtobottom(&$data,$add) {
                global $changed;
                $changed = true;

                $tmp = explode('===',$data);
                $tmp[0] = rtrim($tmp[0])."\n".$add."<!-- If removing the CUU/Clerk note template, keep this comment so ClueBot VI won't readd the template. -->\n\n";
                $tmp = implode('===',$tmp);
                $data = $tmp;
        }

        include '../wikibot.classes.php';
        include 'cluebot6.config.php';

        $wpq = new wikipediaquery;
        $wpapi = new wikipediaapi;
        $wpi = new wikipediaindex;

        $wpapi->login($user,$pass);

        $wpi->forcepost('User:'.$user.'/Source',
                'The following is automatically generated by [[User:'.$user.'|'.$user."]].\n\n\n\n" .
                '* wikibot.classes.php is [[User:ClueBot/Source|here]].' .
                "\n\n\n\n==Source to ".$user."==\n\n" .
                '<pre>'.htmlentities(file_get_contents(__FILE__))."</pre>\n\n\n\n~~~~",
                'Automated source upload.'); /* Our source code, we force post this because this is *our* page, and it triggers the nobots. */

//      $i = 22;
        while (1) {
                $changed = false;
                $data = $wpq->getpage('Wikipedia:Changing username/Usurpations');
                $header = explode('====',$data,2);
                $data = '===='.$header[1];
                $header = $header[0];
                $datatopost = $header;
                $changed = false;
                preg_match_all('/\=\=\=\=\s*(\S.*)\s*\=\=\=\=(.*)(?=\=\=\=\=\s*\S.*\s*\=\=\=\=(.*)|$)/Us',$data,$m,PREG_SET_ORDER);
                $footer = explode($m[count($m)-1][2],$data);
                $footer = $footer[1];
//              echo $footer."\n\n";
//              print_r($m);
                foreach ($m as &$request) {
                        if (preg_match('/\{\{CUU.*/i',$request[2])) continue;
                        if (preg_match('/\{\{Clerk note\}\}/i',$request[2])) continue;
                        if (preg_match('/\{\{Done\}\}/i',$request[2])) continue;
                        if (preg_match('/\{\{Not done\}\}/i',$request[2])) continue;
                        if (preg_match('/\{\{\[\[Image:.*/i',$request[2])) continue;
                        if (preg_match('/ClueBot VI/i',$request[2])) continue;
                        $to = explode('�',trim($request[1]));
                        if (!isset($to[1])) {
                                addtobottom(&$request[2],':{{Clerk note}} Parse error: I had a problem parsing this request.  Please ensure that the header is in the correct format.  Thanks.  ~~~~');
                                continue;
                        }
                        $from = trim($to[0]);
                        $to = trim($to[1]);

                        $to = strtoupper($to{0}).substr($to,1);
                        $from = strtoupper($from{0}).substr($from,1);

                        $params = array();

                        $totaledits = $wpq->contribcount($to);
                        $visibleedits = 0;
                        $cont = null;
                        while (($count = count($wpapi->usercontribs($to,500,&$cont))) == 500) $visibleedits += $count;
                        $visibleedits += $count;
                        $deletededits = $totaledits - $visibleedits;

                        if ($visibleedits > 0) $params['contribs'] = 'yes'; else $params['contribs'] = 'no';
                        if ($deletededits > 0) $params['dcontribs'] = 'yes'; else $params['dcontribs'] = 'no';

                        if (count($wpapi->logs($to)) > 1) $params['logs'] = 'yes'; else $params['logs'] = 'no';

                        $info = $wpapi->users($to);

                        if ($info[0]['name'] != $to) {
                                addtobottom(&$request[2],':{{Clerk note}} User "'.$to.'" is not registered.  Please see [[WP:CHU]] instead.  ~~~~');
                                continue;
                        }

                        preg_match('/^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/',$info[0]['registration'],$regdate);
                        if (((time() - gmmktime($regdate[4],$regdate[5],$regdate[6],$regdate[2],$regdate[3],$regdate[1])) > 6*30*24*60*60) or ((time() - gmmktime($regdate[4],$regdate[5],$regdate[6],$regdate[2],$regdate[3],$regdate[1])) < 3600)) {
                                $params['new'] = 'no';
                        } else {
                                $params['new'] = 'yes';
                        }

                        if (stripos($wpq->getpage('User talk:'.$to),$from) !== false) $params['notified'] = 'yes';
                        else $params['notified'] = 'no';

                        if ($wpi->hasemail($to)) $params['email'] = 'yes'; else $params['email'] = 'no';
                        
                        $fromec = $wpq->contribcount($from);

                        $note = 'User has '.$visibleedits.' undeleted edits, '.$deletededits.' deleted edits, and '.$totaledits.' total edits.  ';
                        $note.= 'Requesting user has '.(isset($fromec)?$fromec:'no').' edits.';

                        $params['note'] = $note;

                        $cuutemplate = ':{{CUU';
                        foreach ($params as $k => $v) $cuutemplate.='|'.$k.'='.$v;
                        $cuutemplate.= '}} ~~~~';

//                      echo $cuutemplate."\n\n";

                        addtobottom(&$request[2],$cuutemplate);
                }

                $newdata = $header;
                foreach ($m as $req) $newdata.= '===='.$req[1].'===='.$req[2];
                $newdata.= $footer;

//              echo $newdata."\n\n";

                if ($changed == true) {
                        $wpi->post('Wikipedia:Changing username/Usurpations',$newdata,'Adding clerk notices. (BOT)');
//                      $i++;
//                      if ($i == 25) die();
                }

                sleep(300);
        }
?>


ClueBot VI (talk) 03:08, 5 June 2008 (UTC)