From 0b6b78d13a97a43e17c287aaafe6ce64abfe9f91 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Wed, 24 Oct 2012 07:32:46 -0700 Subject: [PATCH] It should not be possible for a RequestContext's WikiPage and Title to be different. Looks like someone messed with RequestContext when I wasn't looking at it. WikiPage is a representation of the Title. It should not be possible for wikipage to point to a different title than the context's title. Fix this issue by unsetting WikiPage when setting title and updating title when setting wikipage. Change-Id: I40471b12d08763cb1b47b8382f96d8db94b4f319 --- includes/context/RequestContext.php | 8 ++++++ tests/phpunit/includes/RequestContextTest.php | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/phpunit/includes/RequestContextTest.php diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index cd2bf556f8..e4de030c74 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -93,6 +93,8 @@ class RequestContext implements IContextSource { */ public function setTitle( Title $t ) { $this->title = $t; + // Erase the WikiPage so a new one with the new title gets created. + $this->wikipage = null; } /** @@ -138,6 +140,12 @@ class RequestContext implements IContextSource { * @param $p WikiPage object */ public function setWikiPage( WikiPage $p ) { + $contextTitle = $this->getTitle(); + $pageTitle = $p->getTitle(); + if ( !$contextTitle || !$pageTitle->equals( $contextTitle ) ) { + $this->setTitle( $pageTitle ); + } + // Defer this to the end since setTitle sets it to null. $this->wikipage = $p; } diff --git a/tests/phpunit/includes/RequestContextTest.php b/tests/phpunit/includes/RequestContextTest.php new file mode 100644 index 0000000000..48cf6dc650 --- /dev/null +++ b/tests/phpunit/includes/RequestContextTest.php @@ -0,0 +1,28 @@ +setTitle( $curTitle ); + $this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ), + "When a title is first set WikiPage should be created on-demand for that title." ); + + $curTitle = Title::newFromText( "B" ); + $context->setWikiPage( WikiPage::factory( $curTitle ) ); + $this->assertTrue( $curTitle->equals( $context->getTitle() ), + "Title must be updated when a new WikiPage is provided." ); + + $curTitle = Title::newFromText( "C" ); + $context->setTitle( $curTitle ); + $this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ), + "When a title is updated the WikiPage should be purged and recreated on-demand with the new title." ); + + } + +} -- 2.20.1