changing wfQuery to allow replication
[lhc/web/wiklou.git] / includes / SpecialRandompage.php
1 <?
2
3 function wfSpecialRandompage()
4 {
5 global $wgOut, $wgTitle, $wgArticle, $force;
6 $fname = "wfSpecialRandompage";
7
8 wfSeedRandom();
9 $rand = mt_rand() / mt_getrandmax();
10 # interpolation and sprintf() can muck up with locale-specific decimal separator
11 $randstr = number_format( $rand, 12, ".", "" );
12 $sqlget = "SELECT cur_id,cur_title
13 FROM cur USE INDEX (cur_random)
14 WHERE cur_namespace=0 AND cur_is_redirect=0
15 AND cur_random>$randstr
16 ORDER BY cur_random
17 LIMIT 1";
18 $res = wfQuery( $sqlget, DB_READ, $fname );
19 if( $s = wfFetchObject( $res ) ) {
20 $rt = wfUrlEncode( $s->cur_title );
21 } else {
22 # No articles?!
23 $rt = "";
24 }
25
26 $wgOut->reportTime(); # for logfile
27 $wgOut->redirect( wfLocalUrl( $rt ) );
28 }
29
30 ?>