X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMediaWiki.php;h=0424633a93414ca05ec7d279fabdd0908977c2c1;hb=1bb93ae45ab6fefd269b1be1c1dab13077aec320;hp=1c245c1db929b40f1b5a562006fd2884c2061bb8;hpb=6dcffe76658c8e142733c32d120888d5f6357dc7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 1c245c1db9..0424633a93 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -32,13 +32,20 @@ class MediaWiki { */ private $context; + /** + * @var Config + */ + private $config; + /** * @param null|WebRequest $x * @return WebRequest */ public function request( WebRequest $x = null ) { $old = $this->context->getRequest(); - $this->context->setRequest( $x ); + if ( $x ) { + $this->context->setRequest( $x ); + } return $old; } @@ -48,7 +55,9 @@ class MediaWiki { */ public function output( OutputPage $x = null ) { $old = $this->context->getOutput(); - $this->context->setOutput( $x ); + if ( $x ) { + $this->context->setOutput( $x ); + } return $old; } @@ -61,6 +70,7 @@ class MediaWiki { } $this->context = $context; + $this->config = $context->getConfig(); } /** @@ -170,7 +180,7 @@ class MediaWiki { * @return void */ private function performRequest() { - global $wgServer, $wgUsePathInfo, $wgTitle; + global $wgTitle; wfProfileIn( __METHOD__ ); @@ -198,7 +208,9 @@ class MediaWiki { // Check user's permissions to read this page. // We have to check here to catch special pages etc. // We will check again in Article::view(). - $permErrors = $title->getUserPermissionsErrors( 'read', $user ); + $permErrors = $title->isSpecial( 'RunJobs' ) + ? array() // relies on HMAC key signature alone + : $title->getUserPermissionsErrors( 'read', $user ); if ( count( $permErrors ) ) { // Bug 32276: allowing the skin to generate output with $wgTitle or // $this->context->title set to the input title would allow anonymous users to @@ -231,7 +243,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. @@ -262,7 +274,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 " . @@ -317,8 +329,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(); @@ -366,7 +376,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; @@ -400,8 +410,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(); @@ -422,10 +430,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(); @@ -473,8 +481,6 @@ class MediaWiki { * @return bool */ private function checkMaxLag() { - global $wgShowHostnames; - wfProfileIn( __METHOD__ ); $maxLag = $this->context->getRequest()->getVal( 'maxlag' ); if ( !is_null( $maxLag ) ) { @@ -485,7 +491,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"; @@ -501,22 +507,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; } @@ -575,7 +581,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 @@ -639,9 +645,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 @@ -649,20 +654,20 @@ 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 running jobs asynchronously has been disabled, run the job here - // while the user waits - SpecialRunJobs::executeJobs( $n ); + if ( !$this->config->get( 'RunJobsAsync' ) ) { + // Fall back to running the job here while the user waits + $runner = new JobRunner(); + $runner->run( array( 'maxJobs' => $n ) ); return; } @@ -677,10 +682,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'], @@ -695,7 +701,8 @@ class MediaWiki { if ( !$sock ) { wfDebugLog( 'runJobs', "Failed to start cron API (socket error $errno): $errstr\n" ); // Fall back to running the job here while the user waits - SpecialRunJobs::executeJobs( $n ); + $runner = new JobRunner(); + $runner->run( array( 'maxJobs' => $n ) ); return; }