[Bug 41128] Handle null content in action=raw.
authordaniel <daniel.kinzler@wikimedia.de>
Thu, 18 Oct 2012 10:58:25 +0000 (12:58 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Thu, 18 Oct 2012 10:58:25 +0000 (12:58 +0200)
In RawAction, there are several cases in which we have null instead
of a Content object. Most importanty, this applied for deleted revisions
and missing sections. Handle these cases gracefully.

Change-Id: Iac8560755718a46dcc4dcf118322a66d1caefdae

includes/actions/RawAction.php

index ec3d60a..71cb397 100644 (file)
@@ -150,18 +150,28 @@ class RawAction extends FormlessAction {
                                // Public-only due to cache headers
                                $content = $rev->getContent();
 
-                               if ( !$content instanceof TextContent ) {
+                               if ( $content === null ) {
+                                       // revision not found (or suppressed)
+                                       $text = false;
+                               } elseif ( !$content instanceof TextContent ) {
+                                       // non-text content
                                        wfHttpError( 415, "Unsupported Media Type", "The requested page uses the content model `"
                                                                                . $content->getModel() . "` which is not supported via this interface." );
                                        die();
+                               } else {
+                                       // want a section?
+                                       $section = $request->getIntOrNull( 'section' );
+                                       if ( $section !== null ) {
+                                               $content = $content->getSection( $section );
+                                       }
+
+                                       if ( $content === null || $content === false ) {
+                                               // section not found (or section not supported, e.g. for JS and CSS)
+                                               $text = false;
+                                       } else {
+                                               $text = $content->getNativeData();
+                                       }
                                }
-
-                               $section = $request->getIntOrNull( 'section' );
-                               if ( $section !== null ) {
-                                       $content = $content->getSection( $section );
-                               }
-
-                               $text = $content->getNativeData();
                        }
                }