From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/actions/RawAction.php | 97 ++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 60 deletions(-) (limited to 'includes/actions/RawAction.php') diff --git a/includes/actions/RawAction.php b/includes/actions/RawAction.php index 1a2b3cb1..d0d956ec 100644 --- a/includes/actions/RawAction.php +++ b/includes/actions/RawAction.php @@ -5,7 +5,7 @@ * Copyright © 2004 Gabriel Wicke * http://wikidev.net/ * - * Based on HistoryPage and SpecialExport + * Based on HistoryAction and SpecialExport * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,7 +33,13 @@ * @ingroup Actions */ class RawAction extends FormlessAction { - private $mGen; + /** + * @var bool Does the request include a gen=css|javascript parameter + * @deprecated This used to be a string for "css" or "javascript" but + * it is no longer used. Setting this parameter results in empty content + * being served + */ + private $gen = false; public function getName() { return 'raw'; @@ -48,10 +54,9 @@ class RawAction extends FormlessAction { } function onView() { - global $wgSquidMaxage, $wgForcedRawSMaxage; - $this->getOutput()->disable(); $request = $this->getRequest(); + $config = $this->context->getConfig(); if ( !$request->checkUrlExtension() ) { return; @@ -67,26 +72,25 @@ class RawAction extends FormlessAction { $smaxage = $request->getIntOrNull( 'smaxage' ); if ( $gen == 'css' || $gen == 'js' ) { - $this->mGen = $gen; + $this->gen = true; if ( $smaxage === null ) { - $smaxage = $wgSquidMaxage; + $smaxage = $config->get( 'SquidMaxage' ); } - } else { - $this->mGen = false; } $contentType = $this->getContentType(); - # Force caching for CSS and JS raw content, default: 5 minutes + # Force caching for CSS and JS raw content, default: 5 minutes. + # Note: If using a canonical url for userpage css/js, we send an HTCP purge. if ( $smaxage === null ) { if ( $contentType == 'text/css' || $contentType == 'text/javascript' ) { - $smaxage = intval( $wgForcedRawSMaxage ); + $smaxage = intval( $config->get( 'ForcedRawSMaxage' ) ); } else { $smaxage = 0; } } - $maxage = $request->getInt( 'maxage', $wgSquidMaxage ); + $maxage = $request->getInt( 'maxage', $config->get( 'SquidMaxage' ) ); $response = $request->response(); @@ -99,7 +103,9 @@ class RawAction extends FormlessAction { $privateCache = $privateCache ?: $this->getUser()->isLoggedIn(); # allow the client to cache this for 24 hours $mode = $privateCache ? 'private' : 'public'; - $response->header( 'Cache-Control: ' . $mode . ', s-maxage=' . $smaxage . ', max-age=' . $maxage ); + $response->header( + 'Cache-Control: ' . $mode . ', s-maxage=' . $smaxage . ', max-age=' . $maxage + ); $text = $this->getRawText(); @@ -122,13 +128,13 @@ class RawAction extends FormlessAction { * Get the text that should be returned, or false if the page or revision * was not found. * - * @return String|Bool + * @return string|bool */ public function getRawText() { global $wgParser; # No longer used - if ( $this->mGen ) { + if ( $this->gen ) { return ''; } @@ -138,8 +144,9 @@ class RawAction extends FormlessAction { // If it's a MediaWiki message we can just hit the message cache if ( $request->getBool( 'usemsgcache' ) && $title->getNamespace() == NS_MEDIAWIKI ) { - // The first "true" is to use the database, the second is to use the content langue - // and the last one is to specify the message key already contains the language in it ("/de", etc.) + // The first "true" is to use the database, the second is to use + // the content langue and the last one is to specify the message + // key already contains the language in it ("/de", etc.). $text = MessageCache::singleton()->get( $title->getDBkey(), true, true, true ); // If the message doesn't exist, return a blank if ( $text === false ) { @@ -161,7 +168,7 @@ class RawAction extends FormlessAction { } 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." ); + . $content->getModel() . "` which is not supported via this interface." ); die(); } else { // want a section? @@ -181,7 +188,11 @@ class RawAction extends FormlessAction { } if ( $text !== false && $text !== '' && $request->getVal( 'templates' ) === 'expand' ) { - $text = $wgParser->preprocess( $text, $title, ParserOptions::newFromContext( $this->getContext() ) ); + $text = $wgParser->preprocess( + $text, + $title, + ParserOptions::newFromContext( $this->getContext() ) + ); } return $text; @@ -190,17 +201,18 @@ class RawAction extends FormlessAction { /** * Get the ID of the revision that should used to get the text. * - * @return Integer + * @return int */ public function getOldId() { $oldid = $this->getRequest()->getInt( 'oldid' ); switch ( $this->getRequest()->getText( 'direction' ) ) { case 'next': # output next revision, or nothing if there isn't one + $nextid = 0; if ( $oldid ) { - $oldid = $this->getTitle()->getNextRevisionID( $oldid ); + $nextid = $this->getTitle()->getNextRevisionID( $oldid ); } - $oldid = $oldid ? $oldid : -1; + $oldid = $nextid ?: -1; break; case 'prev': # output previous revision, or nothing if there isn't one @@ -208,20 +220,21 @@ class RawAction extends FormlessAction { # get the current revision so we can get the penultimate one $oldid = $this->page->getLatest(); } - $prev = $this->getTitle()->getPreviousRevisionID( $oldid ); - $oldid = $prev ? $prev : -1; + $previd = $this->getTitle()->getPreviousRevisionID( $oldid ); + $oldid = $previd ?: -1; break; case 'cur': $oldid = 0; break; } + return $oldid; } /** * Get the content type to use for the response * - * @return String + * @return string */ public function getContentType() { $ctype = $this->getRequest()->getVal( 'ctype' ); @@ -243,39 +256,3 @@ class RawAction extends FormlessAction { return $ctype; } } - -/** - * Backward compatibility for extensions - * - * @deprecated in 1.19 - */ -class RawPage extends RawAction { - public $mOldId; - - /** - * @param Page $page - * @param WebRequest|bool $request The WebRequest (default: false). - */ - function __construct( Page $page, $request = false ) { - wfDeprecated( __CLASS__, '1.19' ); - parent::__construct( $page ); - - if ( $request !== false ) { - $context = new DerivativeContext( $this->getContext() ); - $context->setRequest( $request ); - $this->context = $context; - } - } - - public function view() { - $this->onView(); - } - - public function getOldId() { - # Some extensions like to set $mOldId - if ( $this->mOldId !== null ) { - return $this->mOldId; - } - return parent::getOldId(); - } -} -- cgit v1.2.2