fix replaceSection for models that don't support sections
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 23 Jul 2012 11:19:22 +0000 (13:19 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 23 Jul 2012 11:19:22 +0000 (13:19 +0200)
Change-Id: Ib60c616f572bf143e3ea63f269f7a0b0701f144c

includes/EditPage.php
includes/WikiPage.php

index 48da565..8225d5a 100644 (file)
@@ -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 );
index ad1fded..23fbce2 100644 (file)
@@ -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();