View Source
This tool shows you the source code for the latest version of Tangotango's tools.
Showing source code for whatredirectshere.php
<?php
$version = '1.20';
/*
Special:Whatredirectshere
Copyright (C) 2006 Tangotango (tangotango.wp _at_ gmail _dot_ com)
### Many thanks to NullC for providing an optimized query! ###
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');
function _print_footer() {
global $version, $pagename2, $database, $wikitext, $lang, $uilang, $subdom, $domain, $invaliddbnamespecified;
if (isset($invaliddbnamespecified)) {
echo "<p class=\"minorerror\"><strong>{$lang['gen_error']}:</strong> {$lang['gen_nonexistent_wiki']}</p>";
}
?>
<hr />
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="lang" value="<?php echo $uilang; ?>" />
<div class="ttf" style="margin-bottom:.5em">
<div class="ttfr"><span class="ttfl"><?php echo $lang['wrh_title']; ?></span><span class="ttfi"><input type="text" name="title" size="30" value="<?php echo $pagename2; ?>" class="ttfwe" /></span></div>
<div class="ttfr"><span class="ttfl"><?php echo $lang['wrh_database']; ?></span><span class="ttfi"><?php print_dbselectform($subdom, $domain); ?></span></div>
<div class="ttfr"><span class="ttfl"><label for="wikitext"><?php echo $lang['wrh_wiki-text']; ?></label></span><span class="ttfi"><input type="checkbox" name="wikitext" id="wikitext"<?php if ($wikitext) echo ' checked="checked"'; ?> /></span></div>
<div class="ttfr"><span class="ttfl"></span><span class="ttfi ttfib"><input type="submit" value="<?php echo $lang['wrh_find_redirects']; ?>" /></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();
}
// ---------- Begin ---------- //
//Define available localisations
$langs['ar'] = 'العربية';
$langs['de'] = 'Deutsch';
$langs['es'] = 'Español';
$langs['fr'] = 'Français';
$langs['ja'] = '日本語';
$langs['lt'] = 'Lietuvių';
$langs['nl'] = 'Nederlands';
$langs['pl'] = 'Polski';
$langs['pt'] = 'Português';
$langs['ru'] = 'Русский';
$langs['sv'] = 'Svenska';
$langs['tet'] = 'Tetum';
$langs['vi'] = 'Tiếng Việt';
$langs['zh-hant'] = '正體中文';
$langs['zh-cn'] = '简体中文';
//Load languages
loadlanguages('whatredirectshere');
// This block must come BEFORE header, as it may set cookie
setDomainAndSubdom();
if ($uilang == 'ar')
$dir_prefix = 'rtl';
else
$dir_prefix = '';
print_header(array('title' => 'Whatredirectshere'));
echo "<h1>Whatredirectshere</h1>";
echo $lang['wrh_intro']; //Print the intro
$pagename2 = @$_GET['title'];
$wikitext = isset($_GET['wikitext']);
// If some sort of $database has been set
if (!empty($database)) {
//Get our host:
$ourhost = dbnameToHost($database);
if ($ourhost === FALSE) {
// This means the database does not exist
// Probably uncaught legacy db parameter
$invaliddbnamespecified = true;
$database = '';
} else {
//Parse our title:
$ti = parseWikiTitle($ourhost, $pagename2);
$ns = $ti[0];
$pagename = str_replace(' ','_',$ti[1]);
}
}
if (!empty($pagename) && !empty($database) && is_numeric($ns)) {
//Check for patently invalid database names:
if (!isValidDBname($database)) {
bailout($lang['gen_invalid_dbname']);
}
initdbh();
$dbh->select($database);
$pagename = $dbh->escape_string($pagename);
//Find out how many redirects there are in total
$sql = "SELECT count(*) FROM (select pl_from from pagelinks where pl_namespace=$ns and pl_title='$pagename') AS mysqlsucks JOIN page ON pl_from=page_id WHERE page_is_redirect = 1;";
$result = $dbh->query($sql);
if (!$result || ($dbh->num_rows($result) == 0)) {
bailout($lang['wrh_no_redirects']);
}
$count = $dbh->fetch_row($result);
//Calculate the pagination stuff
$pageno = isset($_GET['p']) ? $_GET['p'] : 1;
$numrows = $count[0];
$rowsperpage = 20;
$lastpage = ceil($numrows/$rowsperpage);
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
}
if ($lastpage == 0) {
$limit = '';
} else {
$limit = ' LIMIT '.($pageno - 1) * $rowsperpage .',' .$rowsperpage;
}
//Actual query
$sql = "SELECT page_title,page_namespace FROM (select pl_from from pagelinks where pl_namespace=$ns and pl_title='$pagename') AS mysqlsucks JOIN page ON pl_from=page_id WHERE page_is_redirect = 1{$limit}";
$result = $dbh->query($sql);
//Print results
echo "<hr />";
echo '<p>'.sprintf($lang['wrh_following_redirect'], '[['.getWikiTitle($ourhost,$ns,$pagename).']]').'</p>';
if ($wikitext) {
echo "<pre>";
while ($row = $dbh->fetch_assoc($result)) {
$wikititle = getWikiTitle($ourhost, $row['page_namespace'], $row['page_title']);
echo "* [[{$wikititle}]]\n";
}
echo "</pre>";
} else {
//echo "<ol style=\"margin-bottom:1em\">";
echo '<table class="orderedlist">';
$k = ($pageno - 1) * $rowsperpage;
while ($row = $dbh->fetch_assoc($result)) {
$k++;
$wikititle = getWikiTitle($ourhost, $row['page_namespace'], $row['page_title']);
$wikiurl = getWikiURL($ourhost, $row['page_namespace'], $row['page_title'],TRUE);
//echo "<li><a href=\"{$wikiurl}\">{$wikititle}</a></li>";
echo "<tr><th>{$k}</th><td><a href=\"{$wikiurl}\">{$wikititle}</a></td></tr>";
}
echo "</table>";
//echo "</ol>";
}
//Print pagination links
//Generate query string necessary to recreate query (lang, title, subdom, domain, wikitext)
$qs = '&lang='.@$_GET['lang'].'&title='.@$_GET['title'].'&subdom='.@$_GET['subdom'].'&domain='.@$_GET['domain'];
if (isset($_GET['wikitext'])) $qs .= '&wikitext=yes';
echo '<div style="font-size:85%;margin:1em 0">';
if ($pageno == 1) {
echo '< Previous';
} else {
$prevpage = $pageno-1;
echo "<a href=\"{$_SERVER['PHP_SELF']}?p={$prevpage}{$qs}\">< Previous</a>";
}
echo ' ';
for ($i = 1; $i <= $lastpage; $i++) {
if ($i == $pageno) {
echo " <strong>$i</strong> ";
} else {
echo " <a href=\"{$_SERVER['PHP_SELF']}?p={$i}{$qs}\">$i</a> ";
}
}
echo ' ';
if ($pageno == $lastpage) {
echo 'Next >';
} else {
$nextpage = $pageno+1;
echo "<a href=\"{$_SERVER['PHP_SELF']}?p={$nextpage}{$qs}\">Next ></a>";
}
echo '</div>';
} else {
echo "<h2>{$lang['gen_welcome']}</h2>";
echo "<p>{$lang['wrh_directions']}</p>";
}
_print_footer();
?>
