Merge "API: Allow for format modules that cannot handle errors"
[lhc/web/wiklou.git] / includes / Wiki.php
index d78d7cb..6cf718c 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,15 +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 );
-
-               if ( !$wgEnableAPI ) {
-                       // Fall back to running the job here while the user waits
-                       ApiRunJobs::executeJobs( $n );
-                       return;
-               }
+               $query['signature'] = SpecialRunJobs::getQuerySignature( $query );
 
                $errno = $errstr = null;
                $info = wfParseUrl( $wgServer );
@@ -656,17 +655,20 @@ class MediaWiki {
                        $info['host'],
                        isset( $info['port'] ) ? $info['port'] : 80,
                        $errno,
-                       $errstr
+                       $errstr,
+                       // If it takes more than 100ms to connect to ourselves there
+                       // is a problem elsewhere.
+                       0.1
                );
                wfRestoreWarnings();
                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
-                       ApiRunJobs::executeJobs( $n );
+                       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" );