45 parent::__construct(
'RunJobs' );
57 if ( $this->readOnlyMode->isReadOnly() ) {
58 wfHttpError( 423,
'Locked',
'Wiki is in read-only mode.' );
64 wfHttpError( 400,
'Bad Request',
'Request must be POSTed.' );
69 $optional = [
'maxjobs' => 0,
'maxtime' => 30,
'type' =>
false,
70 'async' =>
true,
'stats' => false ];
71 $required = array_fill_keys( [
'title',
'tasks',
'signature',
'sigexpiry' ],
true );
72 $params = array_intersect_key( $this->
getRequest()->getValues(), $required + $optional );
73 $missing = array_diff_key( $required, $params );
74 if ( count( $missing ) ) {
76 'Missing parameters: ' . implode(
', ', array_keys( $missing ) )
83 unset( $squery[
'signature'] );
85 $providedSignature = $params[
'signature'];
86 $verified = is_string( $providedSignature )
87 && hash_equals( $correctSignature, $providedSignature );
88 if ( !$verified || $params[
'sigexpiry'] < time() ) {
89 wfHttpError( 400,
'Bad Request',
'Invalid or stale signature provided.' );
96 if ( $params[
'async'] ) {
98 HttpStatus::header( 202 );
103 DeferredUpdates::addUpdate(
105 function () use ( $params ) {
106 $this->
doRun( $params );
110 DeferredUpdates::POSTSEND
113 $stats = $this->
doRun( $params );
115 if ( $params[
'stats'] ) {
116 $this->
getRequest()->response()->header(
'Content-Type: application/json' );
117 print FormatJson::encode( $stats );
124 protected function doRun( array $params ) {
125 return $this->jobRunner->run( [
126 'type' => $params[
'type'],
127 'maxJobs' => $params[
'maxjobs'] ?: 1,
128 'maxTime' => $params[
'maxtime'] ?: 30
139 return hash_hmac(
'sha1',
wfArrayToCgi( $query ), $secretKey );
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....
Job queue runner utility methods.
A service class for fetching the wiki's current read-only mode.
getOutput()
Get the OutputPage being used for this instance.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
Special page designed for running background tasks (internal use only)
__construct(JobRunner $jobRunner, ReadOnlyMode $readOnlyMode)
execute( $par)
Default execute method Checks user permissions.
doesWrites()
Indicates whether this special page may perform database writes.
ReadOnlyMode $readOnlyMode
static getQuerySignature(array $query, $secretKey)
Deferrable update that must run outside of any explicit LBFactory transaction round.
Shortcut to construct a special page which is unlisted by default.
while(( $__line=Maintenance::readconsole()) !==false) print