Cleanup for Special:Randompage and Special: Randomredirect after r29725 - http:/...
authorDomas Mituzas <midom@users.mediawiki.org>
Mon, 14 Jan 2008 12:50:20 +0000 (12:50 +0000)
committerDomas Mituzas <midom@users.mediawiki.org>
Mon, 14 Jan 2008 12:50:20 +0000 (12:50 +0000)
Thanks to: alex.emsenhuber

includes/AutoLoader.php
includes/SpecialPage.php
includes/SpecialRandompage.php
includes/SpecialRandomredirect.php

index 83afaeb..9bb88fd 100644 (file)
@@ -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',
index e152c77..e68ad73 100644 (file)
@@ -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' ),
index 0e8e477..b6cde67 100644 (file)
  */
 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
index b7aa3e4..ccf5cbc 100644 (file)
@@ -7,27 +7,14 @@
  * @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;
+       }
 }
 
-