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
}
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;
'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',
+ ],
];
}