diff options
Diffstat (limited to 'includes/SpecialRandomredirect.php')
-rw-r--r-- | includes/SpecialRandomredirect.php | 47 |
1 files changed, 13 insertions, 34 deletions
diff --git a/includes/SpecialRandomredirect.php b/includes/SpecialRandomredirect.php index 2cb2498b..75a6b81d 100644 --- a/includes/SpecialRandomredirect.php +++ b/includes/SpecialRandomredirect.php @@ -3,50 +3,29 @@ /** * 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 + * @addtogroup SpecialPage + * @author Rob Church <robchur@gmail.com>, Ilmari Karonen + * @license 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'; +function wfSpecialRandomredirect( $par = null ) { + global $wgOut, $wgContLang; - # Validate the namespace - $namespace = $wgContLang->getNsIndex( $par ); - if( $namespace === false || $namespace < NS_MAIN ) - $namespace = NS_MAIN; + $rnd = new RandomPage(); + $rnd->setNamespace( $wgContLang->getNsIndex( $par ) ); + $rnd->setRedirect( true ); - # Same logic as RandomPage - $randstr = wfRandom(); + $title = $rnd->getRandomTitle(); - $dbr =& wfGetDB( DB_SLAVE ); - $use_index = $dbr->useIndexClause( 'page_random' ); - $page = $dbr->tableName( 'page' ); + if( is_null( $title ) ) { + $wgOut->addWikiText( wfMsg( 'randomredirect-nopages' ) ); + return; + } - $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::newMainPage(); - $wgOut->reportTime(); $wgOut->redirect( $title->getFullUrl( 'redirect=no' ) ); } |