Mark interwiki redirect URLs with a source parameter to stop them from further redire...
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 15 Mar 2005 03:32:30 +0000 (03:32 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 15 Mar 2005 03:32:30 +0000 (03:32 +0000)
includes/Article.php
includes/DefaultSettings.php
includes/Title.php
index.php

index 8de243b..0c14bd8 100644 (file)
@@ -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
index c36ef05..f14fe7e 100644 (file)
@@ -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
 
index 95ee017..fe03907 100644 (file)
@@ -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;
                        }
index ec62796..0c77aec 100644 (file)
--- 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 );