From: Aaron Schulz Date: Fri, 28 Feb 2014 05:35:30 +0000 (-0800) Subject: Handle some extra cases in triggerJobs() X-Git-Tag: 1.31.0-rc.0~16790 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=1ec4e48b834aeaf473ef21cee57f0a6efb2ed9dc;p=lhc%2Fweb%2Fwiklou.git Handle some extra cases in triggerJobs() * $wgEnableAPI may be false, though it is a basic part of MediaWiki. This only disables api.php and not internal callers so just do that. * Various socket functions may disabled. Though this is a terrible wack-a-mole security measure to handle MediaWiki exploits or non-authenticated services, it may still be in use, so work around it. Change-Id: I54a209e003ffce1fe36a5898fe0da735cf5e32e4 --- diff --git a/includes/Wiki.php b/includes/Wiki.php index fb46d80d43..0f6a0b89f0 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -621,7 +621,7 @@ class MediaWiki { * the socket once it's done. */ protected function triggerJobs() { - global $wgJobRunRate, $wgServer, $wgScriptPath, $wgScriptExtension; + global $wgJobRunRate, $wgServer, $wgScriptPath, $wgScriptExtension, $wgEnableAPI; if ( $wgJobRunRate <= 0 || wfReadOnly() ) { return; @@ -643,16 +643,30 @@ class MediaWiki { 'tasks' => 'jobs', 'maxjobs' => $n, 'sigexpiry' => time() + 5 ); $query['signature'] = ApiRunJobs::getQuerySignature( $query ); + // Slow job running method in case of API or socket functions being disabled + $fallback = function() use ( $query ) { + $api = new ApiMain( new FauxRequest( $query, true ) ); + $api->execute(); + }; + + if ( !$wgEnableAPI ) { + $fallback(); + return; + } + $errno = $errstr = null; $info = wfParseUrl( $wgServer ); + wfSuppressWarnings(); $sock = fsockopen( $info['host'], isset( $info['port'] ) ? $info['port'] : 80, $errno, $errstr ); + wfRestoreWarnings(); if ( !$sock ) { wfDebugLog( 'runJobs', "Failed to start cron API (socket error $errno): $errstr\n" ); + $fallback(); return; } @@ -661,7 +675,7 @@ class MediaWiki { wfDebugLog( 'runJobs', "Running $n job(s) via '$url'\n" ); // Send a cron API request to be performed in the background. - // Give up if this takes to long to send (which should be rare). + // Give up if this takes too long to send (which should be rare). stream_set_timeout( $sock, 1 ); $bytes = fwrite( $sock, $req ); if ( $bytes !== strlen( $req ) ) {