* Added a new associative array ($wgSpecialPageRedirects) that holds
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Wed, 11 May 2005 03:21:25 +0000 (03:21 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Wed, 11 May 2005 03:21:25 +0000 (03:21 +0000)
  Specialpages to redirect from and to as keys and values respectively,
  executePath() now uses it to check if it should redirect the request for a
  specialpage to another location.
  This removes the need for keeping stub redirects around in case we merge or
  rename SpecialPages.

includes/SpecialPage.php

index 00f5142..3c7609b 100644 (file)
@@ -19,7 +19,7 @@
 /**
  *
  */
-global $wgSpecialPages;
+global $wgSpecialPages, $wgSpecialPageRedirects;
 
 /**
  * @access private
@@ -43,7 +43,6 @@ $wgSpecialPages = array(
        'Imagelist'         => new SpecialPage( 'Imagelist' ),
        'Newimages'         => new SpecialPage( 'Newimages' ),
        'Listusers'         => new SpecialPage( 'Listusers' ),
-       'Listadmins'        => new UnlistedSpecialPage( 'Listadmins' ),
        'Statistics'        => new SpecialPage( 'Statistics' ),
        'Randompage'        => new SpecialPage( 'Randompage' ),
        'Lonelypages'       => new SpecialPage( 'Lonelypages' ),
@@ -80,6 +79,17 @@ $wgSpecialPages = array(
        'Groups'                => new SpecialPage( 'Groups' ),
 );
 
+/**
+ * Sometimes the functionality of a specialpage is merged into the
+ * functionality of another or its simply renamed, this allows us to redirect
+ * the request to the proper place.
+ *
+ * @access private
+ */
+$wgSpecialPageRedirects = array(
+       'Listadmins' => 'Listusers'
+);
+
 global $wgUseValidation ;
 if ( $wgUseValidation )
        $wgSpecialPages['Validate'] = new SpecialPage( 'Validate' );
@@ -167,6 +177,21 @@ class SpecialPage
                        return NULL;
                }
        }
+       
+       /**
+        * 
+        * @static
+        * @param string $nam
+        * @return mixed string if the redirect exists, otherwise NULL
+        */
+       function &getRedirect( $name ) {
+               global $wgSpecialPageRedirects;
+               if ( array_key_exists( $name, $wgSpecialPageRedirects ) ) {
+                       return $wgSpecialPageRedirects[$name];
+               } else {
+                       return NULL;
+               }
+       }
 
        /**
         * Return categorised listable special pages
@@ -209,9 +234,15 @@ class SpecialPage
 
                $page =& SpecialPage::getPage( $name );
                if ( is_null( $page ) ) {
-                       $wgOut->setArticleRelated( false );
-                       $wgOut->setRobotpolicy( "noindex,follow" );
-                       $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
+                       $redir =& SpecialPage::getRedirect( $name );
+                       if ( isset( $redir ) ) {
+                               $t = Title::makeTitle( NS_SPECIAL, "Listusers" );
+                               $wgOut->redirect ($t->getFullURL());
+                       } else {
+                               $wgOut->setArticleRelated( false );
+                               $wgOut->setRobotpolicy( "noindex,follow" );
+                               $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
+                       }
                } else {
                        if($par !== NULL) {
                                $wgTitle = Title::makeTitle( NS_SPECIAL, $name );