Begin exposing SiteConfiguration via site contexts
authorChad Horohoe <chadh@wikimedia.org>
Fri, 25 Oct 2013 21:17:24 +0000 (14:17 -0700)
committerChad Horohoe <chadh@wikimedia.org>
Fri, 25 Oct 2013 21:19:04 +0000 (14:19 -0700)
First step of providing configuration without relying on globals.

You can use this in your code now as follows:
 $myvar = $context->getConfig()->get( 'wgMyVar' )

Change-Id: I23194d1ba747a9e0d925154ae065cbd612b4f591

includes/context/ContextSource.php
includes/context/DerivativeContext.php
includes/context/IContextSource.php
includes/context/RequestContext.php

index e13cfa8..1e90013 100644 (file)
@@ -57,6 +57,16 @@ abstract class ContextSource implements IContextSource {
                $this->context = $context;
        }
 
+       /**
+        * Get the SiteConfiguration object
+        *
+        * @since 1.23
+        * @return SiteConfiguration
+        */
+       public function getConfig() {
+               return $this->getContext()->getConfig();
+       }
+
        /**
         * Get the WebRequest object
         *
index fd9bf96..2b2d9c5 100644 (file)
@@ -65,6 +65,11 @@ class DerivativeContext extends ContextSource {
         */
        private $skin;
 
+       /**
+        * @var SiteConfiguration
+        */
+       private $config;
+
        /**
         * Constructor
         * @param IContextSource $context Context to inherit from
@@ -73,6 +78,28 @@ class DerivativeContext extends ContextSource {
                $this->setContext( $context );
        }
 
+       /**
+        * Set the SiteConfiguration object
+        *
+        * @param SiteConfiguration $c
+        */
+       public function setConfig( SiteConfiguration $s ) {
+               $this->config = $s;
+       }
+
+       /**
+        * Get the SiteConfiguration object
+        *
+        * @return SiteConfiguration
+        */
+       public function getConfig() {
+               if ( !is_null( $this->config ) ) {
+                       return $this->config;
+               } else {
+                       return $this->getContext()->getConfig();
+               }
+       }
+
        /**
         * Set the WebRequest object
         *
index 35d5aed..6c5c0a2 100644 (file)
@@ -99,6 +99,14 @@ interface IContextSource {
         */
        public function getSkin();
 
+       /**
+        * Get the site configuration
+        *
+        * @since 1.23
+        * @return SiteConfiguration
+        */
+       public function getConfig();
+
        /**
         * Get a Message object with context set
         *
index 01ec57c..2822c48 100644 (file)
@@ -63,6 +63,33 @@ class RequestContext implements IContextSource {
         */
        private $skin;
 
+       /**
+        * @var SiteConfiguration
+        */
+       private $config;
+
+       /**
+        * Set the SiteConfiguration object
+        *
+        * @param SiteConfiguration $c
+        */
+       public function setConfig( SiteConfiguration $c ) {
+               $this->config = $c;
+       }
+
+       /**
+        * Get the SiteConfiguration object
+        *
+        * @return SiteConfiguration
+        */
+       public function getConfig() {
+               if ( $this->config === null ) {
+                       global $wgConf;
+                       $this->config = $wgConf;
+               }
+               return $this->config;
+       }
+
        /**
         * Set the WebRequest object
         *