From d098dc8cdcc390ea80c742c0dc36bdad1e631da9 Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 23 Jul 2012 13:19:22 +0200 Subject: [PATCH] fix replaceSection for models that don't support sections Change-Id: Ib60c616f572bf143e3ea63f269f7a0b0701f144c --- includes/EditPage.php | 4 ++-- includes/WikiPage.php | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 48da565e1d..8225d5a6a7 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2531,8 +2531,8 @@ HTML $this->content_model, $this->content_format ); #XXX: handle parse errors ? $newContent = $this->mArticle->replaceSectionContent( - $this->section, $textboxContent, - $this->summary, $this->edittime ); + $this->section, $textboxContent, + $this->summary, $this->edittime ); # hanlde legacy text-based hook $newtext_orig = $newContent->serialize( $this->content_format ); diff --git a/includes/WikiPage.php b/includes/WikiPage.php index ad1fded5a6..23fbce2fbb 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -1423,8 +1423,13 @@ class WikiPage extends Page { public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) { wfDeprecated( __METHOD__, '1.WD' ); + if ( strval( $section ) == '' ) { //NOTE: keep condition in sync with condition in replaceSectionContent! + // Whole-page edit; let the whole text through + return $text; + } + if ( !$this->supportsSections() ) { - return null; + throw new MWException( "sections not supported for content model " . $this->getContentHandler()->getModelID() ); } $sectionContent = ContentHandler::makeContent( $text, $this->getTitle() ); # could even make section title, but that's not required. @@ -1459,15 +1464,14 @@ class WikiPage extends Page { public function replaceSectionContent( $section, Content $sectionContent, $sectionTitle = '', $edittime = null ) { wfProfileIn( __METHOD__ ); - if ( !$this->supportsSections() ) { - #XXX: log this? - return null; - } - if ( strval( $section ) == '' ) { // Whole-page edit; let the whole text through $newContent = $sectionContent; } else { + if ( !$this->supportsSections() ) { + throw new MWException( "sections not supported for content model " . $this->getContentHandler()->getModelID() ); + } + // Bug 30711: always use current version when adding a new section if ( is_null( $edittime ) || $section == 'new' ) { $oldContent = $this->getContent(); -- 2.20.1