From 83d88434e6b0c833f8704f5da4621a0ba39fc2ce Mon Sep 17 00:00:00 2001 From: daniel Date: Sat, 9 Jun 2012 13:42:05 +0200 Subject: [PATCH] introduced ContentHandler::supportsSections() --- includes/ContentHandler.php | 19 +++++++++++++++++++ includes/WikiPage.php | 13 ++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index 1495eb196b..2adbee9b2b 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -826,6 +826,17 @@ abstract class ContentHandler { new LinksDeletionUpdate( $title ), ); } + + /** + * Returns true iff this page's content model supports sections. + * + * This default implementation returns false, + * + * @return boolean whether sections are supported. + */ + public function supportsSections() { + return false; + } } /** @@ -970,6 +981,14 @@ class WikitextContentHandler extends TextContentHandler { throw new MWException( "getHtml() not implemented for wikitext. Use getParserOutput()->getText()." ); } + /** + * Returns true because wikitext supports sections. + * + * @return boolean whether sections are supported. + */ + public function supportsSections() { + return false; + } } #XXX: make ScriptContentHandler base class with plugin interface for syntax highlighting? diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 20d61065f4..64cc51a626 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -1408,13 +1408,24 @@ class WikiPage extends Page { $sectionContent = ContentHandler::makeContent( $text, $this->getTitle() ); #XXX: could 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?? - #TODO: add ContentHandler::supportsSections() return ContentHandler::getContentText( $newContent ); #XXX: unclear what will happen for non-wikitext! } + /** + * Returns true iff this page's content model supports sections. + * + * @return boolean whether sections are supported. + * + * @todo: the skin should check this and not offer section functionality if sections are not supported. + */ + public function supportsSections() { + return $this->getContentHandler()->supportsSections(); + } + /** * @param $section null|bool|int or a section number (0, 1, 2, T1, T2...) * @param $content Content: new content of the section -- 2.20.1