(Bug 41178) Fix fatal in EditPage::displayPermissionsError.
authordaniel <daniel.kinzler@wikimedia.de>
Thu, 18 Oct 2012 17:17:03 +0000 (19:17 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Thu, 18 Oct 2012 17:23:40 +0000 (19:23 +0200)
EditPage::displayPermissionsError did not check whether getContentObject
returns false.

While we are at it, making getEditText more robust.

Change-Id: I7d6297530f57949d4a66c663490449cbdb4acad8

includes/EditPage.php

index 4a1e517..bfd42a5 100644 (file)
@@ -471,7 +471,7 @@ class EditPage {
                $content = $this->getContentObject();
 
                # Use the normal message if there's nothing to display
-               if ( $this->firsttime && $content->isEmpty() ) {
+               if ( $this->firsttime && ( $content === false || $content->isEmpty() ) ) {
                        $action = $this->mTitle->exists() ? 'edit' :
                                ( $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage' );
                        throw new PermissionsError( $action, $permErrors );
@@ -1895,20 +1895,30 @@ class EditPage {
        }
 
        /**
-        * Gets an editable textual representation of the given Content object.
+        * Gets an editable textual representation of $content.
         * The textual representation can be turned by into a Content object by the
         * toEditContent() method.
         *
+        * If $content is null or false or a string, $content is returned unchanged.
+        *
         * If the given Content object is not of a type that can be edited using the text base EditPage,
         * an exception will be raised. Set $this->allowNonTextContent to true to allow editing of non-textual
         * content.
         *
-        * @param Content $content
+        * @param Content|null|false|string $content
         * @return String the editable text form of the content.
         *
         * @throws MWException if $content is not an instance of TextContent and $this->allowNonTextContent is not true.
         */
-       protected function toEditText( Content $content ) {
+       protected function toEditText( $content ) {
+               if ( $content === null || $content === false ) {
+                       return $content;
+               }
+
+               if ( is_string( $content ) ) {
+                       return $content;
+               }
+
                if ( !$this->allowNonTextContent && !( $content instanceof TextContent ) ) {
                        throw new MWException( "This content model can not be edited as text: "
                                                                . ContentHandler::getLocalizedName( $content->getModel() ) );