OOP calling convention for database functions. DBMS abstraction implemented by means...
[lhc/web/wiklou.git] / includes / SpecialRandompage.php
1 <?php
2 # $Id$
3
4 function wfSpecialRandompage()
5 {
6 global $wgOut, $wgTitle, $wgArticle, $wgExtraRandompageSQL;
7 $fname = "wfSpecialRandompage";
8
9 wfSeedRandom();
10 $rand = mt_rand() / mt_getrandmax();
11 # interpolation and sprintf() can muck up with locale-specific decimal separator
12 $randstr = number_format( $rand, 12, ".", "" );
13 $db =& wfGetDB( DB_READ );
14 $use_index = $db->useIndexClause( 'cur_random' );
15 if ( $wgExtraRandompageSQL ) {
16 $extra = "AND ($wgExtraRandompageSQL)";
17 } else {
18 $extra = '';
19 }
20 $sqlget = "SELECT cur_id,cur_title
21 FROM cur $use_index
22 WHERE cur_namespace=0 AND cur_is_redirect=0 $extra
23 AND cur_random>$randstr
24 ORDER BY cur_random
25 LIMIT 1";
26 $res = $db->query( $sqlget, $fname );
27 if( $s = $db->fetchObject( $res ) ) {
28 $rt = wfUrlEncode( $s->cur_title );
29 } else {
30 # No articles?!
31 $rt = "";
32 }
33
34 $wgOut->reportTime(); # for logfile
35 $wgOut->redirect( wfLocalUrl( $rt ) );
36 }
37
38 ?>