View Source
This tool shows you the source code for the latest version of Tangotango's tools.
Showing source code for milestone.php
<?php
$version = '1.71';
/*
Milestone tool - Finds users' milestone edits
Copyright (C) 2006-2007 Tangotango (tangotango _at_ ts _dot_ wikimedia _dot_ org)
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/tsutils.php');
require_once('./includes/layout.php');
function _print_footer() {
global $username, $database, $_milestone, $version, $subdom, $domain, $invaliddbnamespecified, $lang, $uilang;
if (isset($invaliddbnamespecified)) {
echo "<p class=\"minorerror\"><strong>{$lang['gen_error']}:</strong> {$lang['gen_nonexistent_wiki']}</p>";
}
if ($uilang == 'ar')
$dir_prefix = 'rtl';
else
$dir_prefix = '';
?>
<hr />
<form method="get" action="milestone.php">
<div class="ttf" style="margin-bottom:.5em">
<div class="ttfr"><span class="ttfl<?php echo $dir_prefix; ?>"><?php echo $lang['mil_username']; ?></span><span class="ttfi<?php echo $dir_prefix; ?>"><input type="text" name="user" class="ttfwe" value="<?php echo $username; ?>" /></span></div>
<div class="ttfr"><span class="ttfl<?php echo $dir_prefix; ?>"><?php echo $lang['mil_wiki']; ?></span><span class="ttfi<?php echo $dir_prefix; ?>"><?php print_dbselectform($subdom, $domain); ?></span></div>
<div class="ttfr"><span class="ttfl<?php echo $dir_prefix; ?>"><?php echo $lang['mil_milestone']; ?></span><span class="ttfi<?php echo $dir_prefix; ?>"><input type="text" class="ttfwe" name="ms" value="<?php echo $_milestone; ?>" /></span></div>
<div class="ttfr"><span class="ttfl<?php echo $dir_prefix; ?>"><?php echo $lang['gen_namespace']; ?></span><span class="ttfi<?php echo $dir_prefix; ?>"><input type="text" class="ttfwe" name="ns" value="<?php echo $namespace; ?>" /></span></div>
<div class="ttfr"><span class="ttfl<?php echo $dir_prefix; ?>"> </span><span class="ttfi<?php echo $dir_prefix; ?>"><?php echo $lang['mil_nsnote']; ?></span></div>
<div class="ttfr"><span class="ttfl<?php echo $dir_prefix; ?>"></span><span class="ttfi<?php echo $dir_prefix; ?> ttfib"><input type="submit" value="<?php echo $lang['mil_findmilestone']; ?>" /></span></div>
<div class="ttfs"></div>
</div>
</form>
<?php
print_replagindicator();
print_footer(array('code' => TRUE, 'version' => $version));
exit;
}
function bailout($msg) {
global $lang;
echo "<h2>{$lang['gen_error']}</h2><p>$msg</p>";
_print_footer();
}
function returnBoolean($int) {
if ($int)
return 'Yes';
else
return 'No';
}
// ---------- Begin ---------- //
// This block must come BEFORE header, as it may set cookie
setDomainAndSubdom();
//Define available localisations
$langs['ar'] = 'العربية';
$langs['de'] = 'Deutsch';
$langs['fi'] = 'Suomi';
$langs['fr'] = 'Français';
$langs['it'] = 'Italiano';
$langs['ja'] = '日本語';
$langs['nl'] = 'Nederlands';
$langs['pl'] = 'Polski';
$langs['pt'] = 'Português';
$langs['ru'] = 'Русский';
$langs['sk'] = 'Slovenčina';
$langs['sv'] = 'Svenska';
$langs['zh-hant'] = '正體中文';
$langs['zh-cn'] = '简体中文';
//Load languages
loadlanguages('milestone');
print_header(array('title' => 'Milestone'));
echo '<h1>Milestone</h1>';
echo $lang['mil_intro'];
$username = @$_GET['user'];
$_milestone = @$_GET['ms']; //1-based count
$milestone = $_milestone - 1; //Zero-based count
$namespace = @$_GET['ns'];
initdbh(); //Connect to DB
if ($_milestone == '')
$_milestone = 100;
if (!is_numeric($namespace))
$namespace = '';
if (!empty($username) && !empty($database) && is_numeric($milestone) && ($milestone >= 0)) {
if (($_milestone >= 2000) && ($_milestone % 500 != 0)) {
bailout($lang['mil_miser']);
}
$database = mysql_real_escape_string($database);
$username = mysql_real_escape_string($username);
$dbh->select($database);
//Find user ID
$result = mysql_query("SELECT user_id FROM user WHERE user_name='$username' LIMIT 1;");
if (!$result || (mysql_num_rows($result) == 0)) {
bailout($lang['mil_nosuchuser']);
}
$row = mysql_fetch_assoc($result);
$uid = $row['user_id'];
//Find edit count
$result = mysql_query("SELECT COUNT(*) FROM revision, page WHERE rev_user=$uid AND rev_page = page_id;");
if (!$result || (mysql_num_rows($result) == 0)) {
bailout($lang['mil_noeditcount']);
}
$row = mysql_fetch_array($result);
$editcount = $row[0];
//echo "<p>User has $editcount edits.</p>";
if ($_milestone > $editcount) {
bailout(sprintf($lang['mil_notenoughedits'],$editcount));
}
$nsquery = '';
if ($namespace != '')
$nsquery = "AND page_namespace = {$namespace} ";
$result = mysql_query("SELECT rev_id,rev_minor_edit,rev_comment,UNIX_TIMESTAMP(rev_timestamp) AS utctime,page_namespace,page_title "
."FROM revision, page WHERE rev_user=$uid AND rev_page = page_id {$nsquery}LIMIT $milestone,1;");
if (!$result) {
bailout($lang['gen_query_failed'] . mysql_error());
}
if (mysql_num_rows($result) == 0) {
bailout($lang['gen_query_failed_badrowcount']);
}
$row = mysql_fetch_assoc($result);
$ourhost = dbnameToHost($database);
echo "<h2>{$lang['mil_results']}</h2>";
echo "<table class=\"wikitable\">";
echo "<tr><th colspan=\"2\">{$lang['mil_editnumber']} {$_milestone}</th></tr>";
echo "<tr><th>{$lang['mil_datetime']}</th><td>".gmdate('r',$row['utctime'])."</td></tr>";
echo "<tr><th>{$lang['mil_editsummary']}</th><td>".$row['rev_comment']."</td></tr>";
$wikititle = getWikiTitle($ourhost, $row['page_namespace'], $row['page_title']);
$wikiurl = getWikiURL ($ourhost, $row['page_namespace'], $row['page_title'], true);
$diffurl = getWikiURL ($ourhost, $row['page_namespace'], $row['page_title'])."&diff=prev&oldid=".$row['rev_id'];
echo "<tr><th>{$lang['mil_pagetitle']}</th><td><a href=\"$wikiurl\">$wikititle</a></td></tr>";
echo "<tr><th>{$lang['mil_minoredit']}</th><td>".returnBoolean($row['rev_minor_edit'])."</td></tr>";
echo "<tr><th>{$lang['mil_revision']}</th><td><a href=\"{$diffurl}\">{$row['rev_id']}</td></tr>";
echo "</table>";
} else {
echo "<h2>{$lang['gen_welcome']}</h2>";
echo "<p>{$lang['mil_instructions']}</p>";
}
_print_footer();
?>
