Utente:Balubino/Curl script
Script di prova di editing di una pagina via curl
[modifica | modifica wikitesto]<?
function form_edit() {
$pagina = 'Utente:Balubino/Curl_test';
$form[] = '<form id="editform" name="editform" method="post" action="" enctype="application/x-www-form-urlencoded">';
$form[] = '<textarea tabindex="1" accesskey="," name="wpTextbox1" rows="25" cols="80"></textarea>';
$form[] = '<br />Pagina: <input tabindex="3" type="text" value="'.$pagina.'" name="wpPage" maxlength="200" size="60" /><br />';
$form[] = '<br />Oggetto: <input tabindex="3" type="text" value="" name="wpSummary" maxlength="200" size="60" /><br />';
$form[] = '<input tabindex="3" type="checkbox" value="1" name="wpMinoredit" accesskey="i" id="wpMinoredit" /><label for="wpMinoredit" title="Segnala come modifica minore [alt-i]">Questa è una modifica minore</label>';
$form[] = '<input tabindex="6" id="wpPreview" type="submit" value="Visualizza anteprima" name="wpPreview" accesskey="p" title="Preview your changes, please use this before saving! [alt-p]"/>';
$form[] = '<input type="hidden" name="azione" value="posta">';
$form[] = '</form>';
return join("\n",$form);
}
$sommario = $_POST['wpSummary'];
$testo = $_POST['wpTextbox1'];
$minedit = $_POST['wpMinoredit'];
$azione = $_POST['azione'];
$pagina = $_POST['wpPage'];
$testo = urlencode(utf8_encode($testo));
$sommario = urlencode(utf8_encode($sommario));
$vars['wpMinoredit'] = $minedit; //val 1/0
$vars['wpWatchthis'] = 0; // checkbox
$vars['wpTextbox1'] = $testo;
$vars['wpSummary'] = $sommario;
#$vars['wpSave'] = 'Salva la pagina';
$vars['wpPreview'] = 'Visualizza anteprima';
$vars['wpSection'] = '0';
$vars['wpEdittime'] = '0';
$vars['action'] = "submit";
foreach ($vars as $k=>$v)
$params[] = "$k=$v";
$formvars = join('&',$params);
$user_agent = "Mozilla/5.0 (Windows; U; Win98; rv:1.7.3) Gecko/20040913 Firefox/0.10";
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$domain = "http://it.wikipedia.org";
$submit_url = "/w/wiki.phtml?title=".$pagina;
$url = $domain.$submit_url;
#$submit_url .= "&action=submit";
// init curl handle
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
#curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // this line makes it work under https
curl_setopt($ch, CURLOPT_POSTFIELDS, $formvars);
// perform post
if ($azione == 'posta') {
$result=curl_exec($ch);
echo("Results: <br>".utf8_decode($result));
curl_close($ch);
} else {
echo form_edit();
}
?>