From: jenkins-bot Date: Wed, 9 Nov 2016 01:27:38 +0000 (+0000) Subject: Merge "Revert "MediaWiki.php: Redirect non-standard title urls to canonical"" X-Git-Tag: 1.31.0-rc.0~4917 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=84851a43f3ea8ea146c4d82c55fd01b9fa302347;hp=7874fc4bec845ad92960b07e969c65f3c3fe74f2 Merge "Revert "MediaWiki.php: Redirect non-standard title urls to canonical"" --- diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index f7e57fc94c..eaa1c99539 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -313,8 +313,6 @@ class MediaWiki { * - Normalise empty title: * /wiki/ -> /wiki/Main * /w/index.php?title= -> /wiki/Main - * - Normalise non-standard title urls: - * /w/index.php?title=Foo_Bar -> /wiki/Foo_Bar * - Don't redirect anything with query parameters other than 'title' or 'action=view'. * * @param Title $title @@ -327,6 +325,8 @@ class MediaWiki { if ( $request->getVal( 'action', 'view' ) != 'view' || $request->wasPosted() + || ( $request->getVal( 'title' ) !== null + && $title->getPrefixedDBkey() == $request->getVal( 'title' ) ) || count( $request->getValueNames( [ 'action', 'title' ] ) ) || !Hooks::run( 'TestCanonicalRedirect', [ $request, $title, $output ] ) ) { @@ -341,19 +341,7 @@ class MediaWiki { } // Redirect to canonical url, make it a 301 to allow caching $targetUrl = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT ); - - if ( $targetUrl != $request->getFullRequestURL() ) { - $output->setCdnMaxage( 1200 ); - $output->redirect( $targetUrl, '301' ); - return true; - } - - // If there is no title, or the title is in a non-standard encoding, we demand - // a redirect. If cgi somehow changed the 'title' query to be non-standard while - // the url is standard, the server is misconfigured. - if ( $request->getVal( 'title' ) === null - || $title->getPrefixedDBkey() != $request->getVal( 'title' ) - ) { + if ( $targetUrl == $request->getFullRequestURL() ) { $message = "Redirect loop detected!\n\n" . "This means the wiki got confused about what page was " . "requested; this sometimes happens when moving a wiki " . @@ -375,7 +363,9 @@ class MediaWiki { } throw new HttpError( 500, $message ); } - return false; + $output->setSquidMaxage( 1200 ); + $output->redirect( $targetUrl, '301' ); + return true; } /** diff --git a/tests/phpunit/includes/MediaWikiTest.php b/tests/phpunit/includes/MediaWikiTest.php index df92012e29..a8d1e33950 100644 --- a/tests/phpunit/includes/MediaWikiTest.php +++ b/tests/phpunit/includes/MediaWikiTest.php @@ -34,7 +34,7 @@ class MediaWikiTest extends MediaWikiTestCase { 'url' => 'http://example.org/w/index.php?title=Foo_Bar', 'query' => [ 'title' => 'Foo_Bar' ], 'title' => 'Foo_Bar', - 'redirect' => 'http://example.org/wiki/Foo_Bar', + 'redirect' => false, ], [ // View: Script path with implicit title from page id @@ -76,21 +76,21 @@ class MediaWikiTest extends MediaWikiTestCase { 'url' => 'http://example.org/w/?title=Foo_Bar', 'query' => [ 'title' => 'Foo_Bar' ], 'title' => 'Foo_Bar', - 'redirect' => 'http://example.org/wiki/Foo_Bar', + 'redirect' => false, ], [ // View: Root path with escaped title 'url' => 'http://example.org/?title=Foo_Bar', 'query' => [ 'title' => 'Foo_Bar' ], 'title' => 'Foo_Bar', - 'redirect' => 'http://example.org/wiki/Foo_Bar', + 'redirect' => false, ], [ // View: Canonical with redundant query 'url' => 'http://example.org/wiki/Foo_Bar?action=view', 'query' => [ 'action' => 'view' ], 'title' => 'Foo_Bar', - 'redirect' => 'http://example.org/wiki/Foo_Bar', + 'redirect' => false, ], [ // Edit: Canonical view url with action query @@ -104,7 +104,7 @@ class MediaWikiTest extends MediaWikiTestCase { 'url' => 'http://example.org/w/index.php?title=Foo_Bar&action=view', 'query' => [ 'title' => 'Foo_Bar', 'action' => 'view' ], 'title' => 'Foo_Bar', - 'redirect' => 'http://example.org/wiki/Foo_Bar', + 'redirect' => false, ], [ // Edit: Index with action query