From 7b2065a248eb8cfbd16da8e6b885062c32a02e5c Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 11 Jun 2012 16:32:34 +0200 Subject: [PATCH] some cleanup in WikiPage --- includes/ContentHandler.php | 2 +- includes/WikiPage.php | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index d033afc11c..59c3426a2c 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -840,7 +840,7 @@ abstract class ContentHandler { } /** - * Returns true iff this page's content model supports sections. + * Returns true iff this content model supports sections. * * This default implementation returns false, * diff --git a/includes/WikiPage.php b/includes/WikiPage.php index da1ff2b7f9..5a8f5e6824 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -1406,13 +1406,15 @@ class WikiPage extends Page { public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) { wfDeprecated( __METHOD__, '1.WD' ); - $sectionContent = ContentHandler::makeContent( $text, $this->getTitle() ); #XXX: could make section title, but that's not required. + if ( !$this->supportsSections() ) { + return null; + } + + $sectionContent = ContentHandler::makeContent( $text, $this->getTitle() ); # could even make section title, but that's not required. - #TODO: check ContentHandler::supportsSections(). throw exception?? $newContent = $this->replaceSectionContent( $section, $sectionContent, $sectionTitle, $edittime ); - #TODO: check $newContent == false. throw exception?? - return ContentHandler::getContentText( $newContent ); #XXX: unclear what will happen for non-wikitext! + return ContentHandler::getContentText( $newContent ); } /** @@ -1421,6 +1423,7 @@ class WikiPage extends Page { * @return boolean whether sections are supported. * * @todo: the skin should check this and not offer section functionality if sections are not supported. + * @todo: the EditPage should check this and not offer section functionality if sections are not supported. */ public function supportsSections() { return $this->getContentHandler()->supportsSections(); @@ -1439,6 +1442,11 @@ 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; @@ -3270,7 +3278,6 @@ class PoolWorkArticleView extends PoolCounterWork { } $time = - microtime( true ); - // TODO: page might not have this method? Hard to tell what page is supposed to be here... $this->parserOutput = $content->getParserOutput( $this->page->getTitle(), $this->revid, $this->parserOptions ); $time += microtime( true ); -- 2.20.1