00001 <?php 00002 # $Id: SpecialRandompage.php,v 1.7 2004/06/09 16:19:24 midom Exp $ 00003 00004 function wfSpecialRandompage() 00005 { 00006 global $wgOut, $wgTitle, $wgArticle, $wgIsMySQL; 00007 $fname = "wfSpecialRandompage"; 00008 00009 wfSeedRandom(); 00010 $rand = mt_rand() / mt_getrandmax(); 00011 # interpolation and sprintf() can muck up with locale-specific decimal separator 00012 $randstr = number_format( $rand, 12, ".", "" ); 00013 $use_index=$wgIsMySQL?"USE INDEX (cur_random)":""; 00014 $sqlget = "SELECT cur_id,cur_title 00015 FROM cur $use_index 00016 WHERE cur_namespace=0 AND cur_is_redirect=0 00017 AND cur_random>$randstr 00018 ORDER BY cur_random 00019 LIMIT 1"; 00020 $res = wfQuery( $sqlget, DB_READ, $fname ); 00021 if( $s = wfFetchObject( $res ) ) { 00022 $rt = wfUrlEncode( $s->cur_title ); 00023 } else { 00024 # No articles?! 00025 $rt = ""; 00026 } 00027 00028 $wgOut->reportTime(); # for logfile 00029 $wgOut->redirect( wfLocalUrl( $rt ) ); 00030 } 00031 00032 ?>