diff --git a/includes/specialpage/SpecialPageFactory.php b/includes/specialpage/SpecialPageFactory.php index 013ceb24e5a..b91273a6946 100644 --- a/includes/specialpage/SpecialPageFactory.php +++ b/includes/specialpage/SpecialPageFactory.php @@ -606,6 +606,9 @@ class SpecialPageFactory { 'user' => $main->getUser(), 'language' => $main->getLanguage(), ]; + if ( $main->canUseWikiPage() ) { + $ctx['wikipage'] = $main->getWikiPage(); + } // Override $wgTitle = $title; @@ -633,6 +636,9 @@ class SpecialPageFactory { $main->setRequest( $ctx['request'] ); $main->setUser( $ctx['user'] ); $main->setLanguage( $ctx['language'] ); + if ( isset( $ctx['wikipage'] ) ) { + $main->setWikiPage( $ctx['wikipage'] ); + } return $ret; } diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php index 7ce4d1efc6a..fc317b71980 100644 --- a/tests/phpunit/includes/ExtraParserTest.php +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -46,6 +46,25 @@ class ExtraParserTest extends MediaWikiTestCase { $this->parser->parse( $longLine, $title, $options )->getText( [ 'unwrap' => true ] ) ); } + /** + * @covers Parser::braceSubstitution + * @covers SpecialPageFactory::capturePath + */ + public function testSpecialPageTransclusionRestoresGlobalState() { + $text = "{{Special:ApiHelp/help}}"; + $title = Title::newFromText( 'testSpecialPageTransclusionRestoresGlobalState' ); + $options = ParserOptions::newFromUser( new User() ); + + RequestContext::getMain()->setTitle( $title ); + RequestContext::getMain()->getWikiPage()->CustomTestProp = true; + + $parsed = $this->parser->parse( $text, $title, $options )->getText(); + $this->assertContains( 'apihelp-header', $parsed ); + + // Verify that this property wasn't wiped out by the parse + $this->assertTrue( RequestContext::getMain()->getWikiPage()->CustomTestProp ); + } + /** * Test the parser entry points * @covers Parser::parse