I had a fix for this bug sitting in my working copy for over a week without getting...
[lhc/web/wiklou.git] / includes / SpecialRandompage.php
1 <?php
2 /**
3 * @version # $Id$
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * Constructor
10 */
11 function wfSpecialRandompage() {
12 global $wgOut, $wgTitle, $wgArticle, $wgExtraRandompageSQL;
13 $fname = 'wfSpecialRandompage';
14
15 $rand = mt_rand() / mt_getrandmax();
16 # interpolation and sprintf() can muck up with locale-specific decimal separator
17 $randstr = number_format( $rand, 12, ".", "" );
18 $db =& wfGetDB( DB_SLAVE );
19 $use_index = $db->useIndexClause( 'cur_random' );
20 $cur = $db->tableName( 'cur' );
21
22 if ( $wgExtraRandompageSQL ) {
23 $extra = "AND ($wgExtraRandompageSQL)";
24 } else {
25 $extra = '';
26 }
27 $sqlget = "SELECT cur_id,cur_title
28 FROM $cur $use_index
29 WHERE cur_namespace=0 AND cur_is_redirect=0 $extra
30 AND cur_random>$randstr
31 ORDER BY cur_random
32 LIMIT 1";
33 $res = $db->query( $sqlget, $fname );
34 if( $s = $db->fetchObject( $res ) ) {
35 $rt = wfUrlEncode( $s->cur_title );
36 } else {
37 # No articles?!
38 $rt = "";
39 }
40
41 $wgOut->reportTime(); # for logfile
42 $wgOut->redirect( wfLocalUrl( $rt ) );
43 }
44
45 ?>