2016-01-11 17:45:24 +00:00
< ? php
2018-08-25 10:51:14 +00:00
// phpcs:disable Generic.Files.LineLength -- Long html test examples
2019-03-11 13:25:18 +00:00
// @phan-file-suppress PhanUndeclaredClassMethod, PhanUndeclaredClassConstant Other extensions used for testing purposes
2018-08-25 10:51:14 +00:00
2022-11-02 21:34:17 +00:00
use MediaWiki\Extension\Notifications\Model\Event ;
2019-04-17 15:46:06 +00:00
use MediaWiki\Revision\RevisionRecord ;
2020-04-17 23:56:31 +00:00
use MediaWiki\Revision\SlotRecord ;
2023-12-11 15:33:08 +00:00
use MediaWiki\Title\Title ;
use MediaWiki\User\User ;
2018-06-17 16:53:56 +00:00
2016-01-11 17:45:24 +00:00
$IP = getenv ( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
$IP = __DIR__ . '/../../..' ;
}
2017-06-20 02:41:30 +00:00
require_once " $IP /maintenance/Maintenance.php " ;
2016-01-11 17:45:24 +00:00
/**
* A maintenance script that generates sample notifications for testing purposes .
*/
class GenerateSampleNotifications extends Maintenance {
2020-12-16 21:31:09 +00:00
/** @var string[] */
2016-12-05 18:51:07 +00:00
private $supportedNotificationTypes = [
2016-03-02 20:04:56 +00:00
'welcome' ,
'edit-user-talk' ,
'mention' ,
'page-linked' ,
'reverted' ,
'email' ,
'user-rights' ,
'cx' ,
'osm' ,
2016-07-29 12:20:42 +00:00
'edit-thanks' ,
'edu' ,
2016-08-04 15:19:20 +00:00
'page-connection' ,
2016-12-05 18:51:07 +00:00
];
2016-03-02 20:04:56 +00:00
2020-12-16 21:31:09 +00:00
/** @var int */
2016-08-19 18:55:05 +00:00
private $timestampCounter = 5 ;
2016-01-11 17:45:24 +00:00
public function __construct () {
parent :: __construct ();
2019-03-27 05:07:48 +00:00
$this -> addDescription ( " Generate sample notifications " );
2016-01-11 17:45:24 +00:00
$this -> addOption (
2016-03-02 20:04:56 +00:00
'force' ,
'Bypass confirmation' ,
false , false , 'f' );
$allTypes = implode ( ',' , $this -> supportedNotificationTypes );
$this -> addOption (
'types' ,
" Comma-separated list of notification types to generate ( $allTypes ) " ,
false , true , 't' );
2016-01-11 17:45:24 +00:00
$this -> addOption (
2016-03-02 20:04:56 +00:00
'user' ,
'Name of the user receiving the notifications' ,
true , true , 'u' );
2016-01-11 17:45:24 +00:00
$this -> addOption (
2016-03-02 20:04:56 +00:00
'agent' ,
'Name of the user creating the notifications' ,
true , true , 'a' );
$this -> addOption (
'other' ,
'Name of another user involved with the notifications' ,
true , true , 'o' );
2016-12-01 21:34:43 +00:00
$this -> requireExtension ( 'Echo' );
2016-08-19 18:55:05 +00:00
$this -> addOption (
'timestamp' ,
2018-08-22 14:13:10 +00:00
'Add notification timestamps (Epoch time format). All notifications that are not ' .
'related directly to edits will be created with a timestamp starting 5 minutes ' .
'before the given timestamp, and increasing by 1 minute per notification.' ,
2016-08-19 18:55:05 +00:00
false , false , 'k' );
2016-01-11 17:45:24 +00:00
}
public function execute () {
$user = $this -> getOptionUser ( 'user' );
$agent = $this -> getOptionUser ( 'agent' );
$otherUser = $this -> getOptionUser ( 'other' );
2016-02-17 17:27:49 +00:00
$title = Title :: newFromText ( 'This is a pretty long page title lets see if it is going to be truncated' );
2016-01-11 17:45:24 +00:00
2016-03-02 20:04:56 +00:00
$types = $this -> getOption ( 'types' );
if ( $types ) {
$types = explode ( ',' , $types );
} else {
$types = $this -> supportedNotificationTypes ;
}
2016-01-11 17:45:24 +00:00
$this -> confirm ();
$this -> output ( " Started processing... \n " );
2016-03-02 20:04:56 +00:00
if ( $this -> shouldGenerate ( 'welcome' , $types ) ) {
$this -> generateWelcome ( $user );
}
if ( $this -> shouldGenerate ( 'edit-user-talk' , $types ) ) {
$this -> generateEditUserTalk ( $user , $agent );
}
if ( $this -> shouldGenerate ( 'mention' , $types ) ) {
$this -> generateMention ( $user , $agent , $otherUser , $title );
}
if ( $this -> shouldGenerate ( 'page-linked' , $types ) ) {
$this -> generatePageLink ( $user , $agent );
}
if ( $this -> shouldGenerate ( 'reverted' , $types ) ) {
$this -> generateReverted ( $user , $agent );
}
if ( $this -> shouldGenerate ( 'email' , $types ) ) {
$this -> generateEmail ( $user , $agent );
}
if ( $this -> shouldGenerate ( 'user-rights' , $types ) ) {
$this -> generateUserRights ( $user , $agent );
}
if ( $this -> shouldGenerate ( 'cx' , $types ) ) {
$this -> generateContentTranslation ( $user );
}
if ( $this -> shouldGenerate ( 'osm' , $types ) ) {
$this -> generateOpenStackManager ( $user , $agent );
}
2016-01-11 17:45:24 +00:00
2016-06-16 16:04:24 +00:00
if ( $this -> shouldGenerate ( 'edit-thanks' , $types ) ) {
$this -> generateEditThanks ( $user , $agent , $otherUser );
}
2016-07-29 12:20:42 +00:00
if ( $this -> shouldGenerate ( 'edu' , $types ) ) {
$this -> generateEducationProgram ( $user , $agent );
}
2016-08-04 15:19:20 +00:00
if ( $this -> shouldGenerate ( 'page-connection' , $types ) ) {
$this -> generateWikibase ( $user , $agent );
}
2016-01-11 17:45:24 +00:00
$this -> output ( " Completed \n " );
}
2016-08-19 18:55:05 +00:00
/**
* Get the set timestamp of the event
*
2018-08-07 06:28:28 +00:00
* @ param bool $getEpoch Get the epoch value
2016-08-19 18:55:05 +00:00
* @ return int Timestamp for the operation
*/
private function getTimestamp ( $getEpoch = false ) {
2019-02-19 08:54:56 +00:00
$startTime = $this -> getOption ( 'timestamp' ) ? : time ();
2016-08-19 18:55:05 +00:00
// Incrementally decrease X minutes from start time
$timestamp = strtotime ( '-' . $this -> timestampCounter ++ . ' minute' , $startTime );
2019-12-21 05:45:14 +00:00
return $getEpoch ? $timestamp : ( int ) wfTimestamp ( TS_UNIX , $timestamp );
2016-08-19 18:55:05 +00:00
}
/**
* Add a timestamp string to the output , if a timestamp option was given ,
* to note the time of the new generated event .
*
* @ param string $output New output message with timestamp
2020-02-29 21:20:56 +00:00
* @ return string
2016-08-19 18:55:05 +00:00
*/
private function addTimestampToOutput ( $output ) {
if ( $this -> getOption ( 'timestamp' ) ) {
$output .= ' (Using timestamp: ' . date ( 'Y-m-d H:i:s' , $this -> getTimestamp ( true ) ) . ')' ;
}
return $output ;
}
2016-01-11 17:45:24 +00:00
private function generateEditUserTalk ( User $user , User $agent ) {
$this -> output ( " { $agent -> getName () } is writing on { $user -> getName () } 's user talk page \n " );
$editId = $this -> generateRandomString ();
$section = " == section $editId == \n \n this is the text $editId\n\n ~~~~ \n \n " ;
$this -> addToUserTalk ( $user , $agent , $section );
}
private function getOptionUser ( $optionName ) {
$username = $this -> getOption ( $optionName );
$user = User :: newFromName ( $username );
2020-12-22 15:36:58 +00:00
if ( ! $user -> isRegistered () ) {
2022-07-08 09:02:45 +00:00
$this -> fatalError ( " User $username does not seem to exist in this wiki " );
2016-01-11 17:45:24 +00:00
}
return $user ;
}
private function generateRandomString ( $length = 10 ) {
return substr ( str_shuffle ( " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " ), 0 , $length );
}
protected function confirm () {
2016-03-02 20:04:56 +00:00
if ( $this -> getOption ( 'force' , false ) ) {
return ;
}
2016-01-11 17:45:24 +00:00
$this -> output ( " === WARNING === \n " );
$this -> output ( " This script modifies the content of several pages, \n " );
$this -> output ( " including user's talk pages. \n " );
$this -> output ( " ONLY RUN ON TEST WIKIS \n " );
$this -> output ( " Enter 'yes' if you wish to continue or any other key to exit \n " );
$confirm = $this -> readconsole ();
if ( $confirm !== 'yes' ) {
2022-07-08 09:02:45 +00:00
$this -> fatalError ( 'Safe decision' );
2016-01-11 17:45:24 +00:00
}
}
private function addToUserTalk ( User $user , User $agent , $contentText ) {
$this -> addToPageContent ( $user -> getTalkPage (), $agent , $contentText );
}
private function addToPageContent ( Title $title , User $agent , $contentText ) {
2023-11-09 20:16:38 +00:00
$page = $this -> getServiceContainer () -> getWikiPageFactory () -> newFromTitle ( $title );
2016-01-11 17:45:24 +00:00
$previousContent = " " ;
2019-10-23 10:45:51 +00:00
$page -> loadPageData ( WikiPage :: READ_LATEST );
2020-05-27 13:44:59 +00:00
$revision = $page -> getRevisionRecord ();
2016-01-11 17:45:24 +00:00
if ( $revision ) {
2020-05-27 13:44:59 +00:00
$content = $revision -> getContent ( SlotRecord :: MAIN , RevisionRecord :: FOR_PUBLIC );
2016-01-11 17:45:24 +00:00
if ( $content instanceof WikitextContent ) {
2019-03-22 20:36:13 +00:00
$previousContent = $content -> getText ();
2016-01-11 17:45:24 +00:00
}
}
2021-06-24 04:54:45 +00:00
$status = $page -> doUserEditContent (
2016-01-11 17:45:24 +00:00
new WikitextContent ( $contentText . $previousContent ),
2021-06-24 04:54:45 +00:00
$agent ,
'generating sample notifications'
2016-01-11 17:45:24 +00:00
);
if ( ! $status -> isGood () ) {
2020-05-23 22:35:19 +00:00
$this -> error ( " Failed to edit { $title -> getPrefixedText () } : { $status -> getMessage () -> text () } " );
2016-01-11 17:45:24 +00:00
}
2016-06-16 16:04:24 +00:00
2020-06-09 23:40:08 +00:00
return $status -> getValue ()[ 'revision-record' ];
2016-01-11 17:45:24 +00:00
}
2016-02-17 17:27:49 +00:00
private function generateMention ( User $user , User $agent , User $otherUser , Title $title ) {
2016-01-11 17:45:24 +00:00
$mention = " == section { $this -> generateRandomString () } == \n Hello [[User: { $user -> getName () } ]] \n ~~~~ \n " ;
// article talk
2016-02-17 17:27:49 +00:00
$this -> output ( " { $agent -> getName () } is mentioning { $user -> getName () } on { $title -> getTalkPage () -> getPrefixedText () } \n " );
$this -> addToPageContent ( $title -> getTalkPage (), $agent , $mention );
2016-01-11 17:45:24 +00:00
2021-03-09 18:29:11 +00:00
// agent talk
2016-01-11 17:45:24 +00:00
$this -> output ( " { $agent -> getName () } is mentioning { $user -> getName () } on { $agent -> getTalkPage () -> getPrefixedText () } \n " );
$this -> addToPageContent ( $agent -> getTalkPage (), $agent , $mention );
// user talk
$this -> output ( " { $agent -> getName () } is mentioning { $user -> getName () } on { $otherUser -> getTalkPage () -> getPrefixedText () } \n " );
$this -> addToPageContent ( $otherUser -> getTalkPage (), $agent , $mention );
// any other page
2016-02-17 17:27:49 +00:00
$this -> output ( " { $agent -> getName () } is mentioning { $user -> getName () } on { $title -> getPrefixedText () } \n " );
$this -> addToPageContent ( $title , $agent , $mention );
2016-01-11 17:45:24 +00:00
}
private function generatePageLink ( User $user , User $agent ) {
2016-02-03 17:34:01 +00:00
$this -> generateOnePageLink ( $user , $agent );
$this -> generateMultiplePageLinks ( $user , $agent );
2016-01-11 17:45:24 +00:00
}
private function generateNewPageTitle () {
return Title :: newFromText ( $this -> generateRandomString () );
}
private function generateReverted ( User $user , User $agent ) {
2023-11-09 20:16:38 +00:00
$services = $this -> getServiceContainer ();
2021-03-01 15:01:31 +00:00
$services -> getUserGroupManager () -> addUserToGroup ( $agent , 'sysop' );
2016-01-11 17:45:24 +00:00
// revert (undo)
$moai = Title :: newFromText ( 'Moai' );
2022-06-03 21:00:26 +00:00
$page = $services -> getWikiPageFactory () -> newFromTitle ( $moai );
2016-01-11 17:45:24 +00:00
$this -> output ( " { $agent -> getName () } is reverting { $user -> getName () } 's edit on { $moai -> getPrefixedText () } \n " );
$this -> addToPageContent ( $moai , $agent , " \n creating a good revision here \n " );
$this -> addToPageContent ( $moai , $user , " \n adding a line here \n " );
2020-04-17 23:56:31 +00:00
$undoRev = $page -> getRevisionRecord ();
2021-03-01 15:01:31 +00:00
$previous = $services -> getRevisionLookup ()
2020-04-17 23:56:31 +00:00
-> getPreviousRevision ( $undoRev );
2021-03-01 15:01:31 +00:00
$handler = $services -> getContentHandlerFactory ()
2020-04-17 23:56:31 +00:00
-> getContentHandler (
$undoRev -> getSlot ( SlotRecord :: MAIN , RevisionRecord :: RAW )
-> getModel ()
);
$undoContent = $undoRev -> getContent ( SlotRecord :: MAIN );
$previousContent = $previous -> getContent ( SlotRecord :: MAIN );
2021-09-03 04:18:57 +00:00
if ( ! $undoContent ) {
$this -> error ( " Failed to undo { $moai -> getPrefixedText () } : undoContent is null. " );
return ;
}
if ( ! $previousContent ) {
$this -> error ( " Failed to undo { $moai -> getPrefixedText () } : previousContent is null. " );
return ;
}
2020-04-17 23:56:31 +00:00
$content = $handler -> getUndoContent (
$undoContent ,
$undoContent ,
$previousContent ,
2022-11-12 06:37:37 +00:00
// undoIsLatest
true
2020-04-17 23:56:31 +00:00
);
2021-06-24 04:54:45 +00:00
$status = $page -> doUserEditContent (
$content ,
$agent ,
'undo' ,
2022-11-12 06:37:37 +00:00
// $flags
0 ,
// $originalRevId
false ,
// $tags
[],
2021-06-24 04:54:45 +00:00
$undoRev -> getId ()
);
2021-03-09 18:29:11 +00:00
2016-01-11 17:45:24 +00:00
if ( ! $status -> isGood () ) {
2020-05-23 22:35:19 +00:00
$this -> error ( " Failed to undo { $moai -> getPrefixedText () } : { $status -> getMessage () -> text () } " );
2016-01-11 17:45:24 +00:00
}
}
private function generateWelcome ( User $user ) {
$this -> output ( " Welcoming { $user -> getName () } \n " );
2022-11-02 21:34:17 +00:00
Event :: create ( [
2016-01-11 17:45:24 +00:00
'type' => 'welcome' ,
'agent' => $user ,
2016-08-19 18:55:05 +00:00
'timestamp' => $this -> getTimestamp (),
2016-12-05 18:51:07 +00:00
] );
2016-01-11 17:45:24 +00:00
}
private function generateEmail ( User $user , User $agent ) {
2016-08-19 18:55:05 +00:00
$output = $this -> addTimestampToOutput ( " { $agent -> getName () } is emailing { $user -> getName () } " );
$this -> output ( " $output\n " );
2022-11-02 21:34:17 +00:00
Event :: create ( [
2016-01-11 17:45:24 +00:00
'type' => 'emailuser' ,
2016-12-05 18:51:07 +00:00
'extra' => [
2016-01-11 17:45:24 +00:00
'to-user-id' => $user -> getId (),
2016-02-10 17:34:26 +00:00
'subject' => 'Long time no see' ,
2016-12-05 18:51:07 +00:00
],
2016-01-11 17:45:24 +00:00
'agent' => $agent ,
2016-08-19 18:55:05 +00:00
'timestamp' => $this -> getTimestamp (),
2016-12-05 18:51:07 +00:00
] );
2016-01-11 17:45:24 +00:00
}
private function generateUserRights ( User $user , User $agent ) {
2016-08-19 18:55:05 +00:00
$output = $this -> addTimestampToOutput ( " { $agent -> getName () } is changing { $user -> getName () } 's rights " );
$this -> output ( " $output\n " );
2016-12-05 18:51:07 +00:00
$this -> createUserRightsNotification ( $user , $agent , [ 'OnlyAdd-1' ], null );
$this -> createUserRightsNotification ( $user , $agent , null , [ 'JustRemove-1' , 'JustRemove-2' ] );
$this -> createUserRightsNotification ( $user , $agent , [ 'Add-1' , 'Add-2' ], [ 'Remove-1' , 'Remove-2' ] );
2016-01-11 17:45:24 +00:00
}
private function createUserRightsNotification ( User $user , User $agent , $add , $remove ) {
2022-11-02 21:34:17 +00:00
Event :: create (
2016-12-05 18:51:07 +00:00
[
2016-01-11 17:45:24 +00:00
'type' => 'user-rights' ,
2016-12-05 18:51:07 +00:00
'extra' => [
2019-06-11 21:43:05 +00:00
'user' => $user -> getId (),
2016-01-11 17:45:24 +00:00
'add' => $add ,
'remove' => $remove ,
2018-01-09 13:41:21 +00:00
'reason' => 'This is the [[reason]] for changing your user rights.' ,
2016-12-05 18:51:07 +00:00
],
2016-01-11 17:45:24 +00:00
'agent' => $agent ,
2016-08-19 18:55:05 +00:00
'timestamp' => $this -> getTimestamp (),
2016-12-05 18:51:07 +00:00
]
2016-01-11 17:45:24 +00:00
);
}
2016-02-08 15:37:49 +00:00
private function generateContentTranslation ( User $user ) {
2017-12-27 12:13:37 +00:00
if ( ! ExtensionRegistry :: getInstance () -> isLoaded ( 'ContentTranslation' ) ) {
2016-02-08 15:37:49 +00:00
return ;
}
$this -> output ( " Generating CX notifications \n " );
2016-12-05 18:51:07 +00:00
foreach ( [ 'cx-first-translation' , 'cx-tenth-translation' , 'cx-hundredth-translation' ] as $eventType ) {
2022-11-02 21:34:17 +00:00
Event :: create (
2016-12-05 18:51:07 +00:00
[
2016-02-08 15:37:49 +00:00
'type' => $eventType ,
2016-12-05 18:51:07 +00:00
'extra' => [
2016-02-08 15:37:49 +00:00
'recipient' => $user -> getId (),
2016-12-05 18:51:07 +00:00
],
2016-08-19 18:55:05 +00:00
'timestamp' => $this -> getTimestamp (),
2016-12-05 18:51:07 +00:00
]
2016-02-08 15:37:49 +00:00
);
}
2022-11-02 21:34:17 +00:00
Event :: create (
2016-12-05 18:51:07 +00:00
[
2016-02-08 15:37:49 +00:00
'type' => 'cx-suggestions-available' ,
2016-12-05 18:51:07 +00:00
'extra' => [
2016-02-08 15:37:49 +00:00
'recipient' => $user -> getId (),
'lastTranslationTitle' => 'History of the People\'s Republic of China'
2016-12-05 18:51:07 +00:00
],
2016-08-19 18:55:05 +00:00
'timestamp' => $this -> getTimestamp (),
2016-12-05 18:51:07 +00:00
]
2016-02-08 15:37:49 +00:00
);
2016-02-03 17:34:01 +00:00
}
private function generateOnePageLink ( User $user , User $agent ) {
$pageBeingLinked = $this -> generateNewPageTitle ();
$this -> addToPageContent ( $pageBeingLinked , $user , " this is a new page " );
$pageLinking = $this -> generateNewPageTitle ();
$content = " checkout [[ { $pageBeingLinked -> getPrefixedText () } ]]! " ;
$this -> output ( " { $agent -> getName () } is linking to { $pageBeingLinked -> getPrefixedText () } from { $pageLinking -> getPrefixedText () } \n " );
$this -> addToPageContent ( $pageLinking , $agent , $content );
}
private function generateMultiplePageLinks ( User $user , User $agent ) {
$pageBeingLinked = $this -> generateNewPageTitle ();
$this -> addToPageContent ( $pageBeingLinked , $user , " this is a new page " );
2016-02-08 15:37:49 +00:00
2016-02-03 17:34:01 +00:00
$content = " checkout [[ { $pageBeingLinked -> getPrefixedText () } ]]! " ;
$this -> output ( " { $agent -> getName () } is linking to { $pageBeingLinked -> getPrefixedText () } from multiple pages \n " );
$this -> addToPageContent ( $this -> generateNewPageTitle (), $agent , $content );
2020-12-10 05:45:51 +00:00
// @phan-suppress-next-line PhanPluginDuplicateAdjacentStatement
2016-02-03 17:34:01 +00:00
$this -> addToPageContent ( $this -> generateNewPageTitle (), $agent , $content );
2020-12-10 05:45:51 +00:00
// @phan-suppress-next-line PhanPluginDuplicateAdjacentStatement
2016-02-03 17:34:01 +00:00
$this -> addToPageContent ( $this -> generateNewPageTitle (), $agent , $content );
2016-02-08 15:37:49 +00:00
}
2016-02-15 19:54:35 +00:00
private function generateOpenStackManager ( User $user , User $agent ) {
2019-03-11 13:25:18 +00:00
if ( ! ExtensionRegistry :: getInstance () -> isLoaded ( 'OpenStackManager' ) ) {
2016-02-15 19:54:35 +00:00
return ;
}
$this -> output ( " Generating OpenStackManager notifications \n " );
2016-12-05 18:51:07 +00:00
foreach ( [ 'build-completed' , 'reboot-completed' , 'deleted' ] as $action ) {
2022-11-02 21:34:17 +00:00
Event :: create ( [
2016-02-15 19:54:35 +00:00
'type' => " osm-instance- $action " ,
'title' => Title :: newFromText ( " Moai " ),
'agent' => $user ,
2016-12-05 18:51:07 +00:00
'extra' => [
2016-02-15 19:54:35 +00:00
'instanceName' => 'instance1' ,
'projectName' => 'TheProject' ,
'notifyAgent' => true ,
2016-08-19 18:55:05 +00:00
],
'timestamp' => $this -> getTimestamp (),
2016-12-05 18:51:07 +00:00
] );
2016-02-15 19:54:35 +00:00
}
2022-11-02 21:34:17 +00:00
Event :: create ( [
2016-02-15 19:54:35 +00:00
'type' => 'osm-projectmembers-add' ,
'title' => Title :: newFromText ( " Moai " ),
'agent' => $agent ,
2016-12-05 18:51:07 +00:00
'extra' => [ 'userAdded' => $user -> getId () ],
2016-08-19 18:55:05 +00:00
'timestamp' => $this -> getTimestamp (),
2016-12-05 18:51:07 +00:00
] );
2016-02-15 19:54:35 +00:00
}
2016-03-02 20:04:56 +00:00
2019-10-23 10:44:35 +00:00
private function shouldGenerate ( $type , array $types ) {
2022-06-23 09:17:10 +00:00
return in_array ( $type , $types );
2016-03-02 20:04:56 +00:00
}
2016-06-16 16:04:24 +00:00
private function generateEditThanks ( User $user , User $agent , User $otherUser ) {
$this -> generateOneEditThanks ( $user , $agent );
$this -> generateMultipleEditThanks ( $user , $agent , $otherUser );
}
private function generateOneEditThanks ( User $user , User $agent ) {
2017-12-27 12:13:37 +00:00
if ( ! ExtensionRegistry :: getInstance () -> isLoaded ( 'Thanks' ) ) {
2016-06-16 16:04:24 +00:00
return ;
}
// make an edit, thank it once
$title = $this -> generateNewPageTitle ();
2020-06-09 23:40:08 +00:00
$revisionRecord = $this -> addToPageContent ( $title , $user , " an awesome edit! ~~~~ " );
2022-11-02 21:34:17 +00:00
Event :: create ( [
2016-06-16 16:04:24 +00:00
'type' => 'edit-thank' ,
'title' => $title ,
'extra' => [
2020-06-09 23:40:08 +00:00
'revid' => $revisionRecord -> getId (),
2016-06-16 16:04:24 +00:00
'thanked-user-id' => $user -> getId (),
'source' => 'generateSampleNotifications.php' ,
],
'agent' => $agent ,
2016-08-19 18:55:05 +00:00
'timestamp' => $this -> getTimestamp (),
2016-06-16 16:04:24 +00:00
] );
2020-06-09 23:40:08 +00:00
$output = $this -> addTimestampToOutput ( " { $agent -> getName () } is thanking { $user -> getName () } for edit { $revisionRecord -> getId () } on { $title -> getPrefixedText () } " );
2016-08-19 18:55:05 +00:00
$this -> output ( " $output\n " );
2016-06-16 16:04:24 +00:00
}
2019-07-14 10:57:45 +00:00
2016-06-16 16:04:24 +00:00
private function generateMultipleEditThanks ( User $user , User $agent , User $otherUser ) {
2017-12-27 12:13:37 +00:00
if ( ! ExtensionRegistry :: getInstance () -> isLoaded ( 'Thanks' ) ) {
2016-06-16 16:04:24 +00:00
return ;
}
// make an edit, thank it twice
$title = $this -> generateNewPageTitle ();
2020-06-09 23:40:08 +00:00
$revisionRecord = $this -> addToPageContent ( $title , $user , " an even better edit! ~~~~ " );
2022-11-02 21:34:17 +00:00
Event :: create ( [
2016-06-16 16:04:24 +00:00
'type' => 'edit-thank' ,
'title' => $title ,
'extra' => [
2020-06-09 23:40:08 +00:00
'revid' => $revisionRecord -> getId (),
2016-06-16 16:04:24 +00:00
'thanked-user-id' => $user -> getId (),
'source' => 'generateSampleNotifications.php' ,
],
'agent' => $agent ,
2016-08-19 18:55:05 +00:00
'timestamp' => $this -> getTimestamp (),
2016-06-16 16:04:24 +00:00
] );
2022-11-02 21:34:17 +00:00
Event :: create ( [
2016-06-16 16:04:24 +00:00
'type' => 'edit-thank' ,
'title' => $title ,
'extra' => [
2020-06-09 23:40:08 +00:00
'revid' => $revisionRecord -> getId (),
2016-06-16 16:04:24 +00:00
'thanked-user-id' => $user -> getId (),
'source' => 'generateSampleNotifications.php' ,
],
'agent' => $otherUser ,
2016-08-19 18:55:05 +00:00
'timestamp' => $this -> getTimestamp (),
2016-06-16 16:04:24 +00:00
] );
2020-06-09 23:40:08 +00:00
$output = $this -> addTimestampToOutput ( " { $agent -> getName () } and { $otherUser -> getName () } are thanking { $user -> getName () } for edit { $revisionRecord -> getId () } on { $title -> getPrefixedText () } " );
2016-08-19 18:55:05 +00:00
$this -> output ( " $output\n " );
2016-06-16 16:04:24 +00:00
}
2016-07-29 12:20:42 +00:00
private function generateEducationProgram ( User $user , User $agent ) {
2018-11-02 15:14:21 +00:00
if ( ! ExtensionRegistry :: getInstance () -> isLoaded ( 'EducationProgram' ) ) {
$this -> output ( " Skipping EducationProgram. Extension not installed. \n " );
2016-07-29 12:20:42 +00:00
return ;
}
$chem101 = Title :: newFromText ( 'School/Chemistry101' );
if ( ! $chem101 -> exists () ) {
$this -> addToPageContent ( $chem101 , $agent , " \n This is the main page for the Chemistry 101 course \n " );
}
$notificationManager = EducationProgram\Extension :: globalInstance () -> getNotificationsManager ();
2016-08-19 18:55:05 +00:00
$output = $this -> addTimestampToOutput ( " { $agent -> getName () } is adding { $user -> getName () } to { $chem101 -> getPrefixedText () } as instructor, student, campus volunteer and online volunteer " );
$this -> output ( " $output\n " );
2016-07-29 12:20:42 +00:00
2016-12-05 18:51:07 +00:00
$types = [
2016-07-29 12:20:42 +00:00
'ep-instructor-add-notification' ,
'ep-online-add-notification' ,
'ep-campus-add-notification' ,
'ep-student-add-notification' ,
2016-12-05 18:51:07 +00:00
];
2016-07-29 12:20:42 +00:00
foreach ( $types as $type ) {
$notificationManager -> trigger (
$type ,
2016-12-05 18:51:07 +00:00
[
2016-07-29 12:20:42 +00:00
'role-add-title' => $chem101 ,
'agent' => $agent ,
2016-12-05 18:51:07 +00:00
'users' => [ $user -> getId () ],
]
2016-07-29 12:20:42 +00:00
);
}
// NOTE: Not generating 'ep-course-talk-notification' for now
// as it requires a full setup to actually work (institution, course, instructors, students).
}
2016-08-04 15:19:20 +00:00
private function generateWikibase ( User $user , User $agent ) {
2021-06-21 11:14:41 +00:00
if ( ! ExtensionRegistry :: getInstance () -> isLoaded ( 'WikibaseClient' ) ) {
2018-11-02 15:14:21 +00:00
$this -> output ( " Skipping Wikibase. Extension not installed. \n " );
2016-08-04 15:19:20 +00:00
return ;
}
$title = $this -> generateNewPageTitle ();
$this -> addToPageContent ( $title , $user , " this is a new page " );
$helpPage = Title :: newFromText ( 'Project:Wikidata' );
$this -> addToPageContent ( $helpPage , $user , " this is the help page " );
2016-08-19 18:55:05 +00:00
$output = $this -> addTimestampToOutput ( " { $agent -> getName () } is connecting { $user -> getName () } 's page { $title -> getPrefixedText () } to an item " );
$this -> output ( " $output\n " );
2022-11-02 21:34:17 +00:00
Event :: create ( [
2018-06-17 16:53:56 +00:00
'type' => EchoNotificationsHandlers :: NOTIFICATION_TYPE ,
2016-08-04 15:19:20 +00:00
'title' => $title ,
'extra' => [
'url' => Title :: newFromText ( 'Item:Q1' ) -> getFullURL (),
2019-04-05 09:06:17 +00:00
'repoSiteName' => 'Wikidata' ,
'entity' => 'Q1' ,
2016-08-04 15:19:20 +00:00
],
'agent' => $agent ,
2016-08-19 18:55:05 +00:00
'timestamp' => $this -> getTimestamp (),
2016-08-04 15:19:20 +00:00
] );
}
2016-01-11 17:45:24 +00:00
}
2019-03-03 14:14:15 +00:00
$maintClass = GenerateSampleNotifications :: class ;
2018-03-17 20:55:20 +00:00
require_once RUN_MAINTENANCE_IF_MAIN ;