View Source
This tool shows you the source code for the latest version of Tangotango's tools.
Showing source code for rfa.php
<?php
$version = '1.51';
/*
RfA Analysis
Now supports RFALib 2.0 and higher
Copyright (C) 2006 Tangotango (tangotango.wp _at_ gmail _dot_ com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
require_once('./phpwikipedia.php');
require_once('./includes/layout.php');
require_once('./rfalib2.php');
require_once('./dateguess.php');
define('USERAGENT','Mozilla/5.0 (compatible; Tangobot-TOOL/1.0)');
define('WIKILOCATION','http://en.wikipedia.org/w/');
$cookiefile = dirname(__FILE__).'/ttbotcookies.txt';
$hostserver = 'en.wikipedia.org';
function print_h_l($var,$searchlist) {
if (empty($var)) {
echo "<ul><li>No items in list</li></ul>";
}
echo "<ol>";
foreach ($var as $vr) {
$iffy = False;
if (isset($vr['iffy'])) {
$iffy = $vr['iffy'];
}
if (isset($vr['error'])) {
$text = "<strong>Error parsing signature:</strong> <em>".htmlspecialchars($vr['context'])."</em>";
} else {
$text = $vr['name'];
}
if (isset($vr['name']) && in_array($vr['name'],$searchlist)) {
if ($iffy == 1)
echo "<li class=\"dup iffy1\">{$text}</li>\n";
else
echo "<li class=\"dup\">{$text}</li>\n";
} else {
if ($iffy == 1)
echo "<li class=\"iffy1\">{$text}</li>\n";
else
echo "<li>{$text}</li>\n";
}
}
echo "</ol>";
}
function bailout($message) {
echo "<h3>Fatal Error</h3>";
echo "<p>$message</p>";
print_footer(array('code' => TRUE));
exit;
}
//BEGIN ==
print_header(array('title' => 'RfA Analysis'));
?>
<h1>RfA Analysis</h1>
<p>This tool identifies duplicate voters in a <a href="http://en.wikipedia.org/wiki/Wikipedia:Requests_for_adminship">Request for adminship</a> on the English Wikipedia. This tool can also analyze Requests for bureaucratship pages.</p>
<p>Source code for the library used (rfalib.php) is available <a href="./viewsource.php?file=rfalib2.php">here</a>. This tool is curently using version <?php echo rfa_getver();?> of the library.</p>
<?php
if (isset($_GET['p'])) {
$targetpage = str_replace(' ','_',$_GET['p']);
echo "<h2>Voters for <a href=\"http://{$hostserver}/wiki/{$targetpage}\">{$_GET['p']}</a></h2>";
$getpage = $targetpage;
//$buffer = file_get_contents('input.txt');
$buffer = getRawPage($getpage);
if (($buffer === False) or (trim($buffer) == '')) {
bailout("Failed to load \"$getpage\" from server");
}
if (preg_match("/#redirect:?\s*?\[\[\s*?(.*?)\s*?\]\]/i",$buffer,$match)) {
bailout("Page redirects to {$match[1]}<br /><a href=\"{$_SERVER['PHP_SELF']}?p=".urlencode($match[1])."\">Click here to analyze it</a>");
}
//Create an RFA object
$myRFA = new RFA();
$result = $myRFA->analyze($buffer);
if ($result !== TRUE) {
bailout($myRFA->lasterror);
}
$enddate = guessdate($myRFA->enddate);
if ($enddate == 0) {
$enddate = $myRFA->enddate;
} else {
$enddate = gmdate('r',$enddate);
}
$tally = count($myRFA->support).'/'.count($myRFA->oppose).'/'.count($myRFA->neutral);
echo "<p><a href=\"http://{$hostserver}/wiki/User:{$myRFA->username}\">{$myRFA->username}</a>'s RfA ({$tally}); End date: {$enddate}.</p>";
echo '<p>Found <strong>'.count($myRFA->duplicates).'</strong> duplicate votes (highlighted in <span class="dup">red</span>).'
.' Votes the tool is unsure about are <span class="iffy1">italicized</span>.</p>';
/* <!-- Votes that are really iffy are <span class="iffy2">underlined</span>.--></p>'; */
echo "<h3>Support</h3>";
print_h_l($myRFA->support,$myRFA->duplicates);
echo "<h3>Oppose</h3>";
print_h_l($myRFA->oppose,$myRFA->duplicates);
echo "<h3>Neutral</h3>";
print_h_l($myRFA->neutral,$myRFA->duplicates);
}
?>
<h2>Analyze</h2>
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<strong>RfA page:</strong>
<input type="text" name="p" size="50" value="<?php echo (isset($_GET['p'])) ? $_GET['p'] : "Wikipedia:Requests for adminship/Name of user" ?>" />
<input type="submit" value="Analyze" />
</form>
<?php
print_footer(array('code' => TRUE, 'version' => $version));
?>
