2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-06-09 16:19:24 +00:00
|
|
|
# $Id$
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
function wfSpecialRandompage()
|
|
|
|
|
{
|
2004-07-10 03:09:26 +00:00
|
|
|
global $wgOut, $wgTitle, $wgArticle, $wgExtraRandompageSQL;
|
2003-04-14 23:10:40 +00:00
|
|
|
$fname = "wfSpecialRandompage";
|
|
|
|
|
|
2003-06-03 21:27:06 +00:00
|
|
|
$rand = mt_rand() / mt_getrandmax();
|
2003-06-06 18:38:14 +00:00
|
|
|
# interpolation and sprintf() can muck up with locale-specific decimal separator
|
|
|
|
|
$randstr = number_format( $rand, 12, ".", "" );
|
2004-07-18 08:48:43 +00:00
|
|
|
$db =& wfGetDB( DB_SLAVE );
|
2004-07-10 03:09:26 +00:00
|
|
|
$use_index = $db->useIndexClause( 'cur_random' );
|
2004-07-18 08:48:43 +00:00
|
|
|
$cur = $db->tableName( 'cur' );
|
|
|
|
|
|
2004-07-10 01:25:42 +00:00
|
|
|
if ( $wgExtraRandompageSQL ) {
|
|
|
|
|
$extra = "AND ($wgExtraRandompageSQL)";
|
|
|
|
|
} else {
|
|
|
|
|
$extra = '';
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
$sqlget = "SELECT cur_id,cur_title
|
2004-07-18 08:48:43 +00:00
|
|
|
FROM $cur $use_index
|
2004-07-10 01:25:42 +00:00
|
|
|
WHERE cur_namespace=0 AND cur_is_redirect=0 $extra
|
2003-06-06 18:38:14 +00:00
|
|
|
AND cur_random>$randstr
|
2003-04-14 23:10:40 +00:00
|
|
|
ORDER BY cur_random
|
|
|
|
|
LIMIT 1";
|
2004-07-10 03:09:26 +00:00
|
|
|
$res = $db->query( $sqlget, $fname );
|
|
|
|
|
if( $s = $db->fetchObject( $res ) ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$rt = wfUrlEncode( $s->cur_title );
|
|
|
|
|
} else {
|
|
|
|
|
# No articles?!
|
|
|
|
|
$rt = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$wgOut->reportTime(); # for logfile
|
|
|
|
|
$wgOut->redirect( wfLocalUrl( $rt ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|