summaryrefslogtreecommitdiff
path: root/includes/SpecialRandomredirect.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2006-10-11 18:12:39 +0000
committerPierre Schmitz <pierre@archlinux.de>2006-10-11 18:12:39 +0000
commit183851b06bd6c52f3cae5375f433da720d410447 (patch)
treea477257decbf3360127f6739c2f9d0ec57a03d39 /includes/SpecialRandomredirect.php
MediaWiki 1.7.1 wiederhergestellt
Diffstat (limited to 'includes/SpecialRandomredirect.php')
-rw-r--r--includes/SpecialRandomredirect.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/includes/SpecialRandomredirect.php b/includes/SpecialRandomredirect.php
new file mode 100644
index 00000000..512553c0
--- /dev/null
+++ b/includes/SpecialRandomredirect.php
@@ -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' ) );
+}
+
+?>