Merge "Expand the protocol for proto-relative links when printing"
[lhc/web/wiklou.git] / includes / Wiki.php
index 6cf718c..297041b 100644 (file)
@@ -444,7 +444,15 @@ class MediaWiki {
        public function run() {
                try {
                        $this->checkMaxLag();
-                       $this->main();
+                       try {
+                               $this->main();
+                       } catch ( ErrorPageError $e ) {
+                               // Bug 62091: while exceptions are convenient to bubble up GUI errors,
+                               // they are not internal application faults. As with normal requests, this
+                               // should commit, print the output, do deferred updates, jobs, and profiling.
+                               wfGetLBFactory()->commitMasterChanges();
+                               $e->report(); // display the GUI error
+                       }
                        if ( function_exists( 'fastcgi_finish_request' ) ) {
                                fastcgi_finish_request();
                        }
@@ -624,7 +632,7 @@ class MediaWiki {
         * the socket once it's done.
         */
        protected function triggerJobs() {
-               global $wgJobRunRate, $wgServer;
+               global $wgJobRunRate, $wgServer, $wgRunJobsAsync;
 
                if ( $wgJobRunRate <= 0 || wfReadOnly() ) {
                        return;
@@ -644,6 +652,22 @@ class MediaWiki {
                        $n = intval( $wgJobRunRate );
                }
 
+               if ( !$wgRunJobsAsync ) {
+                       // If running jobs asynchronously has been disabled, run the job here
+                       // while the user waits
+                       SpecialRunJobs::executeJobs( $n );
+                       return;
+               }
+
+               try {
+                       if ( !JobQueueGroup::singleton()->queuesHaveJobs( JobQueueGroup::TYPE_DEFAULT ) ) {
+                               return; // do not send request if there are probably no jobs
+                       }
+               } catch ( JobQueueError $e ) {
+                       MWExceptionHandler::logException( $e );
+                       return; // do not make the site unavailable
+               }
+
                $query = array( 'title' => 'Special:RunJobs',
                        'tasks' => 'jobs', 'maxjobs' => $n, 'sigexpiry' => time() + 5 );
                $query['signature'] = SpecialRunJobs::getQuerySignature( $query );