5 * @subpackage SpecialPage
11 function wfSpecialRandompage() {
12 global $wgOut, $wgTitle, $wgArticle, $wgExtraRandompageSQL;
13 $fname = 'wfSpecialRandompage';
15 # NOTE! We use a literal constant in the SQL instead of the RAND()
16 # function because RAND() will return a different value for every row
17 # in the table. That's both very slow and returns results heavily
18 # biased towards low values, as rows later in the table will likely
19 # never be reached for comparison.
21 # Using a literal constant means the whole thing gets optimized on
22 # the index, and the comparison is both fast and fair.
24 # interpolation and sprintf() can muck up with locale-specific decimal separator
25 $randstr = wfRandom();
27 $db =& wfGetDB( DB_SLAVE
);
28 $use_index = $db->useIndexClause( 'cur_random' );
29 $cur = $db->tableName( 'cur' );
31 if ( $wgExtraRandompageSQL ) {
32 $extra = "AND ($wgExtraRandompageSQL)";
36 $sqlget = "SELECT cur_id,cur_title
38 WHERE cur_namespace=0 AND cur_is_redirect=0 $extra
39 AND cur_random>$randstr
42 $res = $db->query( $sqlget, $fname );
45 if( $s = $db->fetchObject( $res ) ) {
46 $title =& Title
::makeTitle( NS_MAIN
, $s->cur_title
);
48 if( is_null( $title ) ) {
49 # That's not supposed to happen :)
50 $title =& Title
::newFromText( wfMsg( 'mainpage' ) );
52 $wgOut->reportTime(); # for logfile
53 $wgOut->redirect( $title->getFullUrl() );