r13856 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r13855‎ | r13856 | r13857 >
Date:01:01, 25 April 2006
Author:robchurch
Status:old
Tags:
Comment:
(bug 5684) Introduce Special:Randomredirect
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialRandomredirect.php (added) (history)
  • /trunk/phase3/languages/Messages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialPage.php
@@ -80,6 +80,7 @@
8181 'Listredirects' => new SpecialPage( 'Listredirects' ),
8282 'Revisiondelete' => new SpecialPage( 'Revisiondelete', 'deleterevision' ),
8383 'Unusedtemplates' => new SpecialPage( 'Unusedtemplates' ),
 84+ 'Randomredirect' => new SpecialPage( 'Randomredirect' ),
8485 );
8586
8687 if( !$wgDisableCounters ) {
Index: trunk/phase3/includes/SpecialRandomredirect.php
@@ -0,0 +1,54 @@
 2+<?php
 3+
 4+/**
 5+ * Special page to direct the user to a random redirect page (minus the second redirect)
 6+ *
 7+ * @package MediaWiki
 8+ * @subpackage Special pages
 9+ * @author Rob Church <robchur@gmail.com>
 10+ * @licence GNU General Public Licence 2.0 or later
 11+ */
 12+
 13+/**
 14+ * Main execution point
 15+ * @param $par Namespace to select the redirect from
 16+ */
 17+function wfSpecialRandomredirect( $par = NULL ) {
 18+ global $wgOut, $wgExtraRandompageSQL, $wgContLang;
 19+ $fname = 'wfSpecialRandomredirect';
 20+
 21+ # Validate the namespace
 22+ $namespace = $wgContLang->getNsIndex( $par );
 23+ if( $namespace === false || $namespace < NS_MAIN )
 24+ $namespace = NS_MAIN;
 25+
 26+ # Same logic as RandomPage
 27+ $randstr = wfRandom();
 28+
 29+ $dbr =& wfGetDB( DB_SLAVE );
 30+ $use_index = $dbr->useIndexClause( 'page_random' );
 31+ $page = $dbr->tableName( 'page' );
 32+
 33+ $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : '';
 34+ $sql = "SELECT page_id,page_title
 35+ FROM $page $use_index
 36+ WHERE page_namespace = $namespace AND page_is_redirect = 1 $extra
 37+ AND page_random > $randstr
 38+ ORDER BY page_random";
 39+
 40+ $sql = $dbr->limitResult( $sql, 1, 0 );
 41+ $res = $dbr->query( $sql, $fname );
 42+
 43+ $title = NULL;
 44+ if( $row = $dbr->fetchObject( $res ) )
 45+ $title = Title::makeTitleSafe( $namespace, $row->page_title );
 46+
 47+ # Catch dud titles and return to the main page
 48+ if( is_null( $title ) )
 49+ $title = Title::newFromText( wfMsg( 'mainpage' ) );
 50+
 51+ $wgOut->reportTime();
 52+ $wgOut->redirect( $title->getFullUrl( 'redirect=no' ) );
 53+}
 54+
 55+?>
Property changes on: trunk/phase3/includes/SpecialRandomredirect.php
___________________________________________________________________
Added: svn:eol-style
156 + native
Index: trunk/phase3/RELEASE-NOTES
@@ -117,6 +117,7 @@
118118 * Treat "allmessagesnotsupporteddb" as wikitext when echoing; change default text
119119 * (bug 5497) regeression in HTML normalization in 1.6 (unclosed <li>,<dd>,<dt>)
120120 * (bug 5709) Allow customisation of separator for categories
 121+* (bug 5684) Introduce Special:Randomredirect
121122
122123 == Compatibility ==
123124
Index: trunk/phase3/languages/Messages.php
@@ -926,6 +926,9 @@
927927 '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.',
928928 'unusedtemplateswlh' => 'other links',
929929
 930+# Random redirect
 931+'randomredirect' => 'Random redirect',
 932+
930933 # Statistics
931934 #
932935 'statistics' => 'Statistics',

Status & tagging log