convert "::1" and other pseudo-IPv6 addresses that Apache may throw at us to their...
[lhc/web/wiklou.git] / includes / Title.php
index 03489b5..76cf0eb 100644 (file)
@@ -162,7 +162,7 @@ class Title {
         * @static
         * @access public
         */
-       function newFromURL( $url ) {
+       public static function newFromURL( $url ) {
                global $wgLegalTitleChars;
                $t = new Title();
 
@@ -299,7 +299,7 @@ class Title {
 
                                $rt = Title::newFromText( $m[1] );
                                # Disallow redirects to Special:Userlogout
-                               if ( !is_null($rt) && $rt->getNamespace() == NS_SPECIAL && preg_match( '/^Userlogout/i', $rt->getText() ) ) {
+                               if ( !is_null($rt) && $rt->isSpecial( 'Userlogout' ) ) {
                                        $rt = NULL;
                                }
                        }
@@ -984,7 +984,7 @@ class Title {
         */
        function isProtected( $action = '' ) {
                global $wgRestrictionLevels;
-               if ( -1 == $this->mNamespace ) { return true; }
+               if ( NS_SPECIAL == $this->mNamespace ) { return true; }
                                
                if( $action == 'edit' || $action == '' ) {
                        $r = $this->getRestrictions( 'edit' );
@@ -1016,7 +1016,7 @@ class Title {
                global $wgUser;
 
                if ( is_null( $this->mWatched ) ) {
-                       if ( -1 == $this->mNamespace || 0 == $wgUser->getID()) {
+                       if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn()) {
                                $this->mWatched = false;
                        } else {
                                $this->mWatched = $wgUser->isWatched( $this );
@@ -1160,11 +1160,11 @@ class Title {
                } else {
                        global $wgWhitelistRead;
 
-                       /** If anon users can create an account,
-                           they need to reach the login page first! */
-                       if( $wgUser->isAllowed( 'createaccount' )
-                           && $this->getNamespace() == NS_SPECIAL
-                           && $this->getText() == 'Userlogin' ) {
+                       /** 
+                        * Always grant access to the login page.
+                        * Even anons need to be able to log in.
+                       */
+                       if( $this->isSpecial( 'Userlogin' ) ) {
                                return true;
                        }
 
@@ -1517,7 +1517,7 @@ class Title {
 
                # We already know that some pages won't be in the database!
                #
-               if ( '' != $this->mInterwiki || -1 == $this->mNamespace ) {
+               if ( '' != $this->mInterwiki || NS_SPECIAL == $this->mNamespace ) {
                        $this->mArticleID = 0;
                }
                $f = strstr( $r, '#' );
@@ -2364,5 +2364,37 @@ class Title {
                                return 'nstab-' . $wgContLang->lc( $this->getSubjectNsText() );
                }
        }
+
+       /**
+        * Returns true if this title resolves to the named special page
+        * @param string $name The special page name
+        * @access public
+        */
+       function isSpecial( $name ) {
+               if ( $this->getNamespace() == NS_SPECIAL ) {
+                       list( $thisName, $subpage ) = SpecialPage::resolveAliasWithSubpage( $this->getDBkey() );
+                       if ( $name == $thisName ) {
+                               return true;
+                       }
+               }
+               return false;
+       }
+
+       /**
+        * If the Title refers to a special page alias which is not the local default, 
+        * returns a new Title which points to the local default. Otherwise, returns $this.
+        */
+       function fixSpecialName() {
+               if ( $this->getNamespace() == NS_SPECIAL ) {
+                       $canonicalName = SpecialPage::resolveAlias( $this->mDbkeyform );
+                       if ( $canonicalName ) {
+                               $localName = SpecialPage::getLocalNameFor( $canonicalName );
+                               if ( $localName != $this->mDbkeyform ) {
+                                       return Title::makeTitle( NS_SPECIAL, $localName );
+                               }
+                       }
+               }
+               return $this;
+       }
 }
 ?>