From: Alex Ezell Date: Tue, 9 Oct 2018 15:51:04 +0000 (-0400) Subject: WikiPage: Fix viewing of wiki redirects to NS_MEDIA X-Git-Tag: 1.34.0-rc.0~3823^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=d4a45f9ea8b9e68893f1742a2ff4db19e3725acd;p=lhc%2Fweb%2Fwiklou.git WikiPage: Fix viewing of wiki redirects to NS_MEDIA If a user creates a redirect to a Media namespace title, a fatal error is thrown on viewing such rediect because we protect against redirecting to virtual namespaces. This fix catches this kind of redirect and modifies the namespace to be File before the Title object is created. Follow-up from 613e2699. Bug: T203942 Change-Id: Ib211d98498f635862fea6bf3e7395f4f8718b3d8 --- diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 7c97465389..34b779eda0 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -987,8 +987,16 @@ class WikiPage implements Page, IDBAccessObject { // rd_fragment and rd_interwiki were added later, populate them if empty if ( $row && !is_null( $row->rd_fragment ) && !is_null( $row->rd_interwiki ) ) { + // (T203942) We can't redirect to Media namespace because it's virtual. + // We don't want to modify Title objects farther down the + // line. So, let's fix this here by changing to File namespace. + if ( $row->rd_namespace == NS_MEDIA ) { + $namespace = NS_FILE; + } else { + $namespace = $row->rd_namespace; + } $this->mRedirectTarget = Title::makeTitle( - $row->rd_namespace, $row->rd_title, + $namespace, $row->rd_title, $row->rd_fragment, $row->rd_interwiki ); return $this->mRedirectTarget; diff --git a/tests/phpunit/includes/page/WikiPageDbTestBase.php b/tests/phpunit/includes/page/WikiPageDbTestBase.php index 67cbf58ff4..c8cb1378ef 100644 --- a/tests/phpunit/includes/page/WikiPageDbTestBase.php +++ b/tests/phpunit/includes/page/WikiPageDbTestBase.php @@ -808,6 +808,14 @@ abstract class WikiPageDbTestBase extends MediaWikiLangTestCase { "#REDIRECT [[hello world]]", "Hello world" ], + // The below added to protect against Media namespace + // redirects which throw a fatal: (T203942) + [ + 'WikiPageTest_testGetRedirectTarget_3', + CONTENT_MODEL_WIKITEXT, + "#REDIRECT [[Media:hello_world]]", + "File:Hello world" + ], ]; }