Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_page_contents($title) {
- $data = '';
- while ($data == '') {
- $data = curl_get('http://wiki.scratch.mit.edu/w/api.php?action=query&titles=' . rawurlencode($title) . '&prop=revisions&rvprop=content&format=xml&salt=' . md5(time()));
- }
- $page_xml = @new SimpleXMLElement($data);
- $contents = (string) ($page_xml->query->pages->page->revisions->rev);
- return $contents;
- }
- function curl_post($url, $postfields) {
- $ch = curl_init ();
- curl_setopt ( $ch, CURLOPT_URL, $url);
- curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt ( $ch, CURLOPT_POST, 1 );
- curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postfields);
- curl_setopt ( $ch, CURLOPT_ENCODING, "" );
- curl_setopt ( $ch, CURLOPT_COOKIEFILE, getcwd () . '/cookies.txt' );
- curl_setopt ( $ch, CURLOPT_COOKIEJAR, getcwd () . '/cookies.txt' );
- curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)" );
- $out = curl_exec ( $ch );
- curl_close($ch);
- return $out;
- }
- function curl_get($url) {
- $ch = curl_init ();
- curl_setopt ( $ch, CURLOPT_URL, $url);
- curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt ( $ch, CURLOPT_ENCODING, "" );
- curl_setopt ( $ch, CURLOPT_COOKIEFILE, getcwd () . '/cookies.txt' );
- curl_setopt ( $ch, CURLOPT_COOKIEJAR, getcwd () . '/cookies.txt' );
- curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)" );
- $out = curl_exec ( $ch );
- curl_close($ch);
- return $out;
- }
- function submit_edit($title, $contents, $summary, $minor = false) {
- $tokenxml = new SimpleXMLElement(curl_post('http://wiki.scratch.mit.edu/w/api.php?action=query&prop=info|revisions&intoken=edit&titles=' . rawurlencode($title) . '&format=xml', '')); //get token
- $edittoken = (string)$tokenxml->query->pages->page->attributes()->edittoken;
- $return = curl_post('http://wiki.scratch.mit.edu/w/api.php', 'action=edit&title=' . rawurlencode($title) . '&summary=' . $summary . '&text=' . rawurlencode($contents) . '&format=xml&bot=true' . ($minor = true ? '&minor=true' : '') . '&token=' . rawurlencode($edittoken)); //submit the edit
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement