X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialRunJobs.php;h=ce5533fbf0133dd15d57065bfa31ff4b46d10053;hb=3eebaaffcf25c3779725309570de924ad5bea766;hp=8cf93670bab93e09cc5369fc0fdf0aef7c9f1811;hpb=95981990138dc6fc4b888f5f372bc57e24e3ebe5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialRunJobs.php b/includes/specials/SpecialRunJobs.php index 8cf93670ba..ce5533fbf0 100644 --- a/includes/specials/SpecialRunJobs.php +++ b/includes/specials/SpecialRunJobs.php @@ -34,30 +34,33 @@ class SpecialRunJobs extends UnlistedSpecialPage { parent::__construct( 'RunJobs' ); } + public function doesWrites() { + return true; + } + public function execute( $par = '' ) { $this->getOutput()->disable(); if ( wfReadOnly() ) { - header( "HTTP/1.0 423 Locked" ); + // HTTP 423 Locked + HttpStatus::header( 423 ); print 'Wiki is in read-only mode'; return; } elseif ( !$this->getRequest()->wasPosted() ) { - header( "HTTP/1.0 400 Bad Request" ); + HttpStatus::header( 400 ); print 'Request must be POSTed'; - return; } - $optional = array( 'maxjobs' => 0, 'maxtime' => 30, 'type' => false, 'async' => true ); - $required = array_flip( array( 'title', 'tasks', 'signature', 'sigexpiry' ) ); + $optional = [ 'maxjobs' => 0, 'maxtime' => 30, 'type' => false, 'async' => true ]; + $required = array_flip( [ 'title', 'tasks', 'signature', 'sigexpiry' ] ); $params = array_intersect_key( $this->getRequest()->getValues(), $required + $optional ); $missing = array_diff_key( $required, $params ); if ( count( $missing ) ) { - header( "HTTP/1.0 400 Bad Request" ); + HttpStatus::header( 400 ); print 'Missing parameters: ' . implode( ', ', array_keys( $missing ) ); - return; } @@ -69,9 +72,8 @@ class SpecialRunJobs extends UnlistedSpecialPage { $verified = is_string( $providedSignature ) && hash_equals( $correctSignature, $providedSignature ); if ( !$verified || $params['sigexpiry'] < time() ) { - header( "HTTP/1.0 400 Bad Request" ); + HttpStatus::header( 400 ); print 'Invalid or stale signature provided'; - return; } @@ -83,20 +85,31 @@ class SpecialRunJobs extends UnlistedSpecialPage { // but it needs to know when it is safe to disconnect. Until this // reaches ignore_user_abort(), it is not safe as the jobs won't run. ignore_user_abort( true ); // jobs may take a bit of time - header( "HTTP/1.0 202 Accepted" ); + // HTTP 202 Accepted + HttpStatus::header( 202 ); ob_flush(); flush(); // Once the client receives this response, it can disconnect + set_error_handler( function ( $errno, $errstr ) { + if ( strpos( $errstr, 'Cannot modify header information' ) !== false ) { + return true; // bug T115413 + } + // Delegate unhandled errors to the default MediaWiki handler + // so that fatal errors get proper logging (T89169) + return call_user_func_array( + 'MWExceptionHandler::handleError', func_get_args() + ); + } ); } // Do all of the specified tasks... if ( in_array( 'jobs', explode( '|', $params['tasks'] ) ) ) { $runner = new JobRunner( LoggerFactory::getInstance( 'runJobs' ) ); - $response = $runner->run( array( + $response = $runner->run( [ 'type' => $params['type'], 'maxJobs' => $params['maxjobs'] ? $params['maxjobs'] : 1, 'maxTime' => $params['maxtime'] ? $params['maxjobs'] : 30 - ) ); + ] ); if ( !$params['async'] ) { print FormatJson::encode( $response, true ); }