Merge "Language: s/error_log/wfWarn/"
[lhc/web/wiklou.git] / includes / MediaWiki.php
index 1b014f6..9213c02 100644 (file)
  */
 class MediaWiki {
        /**
-        * @todo Fold $output, etc, into this
         * @var IContextSource
         */
        private $context;
 
        /**
-        * @param null|WebRequest $x
-        * @return WebRequest
+        * @var Config
         */
-       public function request( WebRequest $x = null ) {
-               $old = $this->context->getRequest();
-               if ( $x ) {
-                       $this->context->setRequest( $x );
-               }
-               return $old;
-       }
-
-       /**
-        * @param null|OutputPage $x
-        * @return OutputPage
-        */
-       public function output( OutputPage $x = null ) {
-               $old = $this->context->getOutput();
-               if ( $x ) {
-                       $this->context->setOutput( $x );
-               }
-               return $old;
-       }
+       private $config;
 
        /**
         * @param IContextSource|null $context
@@ -65,6 +45,7 @@ class MediaWiki {
                }
 
                $this->context = $context;
+               $this->config = $context->getConfig();
        }
 
        /**
@@ -174,7 +155,7 @@ class MediaWiki {
         * @return void
         */
        private function performRequest() {
-               global $wgServer, $wgUsePathInfo, $wgTitle;
+               global $wgTitle;
 
                wfProfileIn( __METHOD__ );
 
@@ -237,7 +218,7 @@ class MediaWiki {
                                $url = $title->getFullURL( $query );
                        }
                        // Check for a redirect loop
-                       if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url )
+                       if ( !preg_match( '/^' . preg_quote( $this->config->get( 'Server' ), '/' ) . '/', $url )
                                && $title->isLocal()
                        ) {
                                // 301 so google et al report the target as the actual url.
@@ -268,7 +249,7 @@ class MediaWiki {
                                        "requested; this sometimes happens when moving a wiki " .
                                        "to a new server or changing the server configuration.\n\n";
 
-                               if ( $wgUsePathInfo ) {
+                               if ( $this->config->get( 'UsePathInfo' ) ) {
                                        $message .= "The wiki is trying to interpret the page " .
                                                "title from the URL path portion (PATH_INFO), which " .
                                                "sometimes fails depending on the web server. Try " .
@@ -323,8 +304,6 @@ class MediaWiki {
         * @return mixed An Article, or a string to redirect to another URL
         */
        private function initializeArticle() {
-               global $wgDisableHardRedirects;
-
                wfProfileIn( __METHOD__ );
 
                $title = $this->context->getTitle();
@@ -372,7 +351,7 @@ class MediaWiki {
                                // Is the target already set by an extension?
                                $target = $target ? $target : $article->followRedirect();
                                if ( is_string( $target ) ) {
-                                       if ( !$wgDisableHardRedirects ) {
+                                       if ( !$this->config->get( 'DisableHardRedirects' ) ) {
                                                // we'll need to redirect
                                                wfProfileOut( __METHOD__ );
                                                return $target;
@@ -406,8 +385,6 @@ class MediaWiki {
         * @param Title $requestTitle The original title, before any redirects were applied
         */
        private function performAction( Page $page, Title $requestTitle ) {
-               global $wgUseSquid, $wgSquidMaxage;
-
                wfProfileIn( __METHOD__ );
 
                $request = $this->context->getRequest();
@@ -428,10 +405,10 @@ class MediaWiki {
 
                if ( $action instanceof Action ) {
                        # Let Squid cache things if we can purge them.
-                       if ( $wgUseSquid &&
+                       if ( $this->config->get( 'UseSquid' ) &&
                                in_array( $request->getFullRequestURL(), $requestTitle->getSquidURLs() )
                        ) {
-                               $output->setSquidMaxage( $wgSquidMaxage );
+                               $output->setSquidMaxage( $this->config->get( 'SquidMaxage' ) );
                        }
 
                        $action->show();
@@ -479,8 +456,6 @@ class MediaWiki {
         * @return bool
         */
        private function checkMaxLag() {
-               global $wgShowHostnames;
-
                wfProfileIn( __METHOD__ );
                $maxLag = $this->context->getRequest()->getVal( 'maxlag' );
                if ( !is_null( $maxLag ) ) {
@@ -491,7 +466,7 @@ class MediaWiki {
                                $resp->header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
                                $resp->header( 'X-Database-Lag: ' . intval( $lag ) );
                                $resp->header( 'Content-Type: text/plain' );
-                               if ( $wgShowHostnames ) {
+                               if ( $this->config->get( 'ShowHostnames' ) ) {
                                        echo "Waiting for $host: $lag seconds lagged\n";
                                } else {
                                        echo "Waiting for a database server: $lag seconds lagged\n";
@@ -507,22 +482,22 @@ class MediaWiki {
        }
 
        private function main() {
-               global $wgUseFileCache, $wgTitle, $wgUseAjax;
+               global $wgTitle;
 
                wfProfileIn( __METHOD__ );
 
                $request = $this->context->getRequest();
 
                // Send Ajax requests to the Ajax dispatcher.
-               if ( $wgUseAjax && $request->getVal( 'action', 'view' ) == 'ajax' ) {
+               if ( $this->config->get( 'UseAjax' ) && $request->getVal( 'action', 'view' ) == 'ajax' ) {
 
                        // Set a dummy title, because $wgTitle == null might break things
                        $title = Title::makeTitle( NS_MAIN, 'AJAX' );
                        $this->context->setTitle( $title );
                        $wgTitle = $title;
 
-                       $dispatcher = new AjaxDispatcher();
-                       $dispatcher->performAction();
+                       $dispatcher = new AjaxDispatcher( $this->config );
+                       $dispatcher->performAction( $this->context->getUser() );
                        wfProfileOut( __METHOD__ );
                        return;
                }
@@ -581,7 +556,7 @@ class MediaWiki {
                        }
                }
 
-               if ( $wgUseFileCache && $title->getNamespace() >= 0 ) {
+               if ( $this->config->get( 'UseFileCache' ) && $title->getNamespace() >= 0 ) {
                        wfProfileIn( 'main-try-filecache' );
                        if ( HTMLFileCache::useFileCache( $this->context ) ) {
                                // Try low-level file cache hit
@@ -645,9 +620,8 @@ class MediaWiki {
         * the socket once it's done.
         */
        protected function triggerJobs() {
-               global $wgJobRunRate, $wgServer, $wgRunJobsAsync;
-
-               if ( $wgJobRunRate <= 0 || wfReadOnly() ) {
+               $jobRunRate = $this->config->get( 'JobRunRate' );
+               if ( $jobRunRate <= 0 || wfReadOnly() ) {
                        return;
                } elseif ( $this->getTitle()->isSpecial( 'RunJobs' ) ) {
                        return; // recursion guard
@@ -655,17 +629,17 @@ class MediaWiki {
 
                $section = new ProfileSection( __METHOD__ );
 
-               if ( $wgJobRunRate < 1 ) {
+               if ( $jobRunRate < 1 ) {
                        $max = mt_getrandmax();
-                       if ( mt_rand( 0, $max ) > $max * $wgJobRunRate ) {
-                               return; // the higher $wgJobRunRate, the less likely we return here
+                       if ( mt_rand( 0, $max ) > $max * $jobRunRate ) {
+                               return; // the higher the job run rate, the less likely we return here
                        }
                        $n = 1;
                } else {
-                       $n = intval( $wgJobRunRate );
+                       $n = intval( $jobRunRate );
                }
 
-               if ( !$wgRunJobsAsync ) {
+               if ( !$this->config->get( 'RunJobsAsync' ) ) {
                        // Fall back to running the job here while the user waits
                        $runner = new JobRunner();
                        $runner->run( array( 'maxJobs'  => $n ) );
@@ -683,10 +657,11 @@ class MediaWiki {
 
                $query = array( 'title' => 'Special:RunJobs',
                        'tasks' => 'jobs', 'maxjobs' => $n, 'sigexpiry' => time() + 5 );
-               $query['signature'] = SpecialRunJobs::getQuerySignature( $query );
+               $query['signature'] = SpecialRunJobs::getQuerySignature(
+                       $query, $this->config->get( 'SecretKey' ) );
 
                $errno = $errstr = null;
-               $info = wfParseUrl( $wgServer );
+               $info = wfParseUrl( $this->config->get( 'Server' ) );
                wfSuppressWarnings();
                $sock = fsockopen(
                        $info['host'],