MediaWiki  1.30.0
JobRunner.php
Go to the documentation of this file.
1 <?php
26 use Liuggio\StatsdClient\Factory\StatsdDataFactory;
27 use Psr\Log\LoggerAwareInterface;
28 use Psr\Log\LoggerInterface;
29 use Wikimedia\ScopedCallback;
33 
40 class JobRunner implements LoggerAwareInterface {
42  protected $config;
44  protected $debug;
45 
49  protected $logger;
50 
51  const MAX_ALLOWED_LAG = 3; // abort if more than this much DB lag is present
52  const LAG_CHECK_PERIOD = 1.0; // check replica DB lag this many seconds
53  const ERROR_BACKOFF_TTL = 1; // seconds to back off a queue due to errors
54  const READONLY_BACKOFF_TTL = 30; // seconds to back off a queue due to read-only errors
55 
59  public function setDebugHandler( $debug ) {
60  $this->debug = $debug;
61  }
62 
67  public function setLogger( LoggerInterface $logger ) {
68  $this->logger = $logger;
69  }
70 
74  public function __construct( LoggerInterface $logger = null ) {
75  if ( $logger === null ) {
76  $logger = LoggerFactory::getInstance( 'runJobs' );
77  }
78  $this->setLogger( $logger );
79  $this->config = MediaWikiServices::getInstance()->getMainConfig();
80  }
81 
106  public function run( array $options ) {
107  $jobClasses = $this->config->get( 'JobClasses' );
108  $profilerLimits = $this->config->get( 'TrxProfilerLimits' );
109 
110  $response = [ 'jobs' => [], 'reached' => 'none-ready' ];
111 
112  $type = isset( $options['type'] ) ? $options['type'] : false;
113  $maxJobs = isset( $options['maxJobs'] ) ? $options['maxJobs'] : false;
114  $maxTime = isset( $options['maxTime'] ) ? $options['maxTime'] : false;
115  $noThrottle = isset( $options['throttle'] ) && !$options['throttle'];
116 
117  // Bail if job type is invalid
118  if ( $type !== false && !isset( $jobClasses[$type] ) ) {
119  $response['reached'] = 'none-possible';
120  return $response;
121  }
122  // Bail out if DB is in read-only mode
123  if ( wfReadOnly() ) {
124  $response['reached'] = 'read-only';
125  return $response;
126  }
127 
128  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
129  // Bail out if there is too much DB lag.
130  // This check should not block as we want to try other wiki queues.
131  list( , $maxLag ) = $lbFactory->getMainLB( wfWikiID() )->getMaxLag();
132  if ( $maxLag >= self::MAX_ALLOWED_LAG ) {
133  $response['reached'] = 'replica-lag-limit';
134  return $response;
135  }
136 
137  // Flush any pending DB writes for sanity
138  $lbFactory->commitAll( __METHOD__ );
139 
140  // Catch huge single updates that lead to replica DB lag
141  $trxProfiler = Profiler::instance()->getTransactionProfiler();
142  $trxProfiler->setLogger( LoggerFactory::getInstance( 'DBPerformance' ) );
143  $trxProfiler->setExpectations( $profilerLimits['JobRunner'], __METHOD__ );
144 
145  // Some jobs types should not run until a certain timestamp
146  $backoffs = []; // map of (type => UNIX expiry)
147  $backoffDeltas = []; // map of (type => seconds)
148  $wait = 'wait'; // block to read backoffs the first time
149 
150  $group = JobQueueGroup::singleton();
151  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
152  $jobsPopped = 0;
153  $timeMsTotal = 0;
154  $startTime = microtime( true ); // time since jobs started running
155  $lastCheckTime = 1; // timestamp of last replica DB check
156  do {
157  // Sync the persistent backoffs with concurrent runners
158  $backoffs = $this->syncBackoffDeltas( $backoffs, $backoffDeltas, $wait );
159  $blacklist = $noThrottle ? [] : array_keys( $backoffs );
160  $wait = 'nowait'; // less important now
161 
162  if ( $type === false ) {
163  $job = $group->pop(
166  $blacklist
167  );
168  } elseif ( in_array( $type, $blacklist ) ) {
169  $job = false; // requested queue in backoff state
170  } else {
171  $job = $group->pop( $type ); // job from a single queue
172  }
173  $lbFactory->commitMasterChanges( __METHOD__ ); // flush any JobQueueDB writes
174 
175  if ( $job ) { // found a job
176  ++$jobsPopped;
177  $popTime = time();
178  $jType = $job->getType();
179 
180  WebRequest::overrideRequestId( $job->getRequestId() );
181 
182  // Back off of certain jobs for a while (for throttling and for errors)
183  $ttw = $this->getBackoffTimeToWait( $job );
184  if ( $ttw > 0 ) {
185  // Always add the delta for other runners in case the time running the
186  // job negated the backoff for each individually but not collectively.
187  $backoffDeltas[$jType] = isset( $backoffDeltas[$jType] )
188  ? $backoffDeltas[$jType] + $ttw
189  : $ttw;
190  $backoffs = $this->syncBackoffDeltas( $backoffs, $backoffDeltas, $wait );
191  }
192 
193  $info = $this->executeJob( $job, $lbFactory, $stats, $popTime );
194  if ( $info['status'] !== false || !$job->allowRetries() ) {
195  $group->ack( $job ); // succeeded or job cannot be retried
196  $lbFactory->commitMasterChanges( __METHOD__ ); // flush any JobQueueDB writes
197  }
198 
199  // Back off of certain jobs for a while (for throttling and for errors)
200  if ( $info['status'] === false && mt_rand( 0, 49 ) == 0 ) {
201  $ttw = max( $ttw, $this->getErrorBackoffTTL( $info['error'] ) );
202  $backoffDeltas[$jType] = isset( $backoffDeltas[$jType] )
203  ? $backoffDeltas[$jType] + $ttw
204  : $ttw;
205  }
206 
207  $response['jobs'][] = [
208  'type' => $jType,
209  'status' => ( $info['status'] === false ) ? 'failed' : 'ok',
210  'error' => $info['error'],
211  'time' => $info['timeMs']
212  ];
213  $timeMsTotal += $info['timeMs'];
214 
215  // Break out if we hit the job count or wall time limits...
216  if ( $maxJobs && $jobsPopped >= $maxJobs ) {
217  $response['reached'] = 'job-limit';
218  break;
219  } elseif ( $maxTime && ( microtime( true ) - $startTime ) > $maxTime ) {
220  $response['reached'] = 'time-limit';
221  break;
222  }
223 
224  // Don't let any of the main DB replica DBs get backed up.
225  // This only waits for so long before exiting and letting
226  // other wikis in the farm (on different masters) get a chance.
227  $timePassed = microtime( true ) - $lastCheckTime;
228  if ( $timePassed >= self::LAG_CHECK_PERIOD || $timePassed < 0 ) {
229  try {
230  $lbFactory->waitForReplication( [
231  'ifWritesSince' => $lastCheckTime,
232  'timeout' => self::MAX_ALLOWED_LAG
233  ] );
234  } catch ( DBReplicationWaitError $e ) {
235  $response['reached'] = 'replica-lag-limit';
236  break;
237  }
238  $lastCheckTime = microtime( true );
239  }
240  // Don't let any queue replica DBs/backups fall behind
241  if ( $jobsPopped > 0 && ( $jobsPopped % 100 ) == 0 ) {
242  $group->waitForBackups();
243  }
244 
245  // Bail if near-OOM instead of in a job
246  if ( !$this->checkMemoryOK() ) {
247  $response['reached'] = 'memory-limit';
248  break;
249  }
250  }
251  } while ( $job ); // stop when there are no jobs
252 
253  // Sync the persistent backoffs for the next runJobs.php pass
254  if ( $backoffDeltas ) {
255  $this->syncBackoffDeltas( $backoffs, $backoffDeltas, 'wait' );
256  }
257 
258  $response['backoffs'] = $backoffs;
259  $response['elapsed'] = $timeMsTotal;
260 
261  return $response;
262  }
263 
268  private function getErrorBackoffTTL( $error ) {
269  return strpos( $error, 'DBReadOnlyError' ) !== false
272  }
273 
281  private function executeJob( Job $job, LBFactory $lbFactory, $stats, $popTime ) {
282  $jType = $job->getType();
283  $msg = $job->toString() . " STARTING";
284  $this->logger->debug( $msg, [
285  'job_type' => $job->getType(),
286  ] );
287  $this->debugCallback( $msg );
288 
289  // Run the job...
290  $rssStart = $this->getMaxRssKb();
291  $jobStartTime = microtime( true );
292  try {
293  $fnameTrxOwner = get_class( $job ) . '::run'; // give run() outer scope
294  $lbFactory->beginMasterChanges( $fnameTrxOwner );
295  $status = $job->run();
296  $error = $job->getLastError();
297  $this->commitMasterChanges( $lbFactory, $job, $fnameTrxOwner );
298  // Important: this must be the last deferred update added (T100085, T154425)
300  // Run any deferred update tasks; doUpdates() manages transactions itself
302  } catch ( Exception $e ) {
304  $status = false;
305  $error = get_class( $e ) . ': ' . $e->getMessage();
306  }
307  // Always attempt to call teardown() even if Job throws exception.
308  try {
309  $job->teardown( $status );
310  } catch ( Exception $e ) {
312  }
313 
314  // Commit all outstanding connections that are in a transaction
315  // to get a fresh repeatable read snapshot on every connection.
316  // Note that jobs are still responsible for handling replica DB lag.
317  $lbFactory->flushReplicaSnapshots( __METHOD__ );
318  // Clear out title cache data from prior snapshots
319  MediaWikiServices::getInstance()->getLinkCache()->clear();
320  $timeMs = intval( ( microtime( true ) - $jobStartTime ) * 1000 );
321  $rssEnd = $this->getMaxRssKb();
322 
323  // Record how long jobs wait before getting popped
324  $readyTs = $job->getReadyTimestamp();
325  if ( $readyTs ) {
326  $pickupDelay = max( 0, $popTime - $readyTs );
327  $stats->timing( 'jobqueue.pickup_delay.all', 1000 * $pickupDelay );
328  $stats->timing( "jobqueue.pickup_delay.$jType", 1000 * $pickupDelay );
329  }
330  // Record root job age for jobs being run
331  $rootTimestamp = $job->getRootJobParams()['rootJobTimestamp'];
332  if ( $rootTimestamp ) {
333  $age = max( 0, $popTime - wfTimestamp( TS_UNIX, $rootTimestamp ) );
334  $stats->timing( "jobqueue.pickup_root_age.$jType", 1000 * $age );
335  }
336  // Track the execution time for jobs
337  $stats->timing( "jobqueue.run.$jType", $timeMs );
338  // Track RSS increases for jobs (in case of memory leaks)
339  if ( $rssStart && $rssEnd ) {
340  $stats->updateCount( "jobqueue.rss_delta.$jType", $rssEnd - $rssStart );
341  }
342 
343  if ( $status === false ) {
344  $msg = $job->toString() . " t={job_duration} error={job_error}";
345  $this->logger->error( $msg, [
346  'job_type' => $job->getType(),
347  'job_duration' => $timeMs,
348  'job_error' => $error,
349  ] );
350 
351  $msg = $job->toString() . " t=$timeMs error={$error}";
352  $this->debugCallback( $msg );
353  } else {
354  $msg = $job->toString() . " t={job_duration} good";
355  $this->logger->info( $msg, [
356  'job_type' => $job->getType(),
357  'job_duration' => $timeMs,
358  ] );
359 
360  $msg = $job->toString() . " t=$timeMs good";
361  $this->debugCallback( $msg );
362  }
363 
364  return [ 'status' => $status, 'error' => $error, 'timeMs' => $timeMs ];
365  }
366 
370  private function getMaxRssKb() {
371  $info = wfGetRusage() ?: [];
372  // see https://linux.die.net/man/2/getrusage
373  return isset( $info['ru_maxrss'] ) ? (int)$info['ru_maxrss'] : null;
374  }
375 
381  private function getBackoffTimeToWait( Job $job ) {
382  $throttling = $this->config->get( 'JobBackoffThrottling' );
383 
384  if ( !isset( $throttling[$job->getType()] ) || $job instanceof DuplicateJob ) {
385  return 0; // not throttled
386  }
387 
388  $itemsPerSecond = $throttling[$job->getType()];
389  if ( $itemsPerSecond <= 0 ) {
390  return 0; // not throttled
391  }
392 
393  $seconds = 0;
394  if ( $job->workItemCount() > 0 ) {
395  $exactSeconds = $job->workItemCount() / $itemsPerSecond;
396  // use randomized rounding
397  $seconds = floor( $exactSeconds );
398  $remainder = $exactSeconds - $seconds;
399  $seconds += ( mt_rand() / mt_getrandmax() < $remainder ) ? 1 : 0;
400  }
401 
402  return (int)$seconds;
403  }
404 
413  private function loadBackoffs( array $backoffs, $mode = 'wait' ) {
414  $file = wfTempDir() . '/mw-runJobs-backoffs.json';
415  if ( is_file( $file ) ) {
416  $noblock = ( $mode === 'nowait' ) ? LOCK_NB : 0;
417  $handle = fopen( $file, 'rb' );
418  if ( !flock( $handle, LOCK_SH | $noblock ) ) {
419  fclose( $handle );
420  return $backoffs; // don't wait on lock
421  }
422  $content = stream_get_contents( $handle );
423  flock( $handle, LOCK_UN );
424  fclose( $handle );
425  $ctime = microtime( true );
426  $cBackoffs = json_decode( $content, true ) ?: [];
427  foreach ( $cBackoffs as $type => $timestamp ) {
428  if ( $timestamp < $ctime ) {
429  unset( $cBackoffs[$type] );
430  }
431  }
432  } else {
433  $cBackoffs = [];
434  }
435 
436  return $cBackoffs;
437  }
438 
450  private function syncBackoffDeltas( array $backoffs, array &$deltas, $mode = 'wait' ) {
451  if ( !$deltas ) {
452  return $this->loadBackoffs( $backoffs, $mode );
453  }
454 
455  $noblock = ( $mode === 'nowait' ) ? LOCK_NB : 0;
456  $file = wfTempDir() . '/mw-runJobs-backoffs.json';
457  $handle = fopen( $file, 'wb+' );
458  if ( !flock( $handle, LOCK_EX | $noblock ) ) {
459  fclose( $handle );
460  return $backoffs; // don't wait on lock
461  }
462  $ctime = microtime( true );
463  $content = stream_get_contents( $handle );
464  $cBackoffs = json_decode( $content, true ) ?: [];
465  foreach ( $deltas as $type => $seconds ) {
466  $cBackoffs[$type] = isset( $cBackoffs[$type] ) && $cBackoffs[$type] >= $ctime
467  ? $cBackoffs[$type] + $seconds
468  : $ctime + $seconds;
469  }
470  foreach ( $cBackoffs as $type => $timestamp ) {
471  if ( $timestamp < $ctime ) {
472  unset( $cBackoffs[$type] );
473  }
474  }
475  ftruncate( $handle, 0 );
476  fwrite( $handle, json_encode( $cBackoffs ) );
477  flock( $handle, LOCK_UN );
478  fclose( $handle );
479 
480  $deltas = [];
481 
482  return $cBackoffs;
483  }
484 
490  private function checkMemoryOK() {
491  static $maxBytes = null;
492  if ( $maxBytes === null ) {
493  $m = [];
494  if ( preg_match( '!^(\d+)(k|m|g|)$!i', ini_get( 'memory_limit' ), $m ) ) {
495  list( , $num, $unit ) = $m;
496  $conv = [ 'g' => 1073741824, 'm' => 1048576, 'k' => 1024, '' => 1 ];
497  $maxBytes = $num * $conv[strtolower( $unit )];
498  } else {
499  $maxBytes = 0;
500  }
501  }
502  $usedBytes = memory_get_usage();
503  if ( $maxBytes && $usedBytes >= 0.95 * $maxBytes ) {
504  $msg = "Detected excessive memory usage ({used_bytes}/{max_bytes}).";
505  $this->logger->error( $msg, [
506  'used_bytes' => $usedBytes,
507  'max_bytes' => $maxBytes,
508  ] );
509 
510  $msg = "Detected excessive memory usage ($usedBytes/$maxBytes).";
511  $this->debugCallback( $msg );
512 
513  return false;
514  }
515 
516  return true;
517  }
518 
523  private function debugCallback( $msg ) {
524  if ( $this->debug ) {
525  call_user_func_array( $this->debug, [ wfTimestamp( TS_DB ) . " $msg\n" ] );
526  }
527  }
528 
540  private function commitMasterChanges( LBFactory $lbFactory, Job $job, $fnameTrxOwner ) {
541  $syncThreshold = $this->config->get( 'JobSerialCommitThreshold' );
542 
543  $time = false;
544  $lb = $lbFactory->getMainLB( wfWikiID() );
545  if ( $syncThreshold !== false && $lb->getServerCount() > 1 ) {
546  // Generally, there is one master connection to the local DB
547  $dbwSerial = $lb->getAnyOpenConnection( $lb->getWriterIndex() );
548  // We need natively blocking fast locks
549  if ( $dbwSerial && $dbwSerial->namedLocksEnqueue() ) {
550  $time = $dbwSerial->pendingWriteQueryDuration( $dbwSerial::ESTIMATE_DB_APPLY );
551  if ( $time < $syncThreshold ) {
552  $dbwSerial = false;
553  }
554  } else {
555  $dbwSerial = false;
556  }
557  } else {
558  // There are no replica DBs or writes are all to foreign DB (we don't handle that)
559  $dbwSerial = false;
560  }
561 
562  if ( !$dbwSerial ) {
563  $lbFactory->commitMasterChanges(
564  $fnameTrxOwner,
565  // Abort if any transaction was too big
566  [ 'maxWriteDuration' => $this->config->get( 'MaxJobDBWriteDuration' ) ]
567  );
568 
569  return;
570  }
571 
572  $ms = intval( 1000 * $time );
573 
574  $msg = $job->toString() . " COMMIT ENQUEUED [{job_commit_write_ms}ms of writes]";
575  $this->logger->info( $msg, [
576  'job_type' => $job->getType(),
577  'job_commit_write_ms' => $ms,
578  ] );
579 
580  $msg = $job->toString() . " COMMIT ENQUEUED [{$ms}ms of writes]";
581  $this->debugCallback( $msg );
582 
583  // Wait for an exclusive lock to commit
584  if ( !$dbwSerial->lock( 'jobrunner-serial-commit', __METHOD__, 30 ) ) {
585  // This will trigger a rollback in the main loop
586  throw new DBError( $dbwSerial, "Timed out waiting on commit queue." );
587  }
588  $unlocker = new ScopedCallback( function () use ( $dbwSerial ) {
589  $dbwSerial->unlock( 'jobrunner-serial-commit', __METHOD__ );
590  } );
591 
592  // Wait for the replica DBs to catch up
593  $pos = $lb->getMasterPos();
594  if ( $pos ) {
595  $lb->waitForAll( $pos );
596  }
597 
598  // Actually commit the DB master changes
599  $lbFactory->commitMasterChanges(
600  $fnameTrxOwner,
601  // Abort if any transaction was too big
602  [ 'maxWriteDuration' => $this->config->get( 'MaxJobDBWriteDuration' ) ]
603  );
604  ScopedCallback::consume( $unlocker );
605  }
606 }
JobQueueGroup\USE_CACHE
const USE_CACHE
Definition: JobQueueGroup.php:52
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
JobRunner\ERROR_BACKOFF_TTL
const ERROR_BACKOFF_TTL
Definition: JobRunner.php:53
JobRunner\$logger
$logger
Definition: JobRunner.php:49
Profiler\instance
static instance()
Singleton.
Definition: Profiler.php:62
JobRunner\__construct
__construct(LoggerInterface $logger=null)
Definition: JobRunner.php:74
JobQueueGroup\TYPE_DEFAULT
const TYPE_DEFAULT
Definition: JobQueueGroup.php:49
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2040
Wikimedia\Rdbms\DBReplicationWaitError
Exception class for replica DB wait timeouts.
Definition: DBReplicationWaitError.php:28
$status
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action or null $user:User who performed the tagging when the tagging is subsequent to the action or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition: hooks.txt:1245
JobRunner\getBackoffTimeToWait
getBackoffTimeToWait(Job $job)
Definition: JobRunner.php:381
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
JobRunner\executeJob
executeJob(Job $job, LBFactory $lbFactory, $stats, $popTime)
Definition: JobRunner.php:281
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1324
Wikimedia\Rdbms\LBFactory\flushReplicaSnapshots
flushReplicaSnapshots( $fname=__METHOD__)
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshot.
Definition: LBFactory.php:189
Wikimedia\Rdbms\DBError
Database error base class.
Definition: DBError.php:30
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Wikimedia\Rdbms\LBFactory\commitMasterChanges
commitMasterChanges( $fname=__METHOD__, array $options=[])
Commit changes on all master connections.
Definition: LBFactory.php:210
JobRunner\syncBackoffDeltas
syncBackoffDeltas(array $backoffs, array &$deltas, $mode='wait')
Merge the current backoff expiries from persistent storage.
Definition: JobRunner.php:450
Job
Class to both describe a background job and handle jobs.
Definition: Job.php:31
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, IDatabase $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:111
JobRunner\setLogger
setLogger(LoggerInterface $logger)
Definition: JobRunner.php:67
JobRunner\READONLY_BACKOFF_TTL
const READONLY_BACKOFF_TTL
Definition: JobRunner.php:54
JobRunner\debugCallback
debugCallback( $msg)
Log the job message.
Definition: JobRunner.php:523
MWExceptionHandler\rollbackMasterChangesAndLog
static rollbackMasterChangesAndLog( $e)
Roll back any open database transactions and log the stack trace of the exception.
Definition: MWExceptionHandler.php:93
JobRunner\run
run(array $options)
Run jobs of the specified number/type for the specified time.
Definition: JobRunner.php:106
Wikimedia\Rdbms\LBFactory\getMainLB
getMainLB( $domain=false)
JobRunner\LAG_CHECK_PERIOD
const LAG_CHECK_PERIOD
Definition: JobRunner.php:52
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1778
JobRunner\loadBackoffs
loadBackoffs(array $backoffs, $mode='wait')
Get the previous backoff expiries from persistent storage On I/O or lock acquisition failure this ret...
Definition: JobRunner.php:413
DuplicateJob
No-op job that does nothing.
Definition: DuplicateJob.php:29
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
JobRunner\setDebugHandler
setDebugHandler( $debug)
Definition: JobRunner.php:59
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:2807
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2141
JobRunner\$debug
callable null $debug
Debug output handler.
Definition: JobRunner.php:44
$response
this hook is for auditing only $response
Definition: hooks.txt:781
DeferredUpdates\doUpdates
static doUpdates( $mode='run', $stage=self::ALL)
Do any deferred updates and clear the list.
Definition: DeferredUpdates.php:123
Wikimedia\Rdbms\LBFactory\beginMasterChanges
beginMasterChanges( $fname=__METHOD__)
Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)
Definition: LBFactory.php:198
JobRunner\getMaxRssKb
getMaxRssKb()
Definition: JobRunner.php:370
wfTempDir
wfTempDir()
Tries to get the system directory for temporary files.
Definition: GlobalFunctions.php:2107
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1965
JobRunner\commitMasterChanges
commitMasterChanges(LBFactory $lbFactory, Job $job, $fnameTrxOwner)
Issue a commit on all masters who are currently in a transaction and have made changes to the databas...
Definition: JobRunner.php:540
JobRunner\$config
Config $config
Definition: JobRunner.php:42
$job
if(count( $args)< 1) $job
Definition: recompressTracked.php:47
Wikimedia\Rdbms\LBFactory
An interface for generating database load balancers.
Definition: LBFactory.php:38
JobQueueGroup\singleton
static singleton( $wiki=false)
Definition: JobQueueGroup.php:72
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
LoggerFactory
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method. MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances. The "Spi" in MediaWiki\Logger\Spi stands for "service provider interface". An SPI is an API intended to be implemented or extended by a third party. This software design pattern is intended to enable framework extension and replaceable components. It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki. The service provider interface allows the backend logging library to be implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime. This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance. Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
$wait
$wait
Definition: styleTest.css.php:46
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
JobRunner\MAX_ALLOWED_LAG
const MAX_ALLOWED_LAG
Definition: JobRunner.php:51
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
JobRunner
Job queue runner utility methods.
Definition: JobRunner.php:40
WebRequest\overrideRequestId
static overrideRequestId( $id)
Override the unique request ID.
Definition: WebRequest.php:288
JobRunner\getErrorBackoffTTL
getErrorBackoffTTL( $error)
Definition: JobRunner.php:268
wfGetRusage
wfGetRusage()
Get system resource usage of current request context.
Definition: ProfilerFunctions.php:32
array
the array() calling protocol came about after MediaWiki 1.4rc1.
MWExceptionHandler\logException
static logException( $e, $catcher=self::CAUGHT_BY_OTHER)
Log an exception to the exception log (if enabled).
Definition: MWExceptionHandler.php:613
JobRunner\checkMemoryOK
checkMemoryOK()
Make sure that this script is not too close to the memory usage limit.
Definition: JobRunner.php:490
$type
$type
Definition: testCompression.php:48