From 6e12c4bf9529bbcc172c2ff4f38d821b93eddb01 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 25 Aug 2014 19:14:41 -0700 Subject: [PATCH] AjaxDispatcher: Use Config instead of globals Also removed a usage of $wgUser, and converted AjaxResponse to use Config. Change-Id: Ia9a1e17da26908b81f7f9691445ff75db2fdefb1 --- includes/AjaxDispatcher.php | 19 +++++++++++++------ includes/AjaxResponse.php | 15 ++++++++++----- includes/MediaWiki.php | 4 ++-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/includes/AjaxDispatcher.php b/includes/AjaxDispatcher.php index dde8467f2f..9bc92be94c 100644 --- a/includes/AjaxDispatcher.php +++ b/includes/AjaxDispatcher.php @@ -47,12 +47,19 @@ class AjaxDispatcher { */ private $args; + /** + * @var Config + */ + private $config; + /** * Load up our object with user supplied data */ - function __construct() { + function __construct( Config $config ) { wfProfileIn( __METHOD__ ); + $this->config = $config; + $this->mode = ""; if ( !empty( $_GET["rs"] ) ) { @@ -95,17 +102,17 @@ class AjaxDispatcher { * BEWARE! Data are passed as they have been supplied by the user, * they should be carefully handled in the function processing the * request. + * + * @param User $user */ - function performAction() { - global $wgAjaxExportList, $wgUser; - + function performAction( User $user ) { if ( empty( $this->mode ) ) { return; } wfProfileIn( __METHOD__ ); - if ( !in_array( $this->func_name, $wgAjaxExportList ) ) { + if ( !in_array( $this->func_name, $this->config->get( 'AjaxExportList' ) ) ) { wfDebug( __METHOD__ . ' Bad Request for unknown function ' . $this->func_name . "\n" ); wfHttpError( @@ -113,7 +120,7 @@ class AjaxDispatcher { 'Bad Request', "unknown function " . $this->func_name ); - } elseif ( !User::isEveryoneAllowed( 'read' ) && !$wgUser->isAllowed( 'read' ) ) { + } elseif ( !User::isEveryoneAllowed( 'read' ) && !$user->isAllowed( 'read' ) ) { wfHttpError( 403, 'Forbidden', diff --git a/includes/AjaxResponse.php b/includes/AjaxResponse.php index 41cbd24ca7..8e9f490fa2 100644 --- a/includes/AjaxResponse.php +++ b/includes/AjaxResponse.php @@ -70,12 +70,19 @@ class AjaxResponse { */ private $mText; + /** + * @var Config + */ + private $mConfig; + /** * @param string|null $text + * @param Config|null $config */ - function __construct( $text = null ) { + function __construct( $text = null, Config $config = null ) { $this->mCacheDuration = null; $this->mVary = null; + $this->mConfig = $config ?: ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); $this->mDisabled = false; $this->mText = ''; @@ -150,8 +157,6 @@ class AjaxResponse { * Construct the header and output it */ function sendHeaders() { - global $wgUseSquid, $wgUseESI; - if ( $this->mResponseCode ) { $n = preg_replace( '/^ *(\d+)/', '\1', $this->mResponseCode ); header( "Status: " . $this->mResponseCode, true, (int)$n ); @@ -170,12 +175,12 @@ class AjaxResponse { # and tell the client to always check with the squid. Otherwise, # tell the client to use a cached copy, without a way to purge it. - if ( $wgUseSquid ) { + if ( $this->mConfig->get( 'UseSquid' ) ) { # Expect explicit purge of the proxy cache, but require end user agents # to revalidate against the proxy on each visit. # Surrogate-Control controls our Squid, Cache-Control downstream caches - if ( $wgUseESI ) { + if ( $this->mConfig->get( 'UseESI' ) ) { header( 'Surrogate-Control: max-age=' . $this->mCacheDuration . ', content="ESI/1.0"' ); header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' ); } else { diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 281080cd00..da4af2fd99 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -521,8 +521,8 @@ class MediaWiki { $this->context->setTitle( $title ); $wgTitle = $title; - $dispatcher = new AjaxDispatcher(); - $dispatcher->performAction(); + $dispatcher = new AjaxDispatcher( $this->config ); + $dispatcher->performAction( $this->context->getUser() ); wfProfileOut( __METHOD__ ); return; } -- 2.20.1