* Special:RandomFA for getting a random featured article
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Fri, 30 Sep 2005 23:34:50 +0000 (23:34 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Fri, 30 Sep 2005 23:34:50 +0000 (23:34 +0000)
includes/SpecialPage.php
includes/SpecialRandomFA.php [new file with mode: 0644]
languages/Language.php

index b379a60..99788b8 100644 (file)
@@ -36,6 +36,7 @@ $wgSpecialPages = array(
        'Listusers'         => new SpecialPage( 'Listusers' ),
        'Statistics'        => new SpecialPage( 'Statistics' ),
        'Random'        => new SpecialPage( 'Randompage' ),
+       'RandomFA'          => new SpecialPage( 'RandomFA' ),
        'Lonelypages'       => new SpecialPage( 'Lonelypages' ),
        'Uncategorizedpages'=> new SpecialPage( 'Uncategorizedpages' ),
        'Uncategorizedcategories'=> new SpecialPage( 'Uncategorizedcategories' ),
diff --git a/includes/SpecialRandomFA.php b/includes/SpecialRandomFA.php
new file mode 100644 (file)
index 0000000..bec471f
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ * Constructor
+ */
+function wfSpecialRandomFA() {
+       global $wgOut, $wgTitle, $wgArticle, $wgContLang;
+       $fname = 'wfSpecialRandomFA';   
+
+       $dbr =& wfGetDB( DB_SLAVE );
+       $use_index = $dbr->useIndexClause( 'page_random' );
+       extract( $dbr->tableNames( 'page', 'pagelinks' ) );
+
+       $randstr = wfRandom();
+       $ft = Title::newFromText( wfMsgForContent( 'featuredtemplate' ) );
+       if ( is_null( $ft ) ) {
+               $title = Title::newFromText( wfMsgForContent( 'mainpage' ) );
+               $wgOut->redirect( $title->getFullUrl() );
+               return;
+       }
+       $template = $dbr->addQuotes( $ft->getDBkey() );
+       $sql = "
+               SELECT page_title, page_random
+               FROM $pagelinks
+               LEFT JOIN $page $use_index ON page_id = pl_from
+               WHERE pl_title = $template AND pl_namespace = " . NS_TEMPLATE . " AND page_namespace = " . NS_TALK . " AND page_random > $randstr
+               ORDER BY page_random
+               ";
+       $sql = $dbr->limitResult($sql, 1, 0);
+       $res = $dbr->query( $sql, $fname );
+
+       $title = null;
+       if ( $s = $dbr->fetchObject( $res ) ) {
+               $title =& Title::makeTitle( NS_MAIN, $s->page_title );
+       }
+       if ( is_null( $title ) ) {
+               # That's not supposed to happen :)
+               $title = Title::newFromText( wfMsgForContent( 'mainpage' ) );
+       }
+       $wgOut->reportTime(); # for logfile
+       $wgOut->redirect( $title->getFullUrl() );
+}
+
+?>
index ee3b63e..53ae7d8 100644 (file)
@@ -1106,6 +1106,7 @@ That comes to '''$5''' average edits per page, and '''$6''' views per edit.",
 'maintenancebacklink'  => 'Back to Maintenance Page',
 'disambiguations'      => 'Disambiguation pages',
 'disambiguationspage'  => 'Template:disambig',
+'featuredtemplate'      => 'Template:Featured',
 'disambiguationstext'  => "The following pages link to a <i>disambiguation page</i>. They should link to the appropriate topic instead.<br />A page is treated as disambiguation if it is linked from $1.<br />Links from other namespaces are <i>not</i> listed here.",
 'doubleredirects'      => 'Double redirects',
 'doubleredirectstext'  => "Each row contains links to the first and second redirect, as well as the first line of the second redirect text, usually giving the \"real\" target page, which the first redirect should point to.",