(bug 5684) Introduce Special:Randomredirect
authorRob Church <robchurch@users.mediawiki.org>
Tue, 25 Apr 2006 01:01:10 +0000 (01:01 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Tue, 25 Apr 2006 01:01:10 +0000 (01:01 +0000)
RELEASE-NOTES
includes/SpecialPage.php
includes/SpecialRandomredirect.php [new file with mode: 0644]
languages/Messages.php

index 6963dd9..aecb768 100644 (file)
@@ -117,6 +117,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Treat "allmessagesnotsupporteddb" as wikitext when echoing; change default text
 * (bug 5497) regeression in HTML normalization in 1.6 (unclosed <li>,<dd>,<dt>)
 * (bug 5709) Allow customisation of separator for categories
+* (bug 5684) Introduce Special:Randomredirect
 
 == Compatibility ==
 
index 72ce4dc..a0eca5a 100644 (file)
@@ -80,6 +80,7 @@ $wgSpecialPages = array(
        'Listredirects' => new SpecialPage( 'Listredirects' ),
        'Revisiondelete' => new SpecialPage( 'Revisiondelete', 'deleterevision' ),
        'Unusedtemplates' => new SpecialPage( 'Unusedtemplates' ),
+       'Randomredirect' => new SpecialPage( 'Randomredirect' ),
 );
 
 if( !$wgDisableCounters ) {
diff --git a/includes/SpecialRandomredirect.php b/includes/SpecialRandomredirect.php
new file mode 100644 (file)
index 0000000..512553c
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ * Special page to direct the user to a random redirect page (minus the second redirect)
+ *
+ * @package MediaWiki
+ * @subpackage Special pages
+ * @author Rob Church <robchur@gmail.com>
+ * @licence GNU General Public Licence 2.0 or later
+ */
+
+/**
+ * Main execution point
+ * @param $par Namespace to select the redirect from
+ */
+function wfSpecialRandomredirect( $par = NULL ) {
+       global $wgOut, $wgExtraRandompageSQL, $wgContLang;
+       $fname = 'wfSpecialRandomredirect';
+
+       # Validate the namespace
+       $namespace = $wgContLang->getNsIndex( $par );
+       if( $namespace === false || $namespace < NS_MAIN )
+               $namespace = NS_MAIN;
+
+       # Same logic as RandomPage
+       $randstr = wfRandom();
+
+       $dbr =& wfGetDB( DB_SLAVE );
+       $use_index = $dbr->useIndexClause( 'page_random' );
+       $page = $dbr->tableName( 'page' );
+
+       $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : '';
+       $sql = "SELECT page_id,page_title
+               FROM $page $use_index
+               WHERE page_namespace = $namespace AND page_is_redirect = 1 $extra
+               AND page_random > $randstr
+               ORDER BY page_random";
+               
+       $sql = $dbr->limitResult( $sql, 1, 0 );
+       $res = $dbr->query( $sql, $fname );
+
+       $title = NULL;
+       if( $row = $dbr->fetchObject( $res ) )
+               $title = Title::makeTitleSafe( $namespace, $row->page_title );
+
+       # Catch dud titles and return to the main page
+       if( is_null( $title ) )
+               $title = Title::newFromText( wfMsg( 'mainpage' ) );
+               
+       $wgOut->reportTime();
+       $wgOut->redirect( $title->getFullUrl( 'redirect=no' ) );
+}
+
+?>
index 5526c98..3979f6d 100644 (file)
@@ -926,6 +926,9 @@ this old version, (rev) = revert to this old version.
 'unusedtemplatestext' => 'This page lists all pages in the template namespace which are not included in another page. Remember to check for other links to the templates before deleting them.',
 'unusedtemplateswlh' => 'other links',
 
+# Random redirect
+'randomredirect' => 'Random redirect',
+
 # Statistics
 #
 'statistics'   => 'Statistics',