Removed CVS keywords from files, to make merging between branches
[lhc/web/wiklou.git] / includes / SpecialRandompage.php
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage SpecialPage
5 */
6
7 /**
8 * Constructor
9 */
10 function wfSpecialRandompage() {
11 global $wgOut, $wgTitle, $wgArticle, $wgExtraRandompageSQL;
12 $fname = 'wfSpecialRandompage';
13
14 # NOTE! We use a literal constant in the SQL instead of the RAND()
15 # function because RAND() will return a different value for every row
16 # in the table. That's both very slow and returns results heavily
17 # biased towards low values, as rows later in the table will likely
18 # never be reached for comparison.
19 #
20 # Using a literal constant means the whole thing gets optimized on
21 # the index, and the comparison is both fast and fair.
22
23 # interpolation and sprintf() can muck up with locale-specific decimal separator
24 $randstr = wfRandom();
25
26 $db =& wfGetDB( DB_SLAVE );
27 $use_index = $db->useIndexClause( 'cur_random' );
28 $cur = $db->tableName( 'cur' );
29
30 if ( $wgExtraRandompageSQL ) {
31 $extra = "AND ($wgExtraRandompageSQL)";
32 } else {
33 $extra = '';
34 }
35 $sqlget = "SELECT cur_id,cur_title
36 FROM $cur $use_index
37 WHERE cur_namespace=0 AND cur_is_redirect=0 $extra
38 AND cur_random>$randstr
39 ORDER BY cur_random
40 LIMIT 1";
41 $res = $db->query( $sqlget, $fname );
42
43 $title = null;
44 if( $s = $db->fetchObject( $res ) ) {
45 $title =& Title::makeTitle( NS_MAIN, $s->cur_title );
46 }
47 if( is_null( $title ) ) {
48 # That's not supposed to happen :)
49 $title =& Title::newFromText( wfMsg( 'mainpage' ) );
50 }
51 $wgOut->reportTime(); # for logfile
52 $wgOut->redirect( $title->getFullUrl() );
53 }
54
55 ?>