View Source
This tool shows you the source code for the latest version of Tangotango's tools.
Showing source code for userreg.php
<?php
$version = '1.10';
/*
User registration date/time finder
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('./includes/layout.php');
require_once('./includes/tsutils.php');
// This block must come BEFORE header, as it may set cookie
setDomainAndSubdom();
print_header(array('title' => 'User registration date/time finder'));
?>
<h1>User registration date/time finder</h1>
<?php
//If code requested
if (isset($_GET['code'])) {
echo "<h2>Source Code</h2>";
highlight_file(__FILE__);
print_footer();
exit;
}
?>
<p>This tool finds out when a user account was created.</p>
<ul>
<li>Please contact <a href="http://en.wikipedia.org/wiki/User_talk:Tangotango">Tangotango</a> if you need help, or if you see any anomalies with the data returned.</li>
<li>The intelligent estimate feature is based on <a href="http://tools.wikimedia.de/~interiot/cgi-bin/user_creation">Interiot's user_creation tool</a>.</li>
</ul>
<?php
function _print_footer() {
global $username, $database, $version, $subdom, $domain, $invaliddbnamespecified, $estimate;
if (isset($invaliddbnamespecified)) {
echo "<p class=\"minorerror\"><strong>Error:</strong> The project you selected is either non-existent or is not replicated to the toolserver.</p>";
}
?>
<hr />
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="ttf" style="margin-bottom:.5em">
<div class="ttfr"><span class="ttfl">Username:</span><span class="ttfi"><input type="text" name="user" class="ttfwe" value="<?php echo $username; ?>" /></span></div>
<div class="ttfr"><span class="ttfl">Wiki:</span><span class="ttfi"><?php print_dbselectform($subdom, $domain); ?></span></div>
<div class="ttfr"><span class="ttfl"></span><span class="ttfi"><label for="estimate"><input type="checkbox" name="estimate" id="estimate"<?php echo ($estimate) ? ' checked="checked"' : ''; ?> /> Attempt to estimate if data not found</label></span></div>
<div class="ttfr"><span class="ttfl"></span><span class="ttfi ttfib"><input type="submit" value="Find" /></span></div>
<div class="ttfs"></div>
</div>
</form>
<?php
print_replagindicator();
print_footer(array('code' => TRUE, 'version' => $version));
exit;
}
function bailout($msg) {
echo "<h2>Error</h2><p>$msg</p>";
_print_footer();
}
// BEGIN ======
$username = @$_GET['user'];
initdbh(); //Connect to server, as it needs to do this in any case
if (!empty($username) && !empty($database)) {
$estimate = isset($_GET['estimate']);
$database = addslashes($database); //Just in case (username is escaped later, properly)
$dbh->select($database);
$username = str_replace('_',' ',$username);
$username = mysql_real_escape_string($username);
//Find user ID/registration
$result = mysql_query("SELECT user_id, UNIX_TIMESTAMP(user_registration) AS user_reg FROM user WHERE user_name='$username' LIMIT 1");
if (!$result || (mysql_num_rows($result) == 0)) {
bailout('No such user found. Remember, your user name is case-sensitive; '
.'if you are on a wiki that capitalises the first letter of every title, be sure to do that here as well.');
}
$row = mysql_fetch_assoc($result);
$uid = $row['user_id'];
$reg = $row['user_reg'];
if (empty($reg)) {
$creation = "Data not available";
if ($estimate) {
$creation .= ' - see estimate below';
} else {
$creation .= ' - use estimation feature to find out';
}
} else {
$creation = gmdate('r',$reg);
$estimate = false;
}
echo "<h2>Precise results</h2>";
echo "<table class=\"wikitable\">";
$dbnice = substr($database,0,strlen($database)-2);
echo "<tr><th>User</th><td>{$username}@{$dbnice}</td></tr>";
echo "<tr><th>User ID</th><td>{$uid}</td></tr>";
echo "<tr><th>Registration</th><td>{$creation}</td></tr>";
echo "</table>";
if ($estimate) {
echo "<h2>Estimate</h2>";
$userlist = '';
for ($i = 0; $i < 12; $i++) {
if (empty($userlist)) {
$userlist = $uid + $i;
} else {
$userlist .= ', '. ($uid + $i);
}
}
$sql = "SELECT rev_user_text, rev_user, MIN(rev_timestamp) FROM revision WHERE rev_user IN ($userlist) GROUP BY rev_user_text ORDER BY rev_user";
$result = $dbh->query($sql);
$userids = array(); $usernames = array(); $minrevs = array();
while ($row = $dbh->fetch_row($result)) {
$userids[] = $row[1];
$usernames[] = $row[0];
$minrevs[] = mwTimeStampToUnix($row[2]);
}
//Find lowest minrev
$lowestminrev = min($minrevs); // <-- This is our estimate
//Print table
echo "<table class=\"wikitable\">";
echo "<tr><th>User ID</th><th>Username</th><th>First edit</th></tr>";
//Iterate
for ($i = 0; $i < count($userids); $i++) {
$uidcolumn = ($userids[$i] == $uid) ? ' class="pmtpa"' : '';
$minrevcolumn = ($minrevs[$i] == $lowestminrev) ? ' class="pmtpa"' : '';
$humanminrev = gmdate('r',$minrevs[$i]);
echo "<tr><td{$uidcolumn}>{$userids[$i]}</td><td{$uidcolumn}>{$usernames[$i]}</td><td{$minrevcolumn}>{$humanminrev}</td></tr>";
}
echo "</table>";
}
} else {
echo "<h2>Welcome</h2>";
echo "<p>Please enter valid values for all the fields and hit <strong>Find</strong>.</p>";
}
_print_footer();
?>
