(bug 43008) Show error to user if content type doesn't support sections.
authordaniel <daniel.kinzler@wikimedia.de>
Thu, 13 Dec 2012 21:16:05 +0000 (22:16 +0100)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 21 Jan 2013 14:37:05 +0000 (14:37 +0000)
When trying to edit a page that does not support sections (like a JS or CSS page)
with section=new or so, show an informative error page instead of dying with
a fatal error.

Change-Id: I3d2901b715c10b52fab4fdc6b5e9ab5d887610bd

includes/EditPage.php

index f3c0237..3538a32 100644 (file)
@@ -577,13 +577,15 @@ class EditPage {
        }
 
        /**
-        * Does this EditPage class support section editing?
-        * This is used by EditPage subclasses to indicate their ui cannot handle section edits
+        * Returns whether section editing is supported for the current page.
+        * Subclasses may override this to replace the default behavior, which is
+        * to check ContentHandler::supportsSections.
         *
-        * @return bool
+        * @return bool true if this edit page supports sections, false otherwise.
         */
        protected function isSectionEditSupported() {
-               return true;
+               $contentHandler = ContentHandler::getForTitle( $this->mTitle );
+               return $contentHandler->supportsSections();
        }
 
        /**
@@ -597,6 +599,11 @@ class EditPage {
 
                # Section edit can come from either the form or a link
                $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
+
+               if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) {
+                       throw new ErrorPageError( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
+               }
+
                $this->isNew = !$this->mTitle->exists() || $this->section == 'new';
 
                if ( $request->wasPosted() ) {