Merge "Begin exposing SiteConfiguration via site contexts"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 9 Dec 2013 12:28:51 +0000 (12:28 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 9 Dec 2013 12:28:51 +0000 (12:28 +0000)
1  2 
includes/context/ContextSource.php
includes/context/DerivativeContext.php
includes/context/RequestContext.php

@@@ -41,11 -41,9 +41,11 @@@ abstract class ContextSource implement
        public function getContext() {
                if ( $this->context === null ) {
                        $class = get_class( $this );
 -                      wfDebug( __METHOD__ . " ($class): called and \$context is null. Using RequestContext::getMain() for sanity\n" );
 +                      wfDebug( __METHOD__ . " ($class): called and \$context is null. " .
 +                              "Using RequestContext::getMain() for sanity\n" );
                        $this->context = RequestContext::getMain();
                }
 +
                return $this->context;
        }
  
                $this->context = $context;
        }
  
+       /**
+        * Get the SiteConfiguration object
+        *
+        * @since 1.23
+        * @return SiteConfiguration
+        */
+       public function getConfig() {
+               return $this->getContext()->getConfig();
+       }
        /**
         * Get the WebRequest object
         *
         */
        public function getLang() {
                wfDeprecated( __METHOD__, '1.19' );
 +
                return $this->getLanguage();
        }
  
         */
        public function msg( /* $args */ ) {
                $args = func_get_args();
 +
                return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
        }
  
@@@ -65,6 -65,11 +65,11 @@@ class DerivativeContext extends Context
         */
        private $skin;
  
+       /**
+        * @var SiteConfiguration
+        */
+       private $config;
        /**
         * Constructor
         * @param IContextSource $context Context to inherit from
                $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
         *
         * Set the Title object
         *
         * @param Title $t
 +       * @throws MWException
         */
        public function setTitle( $t ) {
                if ( $t !== null && !$t instanceof Title ) {
         */
        public function msg() {
                $args = func_get_args();
 +
                return call_user_func_array( 'wfMessage', $args )->setContext( $this );
        }
  }
@@@ -63,6 -63,33 +63,33 @@@ class RequestContext implements IContex
         */
        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
         *
                        global $wgRequest; # fallback to $wg till we can improve this
                        $this->request = $wgRequest;
                }
 +
                return $this->request;
        }
  
         * Set the Title object
         *
         * @param Title $t
 +       * @throws MWException
         */
        public function setTitle( $t ) {
                if ( $t !== null && !$t instanceof Title ) {
                        global $wgTitle; # fallback to $wg till we can improve this
                        $this->title = $wgTitle;
                }
 +
                return $this->title;
        }
  
                        }
                        $this->wikipage = WikiPage::factory( $title );
                }
 +
                return $this->wikipage;
        }
  
                if ( $this->output === null ) {
                        $this->output = new OutputPage( $this );
                }
 +
                return $this->output;
        }
  
                if ( $this->user === null ) {
                        $this->user = User::newFromSession( $this->getRequest() );
                }
 +
                return $this->user;
        }
  
         */
        public function getLang() {
                wfDeprecated( __METHOD__, '1.19' );
 +
                return $this->getLanguage();
        }
  
                        $this->skin->setContext( $this );
                        wfProfileOut( __METHOD__ . '-createskin' );
                }
 +
                return $this->skin;
        }
  
         */
        public function msg() {
                $args = func_get_args();
 +
                return call_user_func_array( 'wfMessage', $args )->setContext( $this );
        }
  
                if ( $instance === null ) {
                        $instance = new self;
                }
 +
                return $instance;
        }
  
                        $user = User::newFromName( $params['ip'], false );
                }
  
 -              $importSessionFunction = function( User $user, array $params ) {
 +              $importSessionFunction = function ( User $user, array $params ) {
                        global $wgRequest, $wgUser;
  
                        $context = RequestContext::getMain();
                $importSessionFunction( $user, $params );
  
                // Set callback to save and close the new session and reload the old one
 -              return new ScopedCallback( function() use ( $importSessionFunction, $oUser, $oParams ) {
 +              return new ScopedCallback( function () use ( $importSessionFunction, $oUser, $oParams ) {
                        $importSessionFunction( $oUser, $oParams );
                } );
        }
                        $context->setRequest( new FauxRequest( $request ) );
                }
                $context->user = User::newFromName( '127.0.0.1', false );
 +
                return $context;
        }
  }