37 private $readOnlyMode;
47 parent::__construct(
'RunJobs' );
48 $this->jobRunner = $jobRunner;
49 $this->readOnlyMode = $readOnlyMode;
59 if ( $this->readOnlyMode->isReadOnly() ) {
60 wfHttpError( 423,
'Locked',
'Wiki is in read-only mode.' );
66 wfHttpError( 400,
'Bad Request',
'Request must be POSTed.' );
71 $optional = [
'maxjobs' => 0,
'maxtime' => 30,
'type' =>
false,
72 'async' =>
true,
'stats' => false ];
73 $required = array_fill_keys( [
'title',
'tasks',
'signature',
'sigexpiry' ],
true );
74 $params = array_intersect_key( $this->
getRequest()->getValues(), $required + $optional );
75 $missing = array_diff_key( $required, $params );
76 if ( count( $missing ) ) {
78 'Missing parameters: ' . implode(
', ', array_keys( $missing ) )
85 unset( $squery[
'signature'] );
87 $this->
getConfig()->
get( MainConfigNames::SecretKey ) );
88 $providedSignature = $params[
'signature'];
89 $verified = is_string( $providedSignature )
90 && hash_equals( $correctSignature, $providedSignature );
91 if ( !$verified || $params[
'sigexpiry'] < time() ) {
92 wfHttpError( 400,
'Bad Request',
'Invalid or stale signature provided.' );
99 if ( $params[
'async'] ) {
101 HttpStatus::header( 202 );
106 DeferredUpdates::addUpdate(
108 function () use ( $params ) {
109 $this->
doRun( $params );
113 DeferredUpdates::POSTSEND
116 $stats = $this->
doRun( $params );
118 if ( $params[
'stats'] ) {
119 $this->
getRequest()->response()->header(
'Content-Type: application/json' );
120 print FormatJson::encode( $stats );
127 protected function doRun( array $params ) {
128 return $this->jobRunner->run( [
129 'type' => $params[
'type'],
130 'maxJobs' => $params[
'maxjobs'] ?: 1,
131 'maxTime' => $params[
'maxtime'] ?: 30
142 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 class containing constants representing the names of configuration variables.
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.
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.