* Special:RandomFA for getting a random featured article
[lhc/web/wiklou.git] / includes / SpecialRandomFA.php
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage SpecialPage
5 */
6
7 /**
8 * Constructor
9 */
10 function wfSpecialRandomFA() {
11 global $wgOut, $wgTitle, $wgArticle, $wgContLang;
12 $fname = 'wfSpecialRandomFA';
13
14 $dbr =& wfGetDB( DB_SLAVE );
15 $use_index = $dbr->useIndexClause( 'page_random' );
16 extract( $dbr->tableNames( 'page', 'pagelinks' ) );
17
18 $randstr = wfRandom();
19 $ft = Title::newFromText( wfMsgForContent( 'featuredtemplate' ) );
20 if ( is_null( $ft ) ) {
21 $title = Title::newFromText( wfMsgForContent( 'mainpage' ) );
22 $wgOut->redirect( $title->getFullUrl() );
23 return;
24 }
25 $template = $dbr->addQuotes( $ft->getDBkey() );
26 $sql = "
27 SELECT page_title, page_random
28 FROM $pagelinks
29 LEFT JOIN $page $use_index ON page_id = pl_from
30 WHERE pl_title = $template AND pl_namespace = " . NS_TEMPLATE . " AND page_namespace = " . NS_TALK . " AND page_random > $randstr
31 ORDER BY page_random
32 ";
33 $sql = $dbr->limitResult($sql, 1, 0);
34 $res = $dbr->query( $sql, $fname );
35
36 $title = null;
37 if ( $s = $dbr->fetchObject( $res ) ) {
38 $title =& Title::makeTitle( NS_MAIN, $s->page_title );
39 }
40 if ( is_null( $title ) ) {
41 # That's not supposed to happen :)
42 $title = Title::newFromText( wfMsgForContent( 'mainpage' ) );
43 }
44 $wgOut->reportTime(); # for logfile
45 $wgOut->redirect( $title->getFullUrl() );
46 }
47
48 ?>