Add "longdesc" attribute to all (non-external) images, containing
[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 # 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.
20 #
21 # Using a literal constant means the whole thing gets optimized on
22 # the index, and the comparison is both fast and fair.
23
24 # interpolation and sprintf() can muck up with locale-specific decimal separator
25 $randstr = wfRandom();
26
27 $db =& wfGetDB( DB_SLAVE );
28 $use_index = $db->useIndexClause( 'cur_random' );
29 $cur = $db->tableName( 'cur' );
30
31 if ( $wgExtraRandompageSQL ) {
32 $extra = "AND ($wgExtraRandompageSQL)";
33 } else {
34 $extra = '';
35 }
36 $sqlget = "SELECT cur_id,cur_title
37 FROM $cur $use_index
38 WHERE cur_namespace=0 AND cur_is_redirect=0 $extra
39 AND cur_random>$randstr
40 ORDER BY cur_random
41 LIMIT 1";
42 $res = $db->query( $sqlget, $fname );
43
44 $title = null;
45 if( $s = $db->fetchObject( $res ) ) {
46 $title =& Title::makeTitle( NS_MAIN, $s->cur_title );
47 }
48 if( is_null( $title ) ) {
49 # That's not supposed to happen :)
50 $title =& Title::newFromText( wfMsg( 'mainpage' ) );
51 }
52 $wgOut->reportTime(); # for logfile
53 $wgOut->redirect( $title->getFullUrl() );
54 }
55
56 ?>