jenkins-bot has submitted this change and it was merged.

Change subject: Add GettingStarted notification after user confirms their email:
......................................................................


Add GettingStarted notification after user confirms their email:

* Variations depending on whether they have edited main namespace.
* Does not sent notification if they've already been a user for 30+ days.

Change-Id: Id95be0d56bc27a1702473d2524c4e96f88b871f7
---
M GettingStarted.hooks.php
M GettingStarted.i18n.php
M GettingStarted.php
A resources/ext.gettingstarted.echo.css
A resources/images/echo-gettingstarted-icon.png
5 files changed, 168 insertions(+), 2 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/GettingStarted.hooks.php b/GettingStarted.hooks.php
index e1cf00d..73851ad 100644
--- a/GettingStarted.hooks.php
+++ b/GettingStarted.hooks.php
@@ -33,6 +33,11 @@
         */
        public static function onBeforePageDisplay( $out, $skin ) {
                $out->addModules( 'ext.gettingstarted.openTask' );
+
+               if ( class_exists( 'EchoNotifier' ) ) {
+                       $out->addModules( 'ext.gettingstarted.echo' );
+               }
+
                return true;
        }
 
@@ -104,4 +109,110 @@
 
                return true;
        }
+
+       public static function onBeforeCreateEchoEvent( &$notifications, 
&$categories ) {
+               // Currently not used, but most notifications seem to include 
agent as a param.
+               // It will allow username to be included later with just a 
message change.
+               $defaults = array(
+                       'category' => 'system',
+                       'group' => 'positive',
+                       'title-params' => array( 'agent' ),
+                       'email-subject-params' => array( 'agent' ),
+                       'email-body-params' => array( 'agent', 'titlelink', 
'email-footer' ),
+                       'email-body-batch-params' => array( 'agent', 
'titlelink' ),
+                       'icon' => 'gettingstarted',
+               );
+
+               $notifications['gettingstarted-start-editing'] = array(
+                       'title-message' => 
'notification-gettingstarted-start-editing',
+                       'email-subject-message' => 
'notification-gettingstarted-start-editing-email-subject',
+                       'email-body-message' => 
'notification-gettingstarted-start-editing-text-email-body',
+                       'email-body-batch-message' => 
'notification-gettingstarted-start-editing-text-email-batch-body',
+               ) + $defaults;
+
+               $notifications['gettingstarted-continue-editing'] = array(
+                       'title-message' => 
'notification-gettingstarted-continue-editing',
+                       'email-subject-message' => 
'notification-gettingstarted-continue-editing-email-subject',
+                       'email-body-message' => 
'notification-gettingstarted-continue-editing-text-email-body',
+                       'email-body-batch-message' => 
'notification-gettingstarted-continue-editing-text-email-batch-body',
+               ) + $defaults;
+
+               return true;
+       }
+
+       public static function onEchoGetDefaultNotifiedUsers( $event, &$users ) 
{
+               $type = $event->getType();
+               if ( $type === 'gettingstarted-start-editing' || $type === 
'gettingstarted-continue-editing' ) {
+                       $users[$event->getAgent()->getId()] = 
$event->getAgent();
+               }
+
+               return true;
+       }
+
+       /**
+        * Checks if they have edited the main namespace
+        *
+        * @param User $user user to check
+        * @return true if they have, false otherwise
+        */
+       protected static function hasEditedMainNamespace( $user ) {
+               global $wgRequest;
+
+               $api = new ApiMain(
+                       new DerivativeRequest(
+                               $wgRequest,
+                               array(
+                                       'action' => 'query',
+                                       'list' => 'usercontribs',
+                                       'ucuser' => $user->getName(),
+                                       'uclimit' => 1,
+                                       'ucnamespace' => NS_MAIN,
+                               ),
+                               false // not posted
+                       ),
+                       false // disable write
+               );
+
+               $api->execute();
+               $result = $api->getResultData();
+               return isset( $result['query']['usercontribs'] ) && count( 
$result['query']['usercontribs'] ) >= 1;
+       }
+
+       /**
+        * Checks if they signed up within 
wgGettingStartedRecentPeriodInSeconds period.
+        *
+        * @param User $user user to check
+        * @return boolean true if recent, false otherwise
+        */
+       protected static function isRecentSignup( $user ) {
+               global $wgGettingStartedRecentPeriodInSeconds;
+
+               $registration = $user->getRegistration();
+               if ( $registration === null ) {
+                       return false;
+               }
+
+               $secondsSinceSignup = wfTimestamp( TS_UNIX ) - wfTimestamp( 
TS_UNIX, $registration );
+               return $secondsSinceSignup < 
$wgGettingStartedRecentPeriodInSeconds;
+       }
+
+       public static function onConfirmEmailComplete( $user ) {
+               if ( class_exists( 'EchoNotifier' ) ) {
+                       // The goal is to only do this notification once 
per-user.
+                       // Absent a clean way to do that, this notifies them if 
they signed up with a given time duration.
+                       if ( self::isRecentSignup( $user ) ) {
+                               $type = self::hasEditedMainNamespace( $user ) ? 
'gettingstarted-continue-editing' : 'gettingstarted-start-editing';
+                               EchoEvent::create( array(
+                                       'type' => $type,
+                                       'title' => SpecialPage::getTitleFor( 
'GettingStarted' ),
+                                       'agent' => $user,
+                                       'extra' => array(
+                                               'notifyAgent' => true,
+                                       ),
+                               ) );
+                       }
+               }
+
+               return true;
+       }
 }
