introduced ContentHandler::supportsSections()
authordaniel <daniel.kinzler@wikimedia.de>
Sat, 9 Jun 2012 11:42:05 +0000 (13:42 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Sat, 9 Jun 2012 11:42:05 +0000 (13:42 +0200)
includes/ContentHandler.php
includes/WikiPage.php

index 1495eb1..2adbee9 100644 (file)
@@ -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?
index 20d6106..64cc51a 100644 (file)
@@ -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