preview status in page title
[lhc/web/wiklou.git] / includes / Title.php
index 86a3f7d..77b1a95 100644 (file)
@@ -58,14 +58,14 @@ class Title {
                static $trans;
                $fname = "Title::newFromText";
                wfProfileIn( $fname );
-               
+
                # Note - mixing latin1 named entities and unicode numbered
                # ones will result in a bad link.
                if( !isset( $trans ) ) {
                        global $wgInputEncoding;
                        $trans = array_flip( get_html_translation_table( HTML_ENTITIES ) );
                        if( strcasecmp( "utf-8", $wgInputEncoding ) == 0 ) {
-                           $trans = array_map( "utf8_encode", $trans );
+                               $trans = array_map( "utf8_encode", $trans );
                        }
                }
 
@@ -73,7 +73,7 @@ class Title {
                        wfDebugDieBacktrace( "Called with object instead of string." );
                }
                $text = strtr( $text, $trans );
-               
+
                $text = wfMungeToUtf8( $text );
                
                
@@ -82,9 +82,12 @@ class Title {
 
                $t = new Title();
                $t->mDbkeyform = str_replace( " ", "_", $text );
-        $t->mDefaultNamespace = $defaultNamespace;
-        
+               $t->mDefaultNamespace = $defaultNamespace;
+
                wfProfileOut( $fname );
+               if ( !is_object( $t ) ) {
+                       var_dump( debug_backtrace() );
+               }
                if( $t->secureAndSplit() ) {
                        return $t;
                } else {
@@ -235,7 +238,9 @@ class Title {
        # The URL contains $1, which is replaced by the title
        function getInterwikiLink( $key )
        {       
-               global $wgMemc, $wgDBname, $title_interwiki_cache;
+               global $wgMemc, $wgDBname;
+               static $title_interwiki_cache = array();
+
                $k = "$wgDBname:interwiki:$key";
 
                if( array_key_exists( $k, $title_interwiki_cache ) )
@@ -578,7 +583,7 @@ class Title {
        #
        /* private */ function secureAndSplit()
        {
-               global $wgLang, $wgLocalInterwiki;
+               global $wgLang, $wgLocalInterwiki, $wgCapitalLinks;
                $fname = "Title::secureAndSplit";
                wfProfileIn( $fname );
                
@@ -597,13 +602,8 @@ class Title {
                # Clean up whitespace
                #
                $t = preg_replace( "/[\\s_]+/", "_", $this->mDbkeyform );
-               if ( "_" == @$t{0} ) { 
-                       $t = substr( $t, 1 ); 
-               }
-               $l = strlen( $t );
-               if ( $l && ( "_" == $t{$l-1} ) ) { 
-                       $t = substr( $t, 0, $l-1 ); 
-               }
+               $t = preg_replace( '/^_*(.*?)_*$/', '$1', $t );
+
                if ( "" == $t ) {
                        wfProfileOut( $fname );
                        return false;
@@ -626,7 +626,12 @@ class Title {
                        if ( preg_match( "/^((?:i|x|[a-z]{2,3})(?:-[a-z0-9]+)?|[A-Za-z0-9_\\x80-\\xff]+?)_*:_*(.*)$/", $t, $m ) ) {
                                #$p = strtolower( $m[1] );
                                $p = $m[1];
-                               if ( $ns = $wgLang->getNsIndex( strtolower( $p ) )) {
+                               $lowerNs = strtolower( $p );
+                               if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
+                                       # Canonical namespace
+                                       $t = $m[2];
+                                       $this->mNamespace = $ns;
+                               } elseif ( $ns = $wgLang->getNsIndex( $lowerNs )) {
                                        # Ordinary namespace
                                        $t = $m[2];
                                        $this->mNamespace = $ns;
@@ -672,8 +677,10 @@ class Title {
                }
 
                # Initial capital letter
-               if( $this->mInterwiki == "") $t = $wgLang->ucfirst( $r );
-
+               if( $wgCapitalLinks && $this->mInterwiki == "") {
+                       $t = $wgLang->ucfirst( $r );
+               }
+               
                # Fill fields
                $this->mDbkeyform = $t;
                $this->mUrlform = wfUrlencode( $t );