53 parent::__construct(
'RunJobs' );
54 $this->jobRunner = $jobRunner;
55 $this->readOnlyMode = $readOnlyMode;
65 if ( $this->readOnlyMode->isReadOnly() ) {
66 wfHttpError( 423,
'Locked',
'Wiki is in read-only mode.' );
72 wfHttpError( 400,
'Bad Request',
'Request must be POSTed.' );
77 $optional = [
'maxjobs' => 0,
'maxtime' => 30,
'type' =>
false,
78 'async' =>
true,
'stats' => false ];
79 $required = array_fill_keys( [
'title',
'tasks',
'signature',
'sigexpiry' ],
true );
80 $params = array_intersect_key( $this->
getRequest()->getValues(), $required + $optional );
81 $missing = array_diff_key( $required, $params );
82 if ( count( $missing ) ) {
84 'Missing parameters: ' . implode(
', ', array_keys( $missing ) )
91 unset( $squery[
'signature'] );
94 $providedSignature = $params[
'signature'];
95 $verified = is_string( $providedSignature )
96 && hash_equals( $correctSignature, $providedSignature );
97 if ( !$verified || $params[
'sigexpiry'] < time() ) {
98 wfHttpError( 400,
'Bad Request',
'Invalid or stale signature provided.' );
103 $params += $optional;
105 if ( $params[
'async'] ) {
107 HttpStatus::header( 202 );
112 DeferredUpdates::addUpdate(
114 function () use ( $params ) {
115 $this->
doRun( $params );
119 DeferredUpdates::POSTSEND
122 $stats = $this->
doRun( $params );
124 if ( $params[
'stats'] ) {
125 $this->
getRequest()->response()->header(
'Content-Type: application/json' );
126 print FormatJson::encode( $stats );
133 protected function doRun( array $params ) {
134 return $this->jobRunner->run( [
135 'type' => $params[
'type'],
136 'maxJobs' => $params[
'maxjobs'] ?: 1,
137 'maxTime' => $params[
'maxtime'] ?: 30
148 return hash_hmac(
'sha1',
wfArrayToCgi( $query ), $secretKey );
156class_alias( SpecialRunJobs::class,
'SpecialRunJobs' );
wfHttpError( $code, $label, $desc)
Provide a simple HTTP error.
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Defer callable updates to run later in the PHP process.
Job queue runner utility methods.
A class containing constants representing the names of configuration variables.
const SecretKey
Name constant for the SecretKey setting, for use with Config::get()
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getOutput()
Get the OutputPage being used for this instance.
Shortcut to construct a special page which is unlisted by default.
Deferrable update that must run outside of any explicit LBFactory transaction round.