Planning the future of Botwiki! - Help us bring Botwiki up to date, contribute to our strategy discussion, add bot scripts, and contribute manuals, guides, and tutorials! Almost anything related to bots, particularly those used to edit mediawiki, is welcome.
UNABLE TO EDIT? - We've experienced attacks by spambots lately and now require you to confirm your e-mail before you can edit (go to your preferences, enter an e-mail address, and request a confirmation e-mail, then go to your e-mail and click on the confirmation link). We also require new accounts to make a few edits and wait a few minutes before before you can create a page; however, if this is a problem contact us in #botwiki and we can manually confirm your account. Sorry for the inconvenience.
Php:Votes counter.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Votes counter.php</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- <meta name="robots" content="noindex,nofollow"> -->
<style type="text/css" media="screen,projection">/*<![CDATA[*/
@import "http://en.wikipedia.org/skins-1.5/common/shared.css?80";
@import "http://en.wikipedia.org/skins-1.5/monobook/main.css?80";
@import "../misza.css";
/*]]>*/</style>
</head>
<body class="mediawiki">
<div id="globalWrapper">
<div id="column-content">
<div id="content">
<h1>Votes counter.php</h1><br/>
<p>This is a program written by <a href="http://it.wikipedia.org/wiki/Utente:Filnik" title="Filnik">Filnik</a> to count quickly
the percent of pos/cons votes somewhere. You can also set the percent required to let the program tell you how many votes are needed to
pass it in on way or in the other.
<br/><br/>
<b><a href="http://botwiki.sno.cc/wiki/Php:Votes counter.php" title="Source">Source</a></b>
<br/>
</p>
<h2>Settings:</h2>
<br/>
<?
class http {
private $ch;
function data_encode($data, $keyprefix = "", $keypostfix = "") {
assert( is_array($data) );
$vars=null;
foreach($data as $key=>$value) {
if(is_array($value)) $vars .= $this->data_encode($value, $keyprefix.$key.$keypostfix.urlencode("["), urlencode("]"));
else $vars .= $keyprefix.$key.$keypostfix."=".urlencode($value)."&";
}
return $vars;
}
function __construct(){
$this->ch = curl_init();
$this->cookie_file = 'cookie.txt';
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie_file);
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie_file);
curl_setopt($this->ch, CURLOPT_USERAGENT, "'Filnik's wikidipendenza.php");
#"Mozilla/5.0 (X11; U; Linux i686; it; rv:1.8.1.3) Gecko/20060601 Firefox/2.0.0.4 (Ubuntu-edgy)");
curl_setopt($this->ch,CURLOPT_MAXCONNECTS,100);
curl_setopt($this->ch,CURLOPT_CLOSEPOLICY,CURLCLOSEPOLICY_LEAST_RECENTLY_USED);
}
function post($url,$data) {
curl_setopt($this->ch,CURLOPT_URL,$url);
curl_setopt($this->ch,CURLOPT_FOLLOWLOCATION,True);
curl_setopt($this->ch,CURLOPT_MAXREDIRS,10);
curl_setopt($this->ch,CURLOPT_HEADER,0);
curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($this->ch,CURLOPT_TIMEOUT,30);
curl_setopt($this->ch,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($this->ch,CURLOPT_POST,True);
curl_setopt($this->ch,CURLOPT_POSTFIELDS, substr($this->data_encode($data), 0, -1) );
return curl_exec($this->ch);
}
function get($url){
curl_setopt($this->ch,CURLOPT_URL,$url);
curl_setopt($this->ch,CURLOPT_FOLLOWLOCATION,True);
curl_setopt($this->ch,CURLOPT_MAXREDIRS,10);
curl_setopt($this->ch,CURLOPT_HEADER,0);
curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($this->ch,CURLOPT_TIMEOUT,30);
curl_setopt($this->ch,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($this->ch,CURLOPT_HTTPGET,1);
return curl_exec($this->ch);
}
function __destruct(){
curl_close($this->ch);
@unlink($this->$cookie_file);
}
}
$wikiPage = $_REQUEST['wikiPage'];
echo "<form method=\"get\" action=\"{$_SERVER['PHP_SELF']}\" />
<table><tr><td>Page to parse:</td><td><input type=\"text\" name=\"wikiPage\" id=\"wikiPage\" size=\"70\" value=\"$wikiPage\" /></td></tr>";
$quorum = $_REQUEST['quorum'];
echo "<tr><td class=\"mw-label\">Percent required:</td>
<td class=\"mw-input\" id=\"quorum-max\">
<select name=\"quorum\" id=\"quorum\">";
if ($quorum != '' and $quorum != 0)
{
echo "<option value=\"$quorum\">$quorum%</option>";
}
foreach(range(0, 100) as $num){
echo "<option value=\"$num\">$num%</option>";
}
echo "</select></td></tr>";
#echo "<td><b>Selected:</b></td> <td>$quorum%</td></tr>";
if ($wikiPage != '')
{
$http = new http();
$testo = $http->get($wikiPage);
$testo = str_replace('<a href="/wiki/', '<a href="http://it.wikipedia.org/wiki/', $testo);
$regexp = '/<p><a name="(.*)" id="(.*?)"><\/a><\/p>/';
preg_match_all($regexp, $testo, $results);
echo "<tr><td class=\"mw-label\">Plus section:</td>
<td class=\"mw-input\" id=\"plus-max\">
<select name=\"plus\" id=\"plus\">";
$plus_section = $_REQUEST['plus'];
if ($plus_section != '')
{
echo "<option value=\"$plus_section\">$plus_section</option>";
}
foreach($results[1] as $section){
if ($plus_section != '' and $plus_section == $section)
{
echo ""; # Do nothing
}else{
echo "<option value=\"$section\">$section</option>";
}
}
echo "</select></td></tr>";
echo "<tr><td class=\"mw-label\">Minus section:</td>
<td class=\"mw-input\" id=\"minus-max\">
<select name=\"minus\" id=\"minus\">";
$minus_section = $_REQUEST['minus'];
if ($minus_section != '')
{
echo "<option value=\"$minus_section\">$minus_section</option>";
}
foreach($results[1] as $section){
if ($minus_section != '' and $minus_section == $section)
{
echo ""; # Do nothing
}else{
echo "<option value=\"$section\">$section</option>";
}
}
echo "</select></td></tr>";
}
?>
<tr>
<td class="mw-submit">
<input type='submit' accesskey="c"/>
</td></tr></table>
<?
$plus_section = $_REQUEST['plus'];
$minus_section = $_REQUEST['minus'];
if ($plus_section != '' and $minus_section != '')
{
$regexp2 = '/' . $plus_section . '(.*?)(?:<p>|<!--\s*?NewPP limit report\s*?Preprocessor node count)/s';
preg_match_all($regexp2, $testo, $results_plus);
$plus_votes = substr_count($results_plus[1][1], "<li>");
$regexp3 = '/' . $minus_section . '(.*?)(?:<p>|<!--\s*?NewPP limit report\s*?Preprocessor node count)/s';
preg_match_all($regexp3, $testo, $results_minus);
$minus_votes = substr_count($results_minus[1][1], "<li>");
$total_votes = $plus_votes + $minus_votes;
$percent_without_cent = $plus_votes / $total_votes;
$percent = $percent_without_cent * 100;
$percent_to_print = substr($percent,0,5);
#$perctent = $over_point . '.' . $below_point[0:2]
echo "<br/><b>Percent:</b> $percent_to_print%<br/>
<b>Plus votes:</b> $plus_votes<br/>
<b>Minus votes:</b> $minus_votes<br/>";
$votes_to_change_status = 1;
if ($percent >= $quorum)
{
while (1)
{
$status_votes = 'minus';
$minus_votes_modified = $minus_votes + $votes_to_change_status;
$percent_without_cent = $plus_votes / ($plus_votes + $minus_votes_modified);
$percent = $percent_without_cent * 100;
if ($percent >= $quorum)
{
$votes_to_change_status = $votes_to_change_status + 1;
}else{
break;
}
}
}else{
while (1)
{
$status_votes = 'pro';
$plus_votes_modified = $plus_votes + $votes_to_change_status;
//echo $plus_votes_modified . '<br/>';
$percent_without_cent = $plus_votes_modified / ($plus_votes_modified + $minus_votes);
//echo $percent_without_cent . '<br/>';
$percent = $percent_without_cent * 100;
if ($percent < $quorum){
$votes_to_change_status = $votes_to_change_status + 1;
}else{
break;
}
}
}
echo "<br/><b>Votes needed to pass the percent required:</b> $votes_to_change_status $status_votes
<br/> <small>(Please remember that this last function is quite unprecise)</small>";
}
?>
</div><!--content-->
</div><!--column-content-->
<div id="column-one">
<div id="p-logo" class="portlet">
<a title="Hosted by the Wikimedia Toolserver" href="/" style="background-image: url(toolserv.png);"></a>
</div><!--p-logo-->
<div id="p-navigation" class="portlet">
<h5>Navigation</h5>
<div class="pBody">
<ul>
<?
//Devo aprire il file.
$filename = "links.txt";
// copia il contenuto di un file in una stringa
//$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
if($handle)
{
$contents = fread($handle, filesize($filename));
fclose($handle);
echo $contents;
}
?>
</ul>
</div>
</div><!--p-navigation-->
</div><!--column-one-->
<div class="visualClear" />
<div id="footer">
<a href="http://tools.wikimedia.de/"><img
src="http://tools.wikimedia.de/wikimedia-toolserver-button.png"
alt="Hosted on the Toolserver" /></a>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10-blue"
alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
</div><!--footer-->
</div><!--globalWrapper-->
</body>
</html>