Fix NS_PROJECT_TALK (bug #7792)
[lhc/web/wiklou.git] / includes / Title.php
index a6145e8..a8abb6f 100644 (file)
@@ -615,7 +615,19 @@ class Title {
         * @access public
         */
        function getNsText() {
-               global $wgContLang;
+               global $wgContLang, $wgCanonicalNamespaceNames;
+
+               if ( '' != $this->mInterwiki ) {
+                       // This probably shouldn't even happen. ohh man, oh yuck.
+                       // But for interwiki transclusion it sometimes does.
+                       // Shit. Shit shit shit.
+                       //
+                       // Use the canonical namespaces if possible to try to
+                       // resolve a foreign namespace.
+                       if( isset( $wgCanonicalNamespaceNames[$this->mNamespace] ) ) {
+                               return $wgCanonicalNamespaceNames[$this->mNamespace];
+                       }
+               }
                return $wgContLang->getNsText( $this->mNamespace );
        }
        /**
@@ -812,9 +824,10 @@ class Title {
                } else {
                        $baseUrl = $this->getInterwikiLink( $this->mInterwiki );
 
-                       $namespace = $wgContLang->getNsText( $this->mNamespace );
+                       $namespace = wfUrlencode( $this->getNsText() );
                        if ( '' != $namespace ) {
                                # Can this actually happen? Interwikis shouldn't be parsed.
+                               # Yes! It can in interwiki transclusion. But... it probably shouldn't.
                                $namespace .= ':';
                        }
                        $url = str_replace( '$1', $namespace . $this->mUrlform, $baseUrl );
@@ -989,14 +1002,22 @@ class Title {
         * @return bool
         */
        function isSemiProtected( $action = 'edit' ) {
-               $restrictions = $this->getRestrictions( $action );
-               # We do a full compare because this could be an array
-               foreach( $restrictions as $restriction ) {
-                       if( strtolower( $restriction ) != 'autoconfirmed' ) {
-                               return( false );
+               if( $this->exists() ) {
+                       $restrictions = $this->getRestrictions( $action );
+                       if( count( $restrictions ) > 0 ) {
+                               foreach( $restrictions as $restriction ) {
+                                       if( strtolower( $restriction ) != 'autoconfirmed' )
+                                               return false;
+                               }
+                       } else {
+                               # Not protected
+                               return false;
                        }
+                       return true;
+               } else {
+                       # If it doesn't exist, it can't be protected
+                       return false;
                }
-               return( true );
        }
 
        /**
@@ -1294,6 +1315,15 @@ class Title {
         * @access public
         */
        function loadRestrictions( $res ) {
+               $this->mRestrictions['edit'] = array();
+               $this->mRestrictions['move'] = array();
+               
+               if( !$res ) {
+                       # No restrictions (page_restrictions blank)
+                       $this->mRestrictionsLoaded = true;
+                       return;
+               }
+       
                foreach( explode( ':', trim( $res ) ) as $restrict ) {
                        $temp = explode( '=', trim( $restrict ) );
                        if(count($temp) == 1) {
@@ -1309,23 +1339,24 @@ class Title {
 
        /**
         * Accessor/initialisation for mRestrictions
+        *
+        * @access public
         * @param string $action action that permission needs to be checked for
         * @return array the array of groups allowed to edit this article
-        * @access public
         */
-       function getRestrictions($action) {
-               $id = $this->getArticleID();
-               if ( 0 == $id ) { return array(); }
-
-               if ( ! $this->mRestrictionsLoaded ) {
-                       $dbr =& wfGetDB( DB_SLAVE );
-                       $res = $dbr->selectField( 'page', 'page_restrictions', 'page_id='.$id );
-                       $this->loadRestrictions( $res );
-               }
-               if( isset( $this->mRestrictions[$action] ) ) {
-                       return $this->mRestrictions[$action];
+       function getRestrictions( $action ) {
+               if( $this->exists() ) {
+                       if( !$this->mRestrictionsLoaded ) {
+                               $dbr =& wfGetDB( DB_SLAVE );
+                               $res = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ) );
+                               $this->loadRestrictions( $res );
+                       }
+                       return isset( $this->mRestrictions[$action] )
+                                       ? $this->mRestrictions[$action]
+                                       : array();
+               } else {
+                       return array();
                }
-               return array();
        }
 
        /**
@@ -1442,14 +1473,12 @@ class Title {
         * @private
         */
        /* private */ function prefix( $name ) {
-               global $wgContLang;
-
                $p = '';
                if ( '' != $this->mInterwiki ) {
                        $p = $this->mInterwiki . ':';
                }
                if ( 0 != $this->mNamespace ) {
-                       $p .= $wgContLang->getNsText( $this->mNamespace ) . ':';
+                       $p .= $this->getNsText() . ':';
                }
                return $p . $name;
        }