Merge "Update the documentation at the top of parserTests.txt"
[lhc/web/wiklou.git] / includes / Wiki.php
index 0f6a0b8..4bf8fd3 100644 (file)
@@ -587,6 +587,9 @@ class MediaWiki {
                // Actually do the work of the request and build up any output
                $this->performRequest();
 
+               // Either all DB and deferred updates should happen or none.
+               // The later should not be cancelled due to client disconnect.
+               ignore_user_abort( true );
                // Now commit any transactions, so that unreported errors after
                // output() don't roll back the whole DB transaction
                wfGetLBFactory()->commitMasterChanges();
@@ -621,10 +624,12 @@ class MediaWiki {
         * the socket once it's done.
         */
        protected function triggerJobs() {
-               global $wgJobRunRate, $wgServer, $wgScriptPath, $wgScriptExtension, $wgEnableAPI;
+               global $wgJobRunRate, $wgServer;
 
                if ( $wgJobRunRate <= 0 || wfReadOnly() ) {
                        return;
+               } elseif ( $this->getTitle()->isSpecial( 'RunJobs' ) ) {
+                       return; // recursion guard
                }
 
                $section = new ProfileSection( __METHOD__ );
@@ -639,20 +644,9 @@ class MediaWiki {
                        $n = intval( $wgJobRunRate );
                }
 
-               $query = array( 'action' => 'runjobs',
+               $query = array( 'title' => 'Special:RunJobs',
                        '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;
-               }
+               $query['signature'] = SpecialRunJobs::getQuerySignature( $query );
 
                $errno = $errstr = null;
                $info = wfParseUrl( $wgServer );
@@ -666,11 +660,12 @@ class MediaWiki {
                wfRestoreWarnings();
                if ( !$sock ) {
                        wfDebugLog( 'runJobs', "Failed to start cron API (socket error $errno): $errstr\n" );
-                       $fallback();
+                       // Fall back to running the job here while the user waits
+                       SpecialRunJobs::executeJobs( $n );
                        return;
                }
 
-               $url = wfAppendQuery( "{$wgScriptPath}/api{$wgScriptExtension}", $query );
+               $url = wfAppendQuery( wfScript( 'index' ), $query );
                $req = "POST $url HTTP/1.1\r\nHost: {$info['host']}\r\nConnection: Close\r\n\r\n";
 
                wfDebugLog( 'runJobs', "Running $n job(s) via '$url'\n" );
@@ -684,7 +679,7 @@ class MediaWiki {
                        // Do not wait for the response (the script should handle client aborts).
                        // Make sure that we don't close before that script reaches ignore_user_abort().
                        $status = fgets( $sock );
-                       if ( !preg_match( '#^HTTP/\d\.\d 204 #', $status ) ) {
+                       if ( !preg_match( '#^HTTP/\d\.\d 202 #', $status ) ) {
                                wfDebugLog( 'runJobs', "Failed to start cron API: received '$status'\n" );
                        }
                }