Interwiki redirects using prefixes in the URL
This commit is contained in:
parent
3fec29827d
commit
52def2f997
3 changed files with 36 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
# See title.doc
|
||||
|
||||
/* private static */ $title_interwiki_cache = array();
|
||||
$wgTitleInterwikiCache = array();
|
||||
|
||||
# Title class
|
||||
#
|
||||
|
|
@ -238,21 +238,22 @@ class Title {
|
|||
# The URL contains $1, which is replaced by the title
|
||||
function getInterwikiLink( $key )
|
||||
{
|
||||
global $wgMemc, $wgDBname;
|
||||
static $title_interwiki_cache = array();
|
||||
global $wgMemc, $wgDBname, $wgInterwikiExpiry;
|
||||
static $wgTitleInterwikiCache = array();
|
||||
|
||||
$k = "$wgDBname:interwiki:$key";
|
||||
|
||||
if( array_key_exists( $k, $title_interwiki_cache ) )
|
||||
return $title_interwiki_cache[$k]->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 = "" ) {
|
||||
|
|
|
|||
11
index.php
11
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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue