(bug 4974) Don't follow redirected talk page on "new messages" link
[lhc/web/wiklou.git] / includes / Title.php
index 6be2775..d65176e 100644 (file)
@@ -107,7 +107,6 @@ class Title {
        function newFromText( $text, $defaultNamespace = NS_MAIN ) {
                global $wgTitleCache;
                $fname = 'Title::newFromText';
-               wfProfileIn( $fname );
 
                if( is_object( $text ) ) {
                        wfDebugDieBacktrace( 'Title::newFromText given an object' );
@@ -122,7 +121,6 @@ class Title {
                 * In theory these are value objects and won't get changed...
                 */
                if( $defaultNamespace == NS_MAIN && isset( $wgTitleCache[$text] ) ) {
-                       wfProfileOut( $fname );
                        return $wgTitleCache[$text];
                }
 
@@ -146,10 +144,8 @@ class Title {
                                $cachedcount++;
                                $wgTitleCache[$text] =& $t;
                        }
-                       wfProfileOut( $fname );
                        return $t;
                } else {
-                       wfProfileOut( $fname );
                        $ret = NULL;
                        return $ret;
                }
@@ -383,26 +379,21 @@ class Title {
                global $wgInterwikiCache;
                $fname = 'Title::getInterwikiLink';
 
-               wfProfileIn( $fname );
-
                $key = strtolower( $key );
 
                $k = $wgDBname.':interwiki:'.$key;
                if( array_key_exists( $k, $wgTitleInterwikiCache ) ) {
-                       wfProfileOut( $fname );
                        return $wgTitleInterwikiCache[$k]->iw_url;
                }
 
                if ($wgInterwikiCache) {
-                       wfProfileOut( $fname );
-                       return $this->getInterwikiCached( $key );
+                       return Title::getInterwikiCached( $key );
                }
 
                $s = $wgMemc->get( $k );
                # Ignore old keys with no iw_local
                if( $s && isset( $s->iw_local ) && isset($s->iw_trans)) {
                        $wgTitleInterwikiCache[$k] = $s;
-                       wfProfileOut( $fname );
                        return $s->iw_url;
                }
 
@@ -411,7 +402,6 @@ class Title {
                        array( 'iw_url', 'iw_local', 'iw_trans' ),
                        array( 'iw_prefix' => $key ), $fname );
                if( !$res ) {
-                       wfProfileOut( $fname );
                        return '';
                }
 
@@ -426,7 +416,6 @@ class Title {
                $wgMemc->set( $k, $s, $wgInterwikiExpiry );
                $wgTitleInterwikiCache[$k] = $s;
 
-               wfProfileOut( $fname );
                return $s->iw_url;
        }
        
@@ -442,7 +431,8 @@ class Title {
                global $wgDBname, $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
                global $wgTitleInterwikiCache;
                static $db, $site;
-               if (!db)
+
+               if (!$db)
                        $db=dba_open($wgInterwikiCache,'r','cdb');
                /* Resolve site name */
                if ($wgInterwikiScopes>=3 and !$site) {
@@ -457,7 +447,7 @@ class Title {
                }
                if ($value=='' and $wgInterwikiScopes>=2) { 
                        /* try globals */
-                       $value = dba_fetch("__globals:{$key}", $db);
+                       $value = dba_fetch("__global:{$key}", $db);
                }
                if ($value=='undef')
                        $value='';
@@ -468,7 +458,7 @@ class Title {
                if ($value!='') {
                        list($local,$url)=explode(' ',$value,2);
                        $s->iw_url=$url;
-                       $s->iw_local=$local;
+                       $s->iw_local=(int)$local;
                }
                $wgTitleInterwikiCache[$wgDBname.':interwiki:'.$key] = $s;
                return $s->iw_url;
@@ -504,7 +494,7 @@ class Title {
        function isTrans() {
                global $wgTitleInterwikiCache, $wgDBname;
 
-               if ($this->mInterwiki == '' || !$this->isLocal())
+               if ($this->mInterwiki == '')
                        return false;
                # Make sure key is loaded into cache
                $this->getInterwikiLink( $this->mInterwiki );
@@ -762,6 +752,13 @@ class Title {
 
                if ( $this->isExternal() ) {
                        $url = $this->getFullURL();
+                       if ( $query ) {
+                               // This is currently only used for edit section links in the 
+                               // context of interwiki transclusion. In theory we should 
+                               // append the query to the end of any existing query string,
+                               // but interwiki transclusion is already broken in that case.
+                               $url .= "?$query";
+                       }
                } else {
                        $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
                        if ( $query == '' ) {
@@ -869,6 +866,23 @@ class Title {
         */
        function isExternal() { return ( '' != $this->mInterwiki ); }
 
+       /**
+        * Is this page "semi-protected" - the *only* protection is autoconfirm?
+        *
+        * @param string Action to check (default: edit)
+        * @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 );
+                       }
+               }
+               return( true );
+       }
+
        /**
         * Does the title correspond to a protected article?
         * @param string $what the action the page is protected from,
@@ -930,6 +944,13 @@ class Title {
                wfProfileIn( $fname );
 
                global $wgUser;
+
+               $result = true;
+               if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) ) ) {
+                       wfProfileOut( $fname );
+                       return $result;
+               }
+
                if( NS_SPECIAL == $this->mNamespace ) {
                        wfProfileOut( $fname );
                        return false;
@@ -1033,6 +1054,11 @@ class Title {
        function userCanRead() {
                global $wgUser;
 
+               $result = true;
+                       if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, "read", &$result ) ) ) {
+                       return $result;
+               }
+
                if( $wgUser->isAllowed('read') ) {
                        return true;
                } else {
@@ -1284,7 +1310,6 @@ class Title {
        /* private */ function secureAndSplit() {
                global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
                $fname = 'Title::secureAndSplit';
-               wfProfileIn( $fname );
 
                # Initialisation
                static $rxTc = false;
@@ -1302,13 +1327,11 @@ class Title {
                $t = trim( $t, '_' );
 
                if ( '' == $t ) {
-                       wfProfileOut( $fname );
                        return false;
                }
 
                if( false !== strpos( $t, UTF8_REPLACEMENT ) ) {
                        # Contained illegal UTF-8 sequences or forbidden Unicode chars.
-                       wfProfileOut( $fname );
                        return false;
                }
 
@@ -1339,7 +1362,6 @@ class Title {
                                        if( !$firstPass ) {
                                                # Can't make a local interwiki link to an interwiki link.
                                                # That's just crazy!
-                                               wfProfileOut( $fname );
                                                return false;
                                        }
 
@@ -1351,7 +1373,6 @@ class Title {
                                        if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
                                                if( $t == '' ) {
                                                        # Can't have an empty self-link
-                                                       wfProfileOut( $fname );
                                                        return false;
                                                }
                                                $this->mInterwiki = '';
@@ -1359,6 +1380,13 @@ class Title {
                                                # Do another namespace split...
                                                continue;
                                        }
+
+                                       # If there's an initial colon after the interwiki, that also 
+                                       # resets the default namespace
+                                       if ( $t !== '' && $t[0] == ':' ) {
+                                               $this->mNamespace = NS_MAIN;
+                                               $t = substr( $t, 1 );
+                                       }
                                }
                                # If there's no recognized interwiki or namespace,
                                # then let the colon expression be part of the title.
@@ -1384,7 +1412,6 @@ class Title {
                # Reject illegal characters.
                #
                if( preg_match( $rxTc, $r ) ) {
-                       wfProfileOut( $fname );
                        return false;
                }
 
@@ -1400,14 +1427,12 @@ class Title {
                       strpos( $r, '/./' ) !== false ||
                       strpos( $r, '/../' ) !== false ) )
                {
-                       wfProfileOut( $fname );
                        return false;
                }
 
                # We shouldn't need to query the DB for the size.
                #$maxSize = $dbr->textFieldSize( 'page', 'page_title' );
                if ( strlen( $r ) > 255 ) {
-                       wfProfileOut( $fname );
                        return false;
                }
 
@@ -1433,7 +1458,6 @@ class Title {
                if( $t == '' &&
                        $this->mInterwiki == '' &&
                        $this->mNamespace != NS_MAIN ) {
-                       wfProfileOut( $fname );
                        return false;
                }
 
@@ -1443,7 +1467,6 @@ class Title {
 
                $this->mTextform = str_replace( '_', ' ', $t );
 
-               wfProfileOut( $fname );
                return true;
        }
 
@@ -2065,9 +2088,10 @@ class Title {
         * @return bool
         */
        function equals( $title ) {
-               return $this->getInterwiki() == $title->getInterwiki()
+               // Note: === is necessary for proper matching of number-like titles.
+               return $this->getInterwiki() === $title->getInterwiki()
                        && $this->getNamespace() == $title->getNamespace()
-                       && $this->getDbkey() == $title->getDbkey();
+                       && $this->getDbkey() === $title->getDbkey();
        }
 
        /**