From: Chad Horohoe Date: Fri, 25 Oct 2013 21:17:24 +0000 (-0700) Subject: Begin exposing SiteConfiguration via site contexts X-Git-Tag: 1.31.0-rc.0~17701^2 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=101a2a160b05c1433bcc7ffb54a06420fb1cd14c;hp=1aeec323e8571d66072b50d95225ba8314300bf4;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/context/ContextSource.php b/includes/context/ContextSource.php index e13cfa88ce..1e90013a03 100644 --- a/includes/context/ContextSource.php +++ b/includes/context/ContextSource.php @@ -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 * diff --git a/includes/context/DerivativeContext.php b/includes/context/DerivativeContext.php index fd9bf96338..2b2d9c5690 100644 --- a/includes/context/DerivativeContext.php +++ b/includes/context/DerivativeContext.php @@ -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 * diff --git a/includes/context/IContextSource.php b/includes/context/IContextSource.php index 35d5aed6b5..6c5c0a23af 100644 --- a/includes/context/IContextSource.php +++ b/includes/context/IContextSource.php @@ -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 * diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 01ec57c086..2822c48d94 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -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 *