User:Coastergeekperson04/bot
Appearance
(Redirected from User:Ceres3/bot)
<nowiki><?php /*I got this off something I found as a giude to edit for a bot. I only made the top line, so be aware it can't run or it'll not work. Any tips? By Jonny Watts */ // The supported 'SITECHARSET' encodings are ISO-8859-1, UTF-8 and US-ASCII. define('SITECHARSET','ISO-8859-1'); define('SITENAME','enwiki'); // Not yet used; please use the internal names for Wikimedia Foundation projects (see m:Stewards) define('SERVER','http://en.wikipedia.org'); // Apply bot data here over _ // USERID is not required but this is a useful place to keep it. You can find it at Special:Preferences. define('USERID','CoasterBot'); define('USERNAME','CoasterBot'); define('PASSWORD','why should i tell you?'); function gettext($title) { // en:Special:export returns XML, retrieves top article layer only xml_parse_into_struct(xml_parser_create('UTF-8'), file_get_contents(SERVER.'/wiki/Special:Export/'.$title), $val, $ind); $text = $val[$ind['TEXT'][0]]['value']; if (SITECHARSET != 'UTF-8') { $text = utf8_decode($text); } return $text; } function initeditpage($title) { // Run this once before calling geteditpage() or makeedit() exec("curl --silent -d \"wpName=$user&wpLoginattempt=Log+in&wpPassword=$pass&wpRemember=1&wpRetype=&wpEmail=\" --url \"$serv/wiki/index.php?title=Special:Userlogin&action=submit\" --config cookieconf.txt"); } function geteditpage($title) { // geteditpage() returns $ret['text'] with article text and $ret['attr'] you must pass on to makeedit() $user = CoasterBot; $pass = no peeking!; $serv = I think I will use the toolserver, help?; $title = rawurlencode(str_replace(' ','_',$title)); $req = shell_exec("curl --silent --url \"$serv/w/index.php?title=$title&action=edit\" --config cookieconf.txt"); xml_parse_into_struct(xml_parser_create(SITECHARSET), $req, $val, $ind); if (!is_array($ind['INPUT'])) { $fna = 'dumps/temp' . mt_rand() . '.html'; trigger_error("Dump for following error is at $fna", E_USER_NOTICE); file_put_contents($fna, $req); } $fna = 'dumps/temp' . mt_rand() . '.html'; file_put_contents($fna, $req); $p = strpos($req, '<textarea'); $k = substr($req, $p, strpos($req, '</textarea>') - $p); $k = substr($k, strpos($k, '>') + 1); $text = html_entity_decode($k, ENT_QUOTES, SITECHARSET); foreach ($ind['INPUT'] as $_=>$num) { $attr[$val[$num]['attributes']['NAME']] = $val[$num]['attributes']['VALUE']; } // Unsets remove what a browser would not have submitted. unset($attr['search']); unset($attr['go']); unset($attr['fulltext']); //text: trim($val[$ind['TEXTAREA'][0]]['value']) return array('text' => $text, 'attr' => $attr); } function makeedit($title, $attr, $newtext, $presum = NULL) { global $summary; $title = urlencode(str_replace(' ','_',$title)); $serv = SERVER; $attr['wpSummary'] = $presum . $summary; $attr['wpTextbox1'] = $newtext; // Unsets things that only effect human acconts unset($attr['wpPreview']); unset($attr['wpWatchthis']); foreach ($attr as $name=>$val) { $val = urlencode($val); if ($name == 'wpTextbox1') { var_dump($val); } $data .= "&{$name}={$val}"; } $data = substr($data, 1); $fna = 'temp' . mt_rand() . '.txt'; file_put_contents($fna,"--data $data"); $req = shell_exec("curl -sS --config $fna --url \"$serv/w/index.php?title=$title&action=submit\" --config cookieconf.txt"); unlink($fna); return $req; } ?>