From 1ec4e48b834aeaf473ef21cee57f0a6efb2ed9dc Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 27 Feb 2014 21:35:30 -0800 Subject: [PATCH] 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 --- includes/Wiki.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 ) ) { -- 2.20.1