wiki.techinc.nl/includes/SpecialRandompage.php

31 lines
725 B
PHP
Raw Normal View History

2003-04-14 23:10:40 +00:00
<?
function wfSpecialRandompage()
{
global $wgOut, $wgTitle, $wgArticle, $force;
$fname = "wfSpecialRandompage";
wfSeedRandom();
$rand = mt_rand() / mt_getrandmax();
# interpolation and sprintf() can muck up with locale-specific decimal separator
$randstr = number_format( $rand, 12, ".", "" );
2003-04-14 23:10:40 +00:00
$sqlget = "SELECT cur_id,cur_title
FROM cur USE INDEX (cur_random)
WHERE cur_namespace=0 AND cur_is_redirect=0
AND cur_random>$randstr
2003-04-14 23:10:40 +00:00
ORDER BY cur_random
LIMIT 1";
2003-09-20 02:21:40 +00:00
$res = wfQuery( $sqlget, DB_READ, $fname );
2003-04-14 23:10:40 +00:00
if( $s = wfFetchObject( $res ) ) {
$rt = wfUrlEncode( $s->cur_title );
} else {
# No articles?!
$rt = "";
}
$wgOut->reportTime(); # for logfile
$wgOut->redirect( wfLocalUrl( $rt ) );
}
?>