From: Alex Ezell Date: Fri, 5 Oct 2018 21:32:00 +0000 (-0400) Subject: Replace Media namespace redirects with File namespace X-Git-Tag: 1.34.0-rc.0~3875 X-Git-Url: http://git.cyclocoop.org/wiki/%22.chemin_image%28?a=commitdiff_plain;h=613e2699;p=lhc%2Fweb%2Fwiklou.git Replace Media namespace redirects with File namespace If a user creates a redirect that goes to a [[Media:example.jpg]] page, then an exception is thrown because NS_MEDIA is a virtual namespace. This change catches this case and changes the namespace to an NS_FILE namespace and the redirect works correctly. This change only happens when we are dealing with a redirect so other uses of the NS_MEDIA namespace shouldn't be affected. Bug: T203942 Change-Id: Ia744059650e16510732a65d51b138b11cbd43eb4 --- diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 4636ba349e..e10a530062 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -369,6 +369,11 @@ class MediaWiki { } throw new HttpError( 500, $message ); } + // Protect against redirects to NS_MEDIA namespace + // when the user probably wants NS_FILE + if ( $title->inNamespace( NS_MEDIA ) ) { + $title->mNamespace = NS_FILE; + } $output->setCdnMaxage( 1200 ); $output->redirect( $targetUrl, '301' ); return true; diff --git a/tests/phpunit/includes/MediaWikiTest.php b/tests/phpunit/includes/MediaWikiTest.php index d79d2cf157..916a6ebafc 100644 --- a/tests/phpunit/includes/MediaWikiTest.php +++ b/tests/phpunit/includes/MediaWikiTest.php @@ -134,6 +134,13 @@ class MediaWikiTest extends MediaWikiTestCase { 'title' => 'Double_slash', 'redirect' => false, ], + [ + // View: Media namespace redirect (T203942) + 'url' => 'http://example.org/w/index.php?title=Media:Foo_Bar', + 'query' => [ 'title' => 'Foo_Bar' ], + 'title' => 'File:Foo_Bar', + 'redirect' => 'http://example.org/wiki/File:Foo_Bar', + ], ]; }