From a4adffd49f5b8edc0f16fb9f52471f0732ba8a3e Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 15 Mar 2005 03:32:30 +0000 Subject: [PATCH] Mark interwiki redirect URLs with a source parameter to stop them from further redirecting, and if on a whitelist display the return URL for handy edit-linking. --- includes/Article.php | 17 +++++++++++------ includes/DefaultSettings.php | 15 +++++++++++++++ includes/Title.php | 8 ++++++++ index.php | 6 +++++- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 8de243bff4..0c14bd8e30 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -256,7 +256,8 @@ class Article { $t = $this->mTitle->getPrefixedText(); - $noredir = $noredir || ($wgRequest->getVal( 'redirect' ) == 'no'); + $noredir = $noredir || ($wgRequest->getVal( 'redirect' ) == 'no') + || $wgRequest->getCheck( 'rdfrom' ); $this->mOldId = $oldid; $this->fetchContent( $oldid, $noredir, true ); } @@ -350,7 +351,8 @@ class Article { if( $globalTitle ) { global $wgOut; if ( $rt->getInterwiki() != '' && $rt->isLocal() ) { - $wgOut->redirect( $rt->getFullURL() ) ; + $source = $this->mTitle->getFullURL( 'redirect=no' ); + $wgOut->redirect( $rt->getFullURL( 'rdfrom=' . urlencode( $source ) ) ) ; return false; } if ( $rt->getNamespace() == NS_SPECIAL ) { @@ -670,10 +672,13 @@ class Article { # Can't cache redirects $pcache = false; } elseif ( !empty( $rdfrom ) ) { - $sk = $wgUser->getSkin(); - $redir = $sk->makeExternalLink( $rdfrom, $rdfrom ); - $s = wfMsg( 'redirectedfrom', $redir ); - $wgOut->setSubtitle( $s ); + global $wgRedirectSources; + if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) { + $sk = $wgUser->getSkin(); + $redir = $sk->makeExternalLink( $rdfrom, $rdfrom ); + $s = wfMsg( 'redirectedfrom', $redir ); + $wgOut->setSubtitle( $s ); + } } # wrap user css and user js in pre and don't parse diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index c36ef056f6..f14fe7e57d 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -402,6 +402,21 @@ $wgZhdaemonPort=2004; $wgLocalInterwiki = 'w'; $wgInterwikiExpiry = 10800; # Expiry time for cache of interwiki table +/** + * If local interwikis are set up which allow redirects, + * set this regexp to restrict URLs which will be displayed + * as 'redirected from' links. + * + * It might look something like this: + * $wgRedirectSources = '!^https?://[a-z-]+\.wikipedia\.org/!'; + * + * Leave at false to avoid displaying any incoming redirect markers. + * This does not affect intra-wiki redirects, which don't change + * the URL. + */ +$wgRedirectSources = false; + + $wgShowIPinHeader = true; # For non-logged in users $wgMaxNameChars = 32; # Maximum number of bytes in username diff --git a/includes/Title.php b/includes/Title.php index 95ee0176c4..fe03907537 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -629,6 +629,14 @@ class Title { $namepace .= ':'; } $url = str_replace( '$1', $namespace . $this->mUrlform, $baseUrl ); + if( $query != '' ) { + if( false === strpos( $url, '?' ) ) { + $url .= '?'; + } else { + $url .= '&'; + } + $url .= $query; + } if ( '' != $this->mFragment ) { $url .= '#' . $this->mFragment; } diff --git a/index.php b/index.php index ec627961cb..0c77aec93e 100644 --- a/index.php +++ b/index.php @@ -76,7 +76,11 @@ if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) { $interwiki = Title::newFromUrl( $_REQUEST['title'] ); if( !is_null( $interwiki ) ) $wgTitle = $interwiki; } - $url = $wgTitle->getFullURL(); + if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) { + $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) ); + } else { + $url = $wgTitle->getFullURL(); + } # Check for a redirect loop if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) { $wgOut->redirect( $url ); -- 2.20.1