Chad has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/92004


Change subject: Begin exposing SiteConfiguration via site contexts
......................................................................

Begin exposing SiteConfiguration via site contexts

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
---
M includes/context/ContextSource.php
M includes/context/DerivativeContext.php
M includes/context/IContextSource.php
M includes/context/RequestContext.php
4 files changed, 72 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/04/92004/1

diff --git a/includes/context/ContextSource.php 
b/includes/context/ContextSource.php
index e13cfa8..1e90013 100644
--- a/includes/context/ContextSource.php
+++ b/includes/context/ContextSource.php
@@ -58,6 +58,16 @@
        }
 
        /**
+        * Get the SiteConfiguration object
+        *
+        * @since 1.23
+        * @return SiteConfiguration
+        */
+       public function getConfig() {
+               return $this->getContext()->getConfig();
+       }
+
+       /**
         * Get the WebRequest object
         *
         * @since 1.18
diff --git a/includes/context/DerivativeContext.php 
b/includes/context/DerivativeContext.php
index fd9bf96..2b2d9c5 100644
--- a/includes/context/DerivativeContext.php
+++ b/includes/context/DerivativeContext.php
@@ -66,6 +66,11 @@
        private $skin;
 
        /**
+        * @var SiteConfiguration
+        */
+       private $config;
+
+       /**
         * Constructor
         * @param IContextSource $context Context to inherit from
         */
@@ -74,6 +79,28 @@
        }
 
        /**
+        * 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
         *
         * @param WebRequest $r
diff --git a/includes/context/IContextSource.php 
b/includes/context/IContextSource.php
index 35d5aed..6c5c0a2 100644
--- a/includes/context/IContextSource.php
+++ b/includes/context/IContextSource.php
@@ -100,6 +100,14 @@
        public function getSkin();
 
        /**
+        * Get the site configuration
+        *
+        * @since 1.23
+        * @return SiteConfiguration
+        */
+       public function getConfig();
+
+       /**
         * Get a Message object with context set
         *
         * @return Message
diff --git a/includes/context/RequestContext.php 
b/includes/context/RequestContext.php
index 01ec57c..2822c48 100644
--- a/includes/context/RequestContext.php
+++ b/includes/context/RequestContext.php
@@ -64,6 +64,33 @@
        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
         *
         * @param WebRequest $r

-- 
To view, visit https://gerrit.wikimedia.org/r/92004
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I23194d1ba747a9e0d925154ae065cbd612b4f591
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Chad <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to