diff --git a/GettingStarted.i18n.php b/GettingStarted.i18n.php
index 9d0335e..51d719d 100644
--- a/GettingStarted.i18n.php
+++ b/GettingStarted.i18n.php
@@ -32,8 +32,23 @@
        'guidedtour-tour-gettingstartedpage-clarification-title' => 'Improve 
clarity',
        'guidedtour-tour-gettingstartedpage-clarification-description' => 
"Other people have tagged these pages as confusing, unclear, or vague. It might 
be the whole page that needs fixing, or just a sentence. You don't need to be 
an expert in the topic, just try to make things easier to understand.",
        'guidedtour-tour-gettingstartedpage-add-links-title' => 'Link pages 
together',
-       'guidedtour-tour-gettingstartedpage-add-links-description' => "Every 
link between {{SITENAME}} pages is added by hand, and these pages don't have 
enough. Just add two square brackets around key topics when you're editing, and 
it will link to the relevant {{SITENAME}} page."
+       'guidedtour-tour-gettingstartedpage-add-links-description' => "Every 
link between {{SITENAME}} pages is added by hand, and these pages don't have 
enough. Just add two square brackets around key topics when you're editing, and 
it will link to the relevant {{SITENAME}} page.",
+       'notification-gettingstarted-start-editing' => '{{SITENAME}} is a free 
encyclopedia written by people like you. [[Special:GettingStarted|Get started]] 
by making your first contribution!',
+       'notification-gettingstarted-start-editing-email-subject' => 'Get 
started with editing {{SITENAME}}',
+       'notification-gettingstarted-start-editing-text-email-body' => 
'{{SITENAME}} is a free encyclopedia written by people like you. Get started by 
making your first contribution!
 
