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 );
}
}
wfDebugDieBacktrace( "Called with object instead of string." );
}
$text = strtr( $text, $trans );
-
+
$text = wfMungeToUtf8( $text );
$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 {
# 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 ) )
#
/* private */ function secureAndSplit()
{
- global $wgLang, $wgLocalInterwiki;
+ global $wgLang, $wgLocalInterwiki, $wgCapitalLinks;
$fname = "Title::secureAndSplit";
wfProfileIn( $fname );
# 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;
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;
}
# 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 );