From 52def2f997d8f00561e9d6262844c040d63a35d8 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 4 May 2004 12:37:29 +0000 Subject: [PATCH] Interwiki redirects using prefixes in the URL --- includes/DefaultSettings.php | 1 + includes/Title.php | 36 +++++++++++++++++++++++++----------- index.php | 11 ++++++++++- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 5a83e4cd10..ec7ce9f0a4 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -108,6 +108,7 @@ $wgAmericanDates = false; # Enable for English module to print dates $wgLocalInterwiki = "w"; $wgShowIPinHeader = true; # For non-logged in users $wgMaxNameChars = 32; # Maximum number of bytes in username +$wgInterwikiExpiry = 10800; # Expiry time for cache of interwiki table # Translation using MediaWiki: namespace # This will increase load times by 25-60% unless memcached is installed diff --git a/includes/Title.php b/includes/Title.php index cd55e7420e..b387d172b9 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1,7 +1,7 @@ iw_url; + if( array_key_exists( $k, $wgTitleInterwikiCache ) ) + return $wgTitleInterwikiCache[$k]->iw_url; $s = $wgMemc->get( $k ); - if( $s ) { - $title_interwiki_cache[$k] = $s; + # Ignore old keys with no iw_local + if( $s && isset( $s->iw_local ) ) { + $wgTitleInterwikiCache[$k] = $s; return $s->iw_url; } $dkey = wfStrencode( $key ); - $query = "SELECT iw_url FROM interwiki WHERE iw_prefix='$dkey'"; + $query = "SELECT iw_url,iw_local FROM interwiki WHERE iw_prefix='$dkey'"; $res = wfQuery( $query, DB_READ, "Title::getInterwikiLink" ); if(!$res) return ""; @@ -261,11 +262,24 @@ class Title { $s = (object)false; $s->iw_url = ""; } - $wgMemc->set( $k, $s ); - $title_interwiki_cache[$k] = $s; + $wgMemc->set( $k, $s, $wgInterwikiExpiry ); + $wgTitleInterwikiCache[$k] = $s; return $s->iw_url; } - + + function isLocal() { + global $wgTitleInterwikiCache, $wgDBname; + + if ( $this->mInterwiki != "" ) { + # Make sure key is loaded into cache + $this->getInterwikiLink( $this->mInterwiki ); + $k = "$wgDBname:interwiki:" . $this->mInterwiki; + return (bool)($wgTitleInterwikiCache[$k]->iw_local); + } else { + return true; + } + } + # Update the cur_touched field for an array of title objects # Inefficient unless the IDs are already loaded into the link cache /* static */ function touchArray( $titles, $timestamp = "" ) { diff --git a/index.php b/index.php index 0d54b6b2f4..7f66557c12 100644 --- a/index.php +++ b/index.php @@ -70,9 +70,18 @@ if ( $search = $wgRequest->getText( 'search' ) ) { } else { wfGo( $search ); } -} else if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) { +} else if( !$wgTitle or $wgTitle->getDBkey() == "" ) { $wgTitle = Title::newFromText( wfMsg( "badtitle" ) ); $wgOut->errorpage( "badtitle", "badtitletext" ); +} else if ( $wgTitle->getInterwiki() != "" ) { + $url = $wgTitle->getFullURL(); + # Check for a redirect loop + if ( !preg_match( "/^" . preg_quote( $wgServer ) . "/", $url ) && $wgTitle->isLocal() ) { + $wgOut->redirect( $url ); + } else { + $wgTitle = Title::newFromText( wfMsg( "badtitle" ) ); + $wgOut->errorpage( "badtitle", "badtitletext" ); + } } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) { /* redirect to canonical url, make it a 301 to allow caching */ $wgOut->redirect( $wgTitle->getFullURL(), '301'); -- 2.20.1