From a2407ce9c832fb85a3b369d40b185af7a40ff1a2 Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Mon, 14 Jan 2008 12:50:20 +0000 Subject: [PATCH] Cleanup for Special:Randompage and Special: Randomredirect after r29725 - http://bugzilla.wikimedia.org/show_bug.cgi?id=12624 Thanks to: alex.emsenhuber --- includes/AutoLoader.php | 1 + includes/SpecialPage.php | 2 +- includes/SpecialRandompage.php | 43 +++++++++++++----------------- includes/SpecialRandomredirect.php | 27 +++++-------------- 4 files changed, 27 insertions(+), 46 deletions(-) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 83afaebfbf..9bb88fdc5a 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -213,6 +213,7 @@ function __autoload($className) { 'PreferencesForm' => 'includes/SpecialPreferences.php', 'SpecialPrefixindex' => 'includes/SpecialPrefixindex.php', 'RandomPage' => 'includes/SpecialRandompage.php', + 'SpecialRandomredirect' => 'includes/SpecialRandomredirect.php', 'PasswordResetForm' => 'includes/SpecialResetpass.php', 'RevisionDeleteForm' => 'includes/SpecialRevisiondelete.php', 'RevisionDeleter' => 'includes/SpecialRevisiondelete.php', diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index e152c77b05..e68ad73c43 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -141,7 +141,7 @@ class SpecialPage 'Listredirects' => array( 'SpecialPage', 'Listredirects' ), 'Revisiondelete' => array( 'UnlistedSpecialPage', 'Revisiondelete', 'deleterevision' ), 'Unusedtemplates' => array( 'SpecialPage', 'Unusedtemplates' ), - 'Randomredirect' => array( 'SpecialPage', 'Randomredirect' ), + 'Randomredirect' => 'SpecialRandomredirect', 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ), 'Mypage' => array( 'SpecialMypage' ), diff --git a/includes/SpecialRandompage.php b/includes/SpecialRandompage.php index 0e8e47716d..b6cde67d70 100644 --- a/includes/SpecialRandompage.php +++ b/includes/SpecialRandompage.php @@ -15,49 +15,42 @@ */ class RandomPage extends SpecialPage { private $namespace = NS_MAIN; // namespace to select pages from - private $redirect = false; // select redirects instead of normal pages? - public function getNamespace ( ) { - return $this->namespace; - } - - function getTitle($par=null) { - return SpecialPage::getTitleFor("Randompage"); + function __construct( $name = 'Randompage' ){ + parent::__construct( $name ); } - - function getLocalName() { - return SpecialPage::getLocalNameFor("Randompage"); + + public function getNamespace() { + return $this->namespace; } - public function setHeaders() {} - public function outputHeader() {} - public function setNamespace ( $ns ) { if( $ns < NS_MAIN ) $ns = NS_MAIN; $this->namespace = $ns; } - public function getRedirect ( ) { - return $this->redirect; - } - public function setRedirect ( $redirect ) { - $this->redirect = $redirect; + + // select redirects instead of normal pages? + // Overriden by SpecialRandomredirect + public function isRedirect(){ + return false; } - public function execute( $par = null ) { + public function execute( $par ) { global $wgOut, $wgContLang; if ($par) $this->setNamespace( $wgContLang->getNsIndex( $par ) ); - $this->setRedirect( false ); $title = $this->getRandomTitle(); if( is_null( $title ) ) { - $wgOut->addWikiText( wfMsg( 'randompage-nopages' ) ); + $this->setHeaders(); + $wgOut->addWikiText( wfMsg( strtolower( $this->mName ) . '-nopages' ) ); return; } - $wgOut->redirect( $title->getFullUrl() ); + $query = $this->isRedirect() ? 'redirect=no' : ''; + $wgOut->redirect( $title->getFullUrl( $query ) ); } @@ -65,7 +58,7 @@ class RandomPage extends SpecialPage { * Choose a random title. * @return Title object (or null if nothing to choose from) */ - public function getRandomTitle ( ) { + public function getRandomTitle() { $randstr = wfRandom(); $row = $this->selectRandomPageFromDB( $randstr ); @@ -85,7 +78,7 @@ class RandomPage extends SpecialPage { return null; } - private function selectRandomPageFromDB ( $randstr ) { + private function selectRandomPageFromDB( $randstr ) { global $wgExtraRandompageSQL; $fname = 'RandomPage::selectRandomPageFromDB'; @@ -95,7 +88,7 @@ class RandomPage extends SpecialPage { $page = $dbr->tableName( 'page' ); $ns = (int) $this->namespace; - $redirect = $this->redirect ? 1 : 0; + $redirect = $this->isRedirect() ? 1 : 0; $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : ""; $sql = "SELECT page_title diff --git a/includes/SpecialRandomredirect.php b/includes/SpecialRandomredirect.php index b7aa3e490b..ccf5cbcd97 100644 --- a/includes/SpecialRandomredirect.php +++ b/includes/SpecialRandomredirect.php @@ -7,27 +7,14 @@ * @author Rob Church , 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, $wgContLang; - - $rnd = new RandomPage(); - $rnd->setNamespace( $wgContLang->getNsIndex( $par ) ); - $rnd->setRedirect( true ); - - $title = $rnd->getRandomTitle(); - - if( is_null( $title ) ) { - $wgOut->addWikiText( wfMsg( 'randomredirect-nopages' ) ); - return; +class SpecialRandomredirect extends RandomPage { + function __construct(){ + parent::__construct( 'Randomredirect' ); } - $wgOut->reportTime(); - $wgOut->redirect( $title->getFullUrl( 'redirect=no' ) ); + // Override parent::isRedirect() + public function isRedirect(){ + return true; + } } - -- 2.20.1