Merge "Begin exposing SiteConfiguration via site contexts"
[lhc/web/wiklou.git] / includes / context / DerivativeContext.php
index eda56a7..1e3fbf2 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
         *
@@ -99,8 +126,12 @@ class DerivativeContext extends ContextSource {
         * Set the Title object
         *
         * @param Title $t
+        * @throws MWException
         */
-       public function setTitle( Title $t ) {
+       public function setTitle( $t ) {
+               if ( $t !== null && !$t instanceof Title ) {
+                       throw new MWException( __METHOD__ . " expects an instance of Title" );
+               }
                $this->title = $t;
        }
 
@@ -281,4 +312,21 @@ class DerivativeContext extends ContextSource {
                        return $this->getContext()->getSkin();
                }
        }
+
+       /**
+        * Get a message using the current context.
+        *
+        * This can't just inherit from ContextSource, since then
+        * it would set only the original context, and not take
+        * into account any changes.
+        *
+        * @param String Message name
+        * @param Variable number of message arguments
+        * @return Message
+        */
+       public function msg() {
+               $args = func_get_args();
+
+               return call_user_func_array( 'wfMessage', $args )->setContext( $this );
+       }
 }