From fd966d17436c77b6f06f51f0e01cc5b5266386ee Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 18 Oct 2012 19:51:49 +0200 Subject: [PATCH] Make EditPage robust against null content. This adds some checks to avoid fatal errors due to access to non-objects. Change-Id: Ib0e867a9aed50226fa8c6f3af655cd11e7fb83ed --- includes/EditPage.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 4a1e5170f5..697daf0733 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -940,11 +940,11 @@ class EditPage { * to the original text of the edit. * * This difers from Article::getContent() that when a missing revision is - * encountered the result will be an empty string and not the + * encountered the result will be null and not the * 'missing-revision' message. * * @since 1.19 - * @return string + * @return Content|null */ private function getOriginalContent() { if ( $this->section == 'new' ) { @@ -1074,6 +1074,10 @@ class EditPage { $parserOptions = ParserOptions::newFromUser( $wgUser ); $content = $page->getContent( Revision::RAW ); + if ( !$content ) { + return $handler->makeEmptyContent(); + } + return $content->preloadTransform( $title, $parserOptions ); } @@ -1676,19 +1680,21 @@ class EditPage { // This is the revision the editor started from $baseRevision = $this->getBaseRevision(); - if ( is_null( $baseRevision ) ) { + $baseContent = $baseRevision ? $baseRevision->getContent() : null; + + if ( is_null( $baseContent ) ) { wfProfileOut( __METHOD__ ); return false; } - $baseContent = $baseRevision->getContent(); // The current state, we want to merge updates into it $currentRevision = Revision::loadFromTitle( $db, $this->mTitle ); - if ( is_null( $currentRevision ) ) { + $currentContent = $currentRevision ? $currentRevision->getContent() : null; + + if ( is_null( $currentContent ) ) { wfProfileOut( __METHOD__ ); return false; } - $currentContent = $currentRevision->getContent(); $handler = ContentHandler::getForModelID( $baseContent->getModel() ); -- 2.20.1