summaryrefslogtreecommitdiff
path: root/includes/actions/RawAction.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/actions/RawAction.php')
-rw-r--r--includes/actions/RawAction.php35
1 files changed, 28 insertions, 7 deletions
diff --git a/includes/actions/RawAction.php b/includes/actions/RawAction.php
index 174ca3f8..d1d457c0 100644
--- a/includes/actions/RawAction.php
+++ b/includes/actions/RawAction.php
@@ -29,6 +29,8 @@
/**
* A simple method to retrieve the plain source of an article,
* using "action=raw" in the GET request string.
+ *
+ * @ingroup Actions
*/
class RawAction extends FormlessAction {
private $mGen;
@@ -46,7 +48,7 @@ class RawAction extends FormlessAction {
}
function onView() {
- global $wgGroupPermissions, $wgSquidMaxage, $wgForcedRawSMaxage, $wgJsMimeType;
+ global $wgSquidMaxage, $wgForcedRawSMaxage, $wgJsMimeType;
$this->getOutput()->disable();
$request = $this->getRequest();
@@ -91,7 +93,7 @@ class RawAction extends FormlessAction {
$response->header( 'Content-type: ' . $contentType . '; charset=UTF-8' );
# Output may contain user-specific data;
# vary generated content for open sessions on private wikis
- $privateCache = !$wgGroupPermissions['*']['read'] && ( $smaxage == 0 || session_id() != '' );
+ $privateCache = !User::groupHasPermission( '*', 'read' ) && ( $smaxage == 0 || session_id() != '' );
# allow the client to cache this for 24 hours
$mode = $privateCache ? 'private' : 'public';
$response->header( 'Cache-Control: ' . $mode . ', s-maxage=' . $smaxage . ', max-age=' . $maxage );
@@ -148,10 +150,29 @@ class RawAction extends FormlessAction {
$request->response()->header( "Last-modified: $lastmod" );
// Public-only due to cache headers
- $text = $rev->getText();
- $section = $request->getIntOrNull( 'section' );
- if ( $section !== null ) {
- $text = $wgParser->getSection( $text, $section );
+ $content = $rev->getContent();
+
+ 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();
+ }
}
}
}
@@ -185,7 +206,7 @@ class RawAction extends FormlessAction {
$oldid = $this->page->getLatest();
}
$prev = $this->getTitle()->getPreviousRevisionId( $oldid );
- $oldid = $prev ? $prev : -1 ;
+ $oldid = $prev ? $prev : -1;
break;
case 'cur':
$oldid = 0;