'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',
'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' ),
*/
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 ) );
}
* 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 );
return null;
}
- private function selectRandomPageFromDB ( $randstr ) {
+ private function selectRandomPageFromDB( $randstr ) {
global $wgExtraRandompageSQL;
$fname = 'RandomPage::selectRandomPageFromDB';
$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
* @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, $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;
+ }
}
-