+Visit $2 for a list of easy ways to improve pages.
+
+$3',
+       'notification-gettingstarted-start-editing-text-email-batch-body' => 
'Get started with {{SITENAME}} editing by visiting $2',
+       'notification-gettingstarted-continue-editing' => 'Nice work! You\'ve 
already made your first edits to {{SITENAME}}. If you\'re looking for more to 
do, here are some [[Special:GettingStarted|easy ways to contribute]].',
+       'notification-gettingstarted-continue-editing-email-subject' => 'Easy 
ways to improve {{SITENAME}}',
+       'notification-gettingstarted-continue-editing-text-email-body' => 'Nice 
work! You\'ve already made your first edits to {{SITENAME}}.
+
+If you\'re looking for more to do, there\'s a list of easy ways to help at $2
+
+$3',
+       'notification-gettingstarted-continue-editing-text-email-batch-body' => 
'Looking for more to do? Visit $2 for a list of easy ways to help.',
 );
 
 /** Message documentation (Message documentation)
@@ -69,6 +84,28 @@
        'guidedtour-tour-gettingstartedpage-clarification-description' => 
'Description of clarification tooltip on Special:GettingStarted',
        'guidedtour-tour-gettingstartedpage-add-links-title' => 'Title of 
tooltip about adding links on Special:GettingStarted.',
        'guidedtour-tour-gettingstartedpage-add-links-description' => 
'Description of tooltip about adding links on Special:GettingStarted',
+       'notification-gettingstarted-start-editing' => 'Text shown on web when 
someone confirms their email but has not yet edited the main namespace:
+* $1 - username (unused); GENDER is supported',
+       'notification-gettingstarted-start-editing-email-subject' => 'Subject 
of email sent when someone confirms their email but has not yet edited the main 
namespace:
+* $1 - username (unused); GENDER is supported',
+       'notification-gettingstarted-start-editing-text-email-body' => 'Body of 
text email sent when someone confirms their email but has not yet edited the 
main namespace:
+* $1 - username (unused); GENDER is supported
+* $2 - URL of Special:GettingStarted
+* $3 - email footer',
+       'notification-gettingstarted-start-editing-text-email-batch-body' => 
'Body of batch version of text email sent when someone confirms their email but 
has not yet edited the main namespace:
+* $1 - username (unused); GENDER is supported
+* $2 - URL of Special:GettingStarted',
+       'notification-gettingstarted-continue-editing' => 'Text shown on web 
when someone confirms their email, and has already edited the main namespace:
+* $1 - username (unused); GENDER is supported',
+       'notification-gettingstarted-continue-editing-email-subject' => 
'Subject of email sent when someone confirms their email, and has already 
edited the main namespace:
+* $1 - username (unused); GENDER is supported',
+       'notification-gettingstarted-continue-editing-text-email-body' => 'Body 
of text email sent when someone confirms their email, and has already edited 
the main namespace:
+* $1 - username (unused); GENDER is supported
+* $2 - URL of Special:GettingStarted
+* $3 - email footer',
+       'notification-gettingstarted-continue-editing-text-email-batch-body' => 
'Body of batch version of text email sent when someone confirms their email, 
and has already edited the main namespace:
+* $1 - username (unused); GENDER is supported
+* $2 - URL of Special:GettingStarted',
 );
 
 /** Belarusian (Taraškievica orthography) (беларуская (тарашкевіца)‎)
diff --git a/GettingStarted.php b/GettingStarted.php
index ad360f3..0086dbe 100644
--- a/GettingStarted.php
+++ b/GettingStarted.php
@@ -52,6 +52,10 @@
        )
 );
 
+// If they signed up with this number of seconds, it's considered recent
+// Below default is 30 days.
+$wgGettingStartedRecentPeriodInSeconds = 2592000;
+
 /**
  * @var string|bool: redis host to use; false if unset.
  * @example string: '127.0.0.1'
@@ -98,7 +102,7 @@
        ),
 ) + $gettingStartedModuleInfo;
 
-// Every page site-wide
+// ext.gettingstarted.openTask and ext.gettingstarted.echo (if Echo is 
enabled) are every page site-wide.
 $wgResourceModules[ 'ext.gettingstarted.openTask' ] = array(
        'scripts' => 'ext.gettingstarted.openTask.js',
        'dependencies' => array(
@@ -113,6 +117,10 @@
        'messages' => array(
                'red-link-title'
        )
+) + $gettingStartedModuleInfo;
+
+$wgResourceModules[ 'ext.gettingstarted.echo' ] = array(
+       'styles' => 'ext.gettingstarted.echo.css'
 ) + $gettingStartedModuleInfo;
 
 // This loads on both account creation and the special page, even if JS is off
@@ -152,3 +160,6 @@
 $wgHooks[ 'LinksUpdateComplete' ][] = 
'RedisCategorySync::onLinksUpdateComplete';
 $wgHooks[ 'ListDefinedTags' ][] = 'GettingStartedHooks::onListDefinedTags';
 $wgHooks[ 'MakeGlobalVariablesScript' ][] = 
'GettingStartedHooks::onMakeGlobalVariablesScript';
+$wgHooks[ 'BeforeCreateEchoEvent' ][] = 
'GettingStartedHooks::onBeforeCreateEchoEvent';
+$wgHooks[ 'EchoGetDefaultNotifiedUsers' ][] = 
'GettingStartedHooks::onEchoGetDefaultNotifiedUsers';
+$wgHooks[ 'ConfirmEmailComplete' ][] = 
'GettingStartedHooks::onConfirmEmailComplete';
diff --git a/resources/ext.gettingstarted.echo.css 
b/resources/ext.gettingstarted.echo.css
new file mode 100644
index 0000000..187c55b
--- /dev/null
+++ b/resources/ext.gettingstarted.echo.css
@@ -0,0 +1,7 @@
+/* Loaded on every page so it is available for Echo */
+
+/* I had to add extra specificity to override the default 'none' background */
+.mw-echo-icon.mw-echo-icon-gettingstarted {
+       /* @embed */
+       background-image: url(images/echo-gettingstarted-icon.png);
+}
diff --git a/resources/images/echo-gettingstarted-icon.png 
b/resources/images/echo-gettingstarted-icon.png
new file mode 100644
index 0000000..c343ff4
--- /dev/null
+++ b/resources/images/echo-gettingstarted-icon.png
Binary files differ

-- 
To view, visit https://gerrit.wikimedia.org/r/56321
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id95be0d56bc27a1702473d2524c4e96f88b871f7
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/GettingStarted
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Spage <[email protected]>
Gerrit-Reviewer: Swalling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to