MediaWiki master
RecentChangeNotifyJob.php
Go to the documentation of this file.
1<?php
6
7namespace MediaWiki\RecentChanges;
8
9use MediaWiki\JobQueue\Job;
10use MediaWiki\Title\Title;
11use MediaWiki\User\User;
12
22 private RecentChangeLookup $recentChangeLookup;
23
24 public function __construct(
26 array $params,
27 RecentChangeLookup $recentChangeLookup
28 ) {
29 parent::__construct( 'enotifNotify', $title, $params );
30
31 $this->recentChangeLookup = $recentChangeLookup;
32 }
33
35 public function run() {
36 $notifier = new RecentChangeNotifier();
37 // Get the user from ID (rename safe). Anons are 0, so defer to name.
38 if ( isset( $this->params['editorID'] ) && $this->params['editorID'] ) {
39 $editor = User::newFromId( $this->params['editorID'] );
40 // B/C, only the name might be given.
41 } else {
42 # @todo FIXME: newFromName could return false on a badly configured wiki.
43 $editor = User::newFromName( $this->params['editor'], false );
44 }
45 if ( !array_key_exists( 'rc_id', $this->params ) ) {
46 $this->setLastError(
47 'Cannot execute RecentChangeNotifyJob without `rc_id`. This has to be an old job'
48 );
49 return true;
50 }
51 $recentChange = $this->recentChangeLookup->getRecentChangeById( $this->params['rc_id'] );
52 if ( $recentChange ) {
53 $notifier->actuallyNotifyOnPageChange(
54 $editor,
55 $this->title,
56 $recentChange,
57 $this->params['watchers'],
58 $this->params['pageStatus']
59 );
60 }
61 return true;
62 }
63}
64
66class_alias( RecentChangeNotifyJob::class, 'EnotifNotifyJob' );
Describe and execute a background job.
Definition Job.php:28
array $params
Array of job parameters.
Definition Job.php:33
setLastError( $error)
Definition Job.php:424
Find watchers and create notifications after a page is changed.
__construct(Title $title, array $params, RecentChangeLookup $recentChangeLookup)
run()
Run the job.If this method returns false or completes exceptionally, the job runner will retry execut...
Represents a title within MediaWiki.
Definition Title.php:69