AjaxDispatcher: Use Config instead of globals
authorKunal Mehta <legoktm@gmail.com>
Tue, 26 Aug 2014 02:14:41 +0000 (19:14 -0700)
committerKunal Mehta <legoktm@gmail.com>
Tue, 26 Aug 2014 02:20:30 +0000 (19:20 -0700)
Also removed a usage of $wgUser, and converted
AjaxResponse to use Config.

Change-Id: Ia9a1e17da26908b81f7f9691445ff75db2fdefb1

includes/AjaxDispatcher.php
includes/AjaxResponse.php
includes/MediaWiki.php

index dde8467..9bc92be 100644 (file)
@@ -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',
index 41cbd24..8e9f490 100644 (file)
@@ -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 {
index 281080c..da4af2f 100644 (file)
@@ -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;
                }