Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/305669
Change subject: [EXPERIMENTAL] [DON'T MERGE] Add timestamps to generated notifications ...................................................................... [EXPERIMENTAL] [DON'T MERGE] Add timestamps to generated notifications This is an experiment to see if we can add those timestamps at all when using the maintenance script to create notifications. ** DO NOT MERGE ** Change-Id: I9e6b8660178ca0734979946c8e6ec8d43fc3de41 --- M includes/model/Event.php M maintenance/generateSampleNotifications.php 2 files changed, 32 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/69/305669/1 diff --git a/includes/model/Event.php b/includes/model/Event.php index 325d8ad..f9ae05f 100644 --- a/includes/model/Event.php +++ b/includes/model/Event.php @@ -119,7 +119,7 @@ } $obj->id = false; - if ( isset( $info['timestamp'] ) ) { + if ( isset( $info['timestamp'] ) && $info['timestamp'] !== null ) { $obj->timestamp = $info['timestamp']; } else { $obj->timestamp = wfTimestampNow(); diff --git a/maintenance/generateSampleNotifications.php b/maintenance/generateSampleNotifications.php index bd2926b..7099ed4 100644 --- a/maintenance/generateSampleNotifications.php +++ b/maintenance/generateSampleNotifications.php @@ -26,6 +26,9 @@ 'page-connection', ); + private $start_time = 0; + private $timestamp_counter = 1; + public function __construct() { parent::__construct(); $this->mDescription = "Generate sample notifications"; @@ -55,6 +58,11 @@ 'other', 'Name of another user involved with the notifications', true, true, 'o' ); + + $this->addOption( + 'fake_timestamp', + 'Fake timestamps for notifications', + false, false, 'fkt' ); } public function execute() { @@ -64,6 +72,8 @@ $user = $this->getOptionUser( 'user' ); $agent = $this->getOptionUser( 'agent' ); + $this->start_time = time(); + $otherUser = $this->getOptionUser( 'other' ); $title = Title::newFromText( 'This is a pretty long page title lets see if it is going to be truncated' ); @@ -139,7 +149,8 @@ private function getOptionUser( $optionName ) { $username = $this->getOption( $optionName ); $user = User::newFromName( $username ); - if ( $user->isAnon() ) { + + if ( !$user || $user->isAnon() ) { $this->error( "User $username does not seem to exist in this wiki", 1 ); } return $user; @@ -263,7 +274,8 @@ 'agent' => $user, 'extra' => array( 'notifyAgent' => true - ) + ), + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ) ); } @@ -276,6 +288,7 @@ 'subject' => 'Long time no see', ), 'agent' => $agent, + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ) ); } @@ -297,6 +310,7 @@ 'reason' => 'This is the reason for changing your user rights.', ), 'agent' => $agent, + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ) ); } @@ -314,6 +328,7 @@ 'extra' => array( 'recipient' => $user->getId(), ), + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ) ); } @@ -325,6 +340,7 @@ 'recipient' => $user->getId(), 'lastTranslationTitle' => 'History of the People\'s Republic of China' ), + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ) ); } @@ -366,7 +382,9 @@ 'instanceName' => 'instance1', 'projectName' => 'TheProject', 'notifyAgent' => true, - ) + ), + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, + ) ); } @@ -375,6 +393,7 @@ 'title' => Title::newFromText( "Moai" ), 'agent' => $agent, 'extra' => array( 'userAdded' => $user->getId() ), + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ) ); } @@ -403,6 +422,7 @@ 'source' => 'generateSampleNotifications.php', ], 'agent' => $agent, + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ] ); $this->output( "{$agent->getName()} is thanking {$user->getName()} for edit {$revision->getId()} on {$title->getPrefixedText()}\n" ); } @@ -422,6 +442,7 @@ 'source' => 'generateSampleNotifications.php', ], 'agent' => $agent, + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ] ); EchoEvent::create( [ 'type' => 'edit-thank', @@ -432,6 +453,7 @@ 'source' => 'generateSampleNotifications.php', ], 'agent' => $otherUser, + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ] ); $this->output( "{$agent->getName()} and {$otherUser->getName()} are thanking {$user->getName()} for edit {$revision->getId()} on {$title->getPrefixedText()}\n" ); } @@ -464,12 +486,17 @@ 'role-add-title' => $chem101, 'agent' => $agent, 'users' => array( $user->getId() ), + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ) ); } // NOTE: Not generating 'ep-course-talk-notification' for now // as it requires a full setup to actually work (institution, course, instructors, students). + } + + private function upTimestampCounter() { + return $this->timestamp_counter++; } private function generateWikibase( User $user, User $agent ) { @@ -492,6 +519,7 @@ 'repoSiteName' => 'Wikidata' ], 'agent' => $agent, + 'timestamp' => $this->getOptionUser( 'timestamp' ) ? wfTimestamp( TS_MW, $this->start_time - ( 60 * 60 * $this->upTimestampCounter() ) ) : null, ] ); } } -- To view, visit https://gerrit.wikimedia.org/r/305669 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9e6b8660178ca0734979946c8e6ec8d43fc3de41 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: master Gerrit-Owner: Mooeypoo <mor...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits