r107617 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107616‎ | r107617 | r107618 >
Date:01:31, 30 December 2011
Author:bsitu
Status:ok (Comments)
Tags:
Comment:
Adding ClickTracking to Feedback Response Email links
Modified paths:
  • /trunk/extensions/MoodBar/ApiFeedbackDashboardResponse.php (modified) (history)
  • /trunk/extensions/MoodBar/MoodBar.i18n.php (modified) (history)
  • /trunk/extensions/MoodBar/include/MoodBarHTMLEmailNotification.php (modified) (history)
  • /trunk/extensions/MoodBar/include/MoodBarHTMLMailerJob.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/include/MoodBarHTMLMailerJob.php
@@ -25,7 +25,8 @@
2626 $this->title,
2727 $this->params['timestamp'],
2828 $this->params['feedback'],
29 - $this->params['response']
 29+ $this->params['response'],
 30+ $this->params['type']
3031 );
3132 return true;
3233 }
Index: trunk/extensions/MoodBar/include/MoodBarHTMLEmailNotification.php
@@ -7,7 +7,7 @@
88 class MoodBarHTMLEmailNotification {
99
1010 protected $to, $subject, $body, $replyto, $from;
11 - protected $timestamp, $composed_common, $response, $feedback;
 11+ protected $timestamp, $composed_common, $response, $feedback, $type;
1212 protected $mime_boundary;
1313
1414 /**
@@ -36,8 +36,9 @@
3737 * @param $timestamp string Edit timestamp
3838 * @param $response string response text
3939 * @param $feedback integer feedback id
 40+ * @param $type string moodbar type
4041 */
41 - public function notifyOnRespond( $editor, $title, $timestamp, $feedback, $response ) {
 42+ public function notifyOnRespond( $editor, $title, $timestamp, $feedback, $response, $type ) {
4243 global $wgEnotifUseJobQ, $wgEnotifUserTalk;
4344
4445 if ( $title->getNamespace() != NS_USER_TALK || !$wgEnotifUserTalk ||
@@ -51,12 +52,13 @@
5253 'editorID' => $editor->getID(),
5354 'timestamp' => $timestamp,
5455 'response' => $response,
55 - 'feedback' => $feedback
 56+ 'feedback' => $feedback,
 57+ 'type' => $type
5658 );
5759 $job = new MoodBarHTMLMailerJob( $title, $params );
5860 $job->insert();
5961 } else {
60 - $this->actuallyNotifyOnRespond( $editor, $title, $timestamp, $feedback, $response );
 62+ $this->actuallyNotifyOnRespond( $editor, $title, $timestamp, $feedback, $response, $type );
6163 }
6264 }
6365
@@ -71,8 +73,9 @@
7274 * @param $timestamp string Edit timestamp
7375 * @param $response string response text
7476 * @param $feedabck integer feedback id
 77+ * @param $type string moodbar type
7578 */
76 - public function actuallyNotifyOnRespond( $editor, $title, $timestamp, $feedback, $response ) {
 79+ public function actuallyNotifyOnRespond( $editor, $title, $timestamp, $feedback, $response, $type ) {
7780 global $wgEnotifUserTalk;
7881
7982 wfProfileIn( __METHOD__ );
@@ -87,6 +90,7 @@
8891 $this->composed_common = false;
8992 $this->response = $response;
9093 $this->feedback = $feedback;
 94+ $this->type = $type;
9195
9296 if ( $wgEnotifUserTalk && $this->canSendUserTalkEmail( $editor, $title ) ) {
9397 $this->compose( $this->targetUser );
@@ -147,28 +151,27 @@
148152 $this->subject = wfMessage( 'moodbar-enotif-subject' )->params( $pageEditor )->escaped();
149153
150154 // build the body
151 - $messageCache = MessageCache::singleton();
152 - $targetUserName = $this->targetUser->getName();
153 - $FeedbackUrl = SpecialPage::getTitleFor( 'FeedbackDashboard', $this->feedback )->getPrefixedText();
154 - $editorTalkPage = $this->editor->getTalkPage()->getPrefixedText();
155 - $targetUserTalkPage = $this->targetUser->getTalkPage()->getCanonicalUrl();
 155+ $messageCache = MessageCache::singleton();
 156+ $targetUserName = $this->targetUser->getName();
 157+ $links = $this->buildEmailLink();
 158+
156159 //text version
157160 $textBody = wfMessage( 'moodbar-enotif-body' )->params( $targetUserName,
158 - $FeedbackUrl,
159 - $editorTalkPage,
 161+ $links['feedbackPageUrl'],
 162+ $links['editorTalkPageUrl'],
160163 $this->response,
161 - $targetUserTalkPage,
 164+ $links['targetUserTalkPageUrl'],
162165 $pageEditor )->escaped();
163166 $textBody = MessageCache::singleton()->transform( $textBody, false, null, $this->title );
164167
165 - //html version, this ugly as we have to make wiki link clickable in emails
 168+ //html version, this is a little bit ugly as we have to make wiki link clickable in emails
166169 $action = $wgRequest->getVal( 'action' );
167170 $wgRequest->setVal( 'action', 'render' );
168171 $htmlBody = wfMsgExt( 'moodbar-enotif-body', array( 'parse' ), $targetUserName,
169 - $FeedbackUrl,
170 - $editorTalkPage,
 172+ $links['feedbackPageUrl'],
 173+ $links['editorTalkPageUrl'],
171174 '<div style="margin-left:20px; margin-right:20px;">' .$this->response . '</div>',
172 - $targetUserTalkPage,
 175+ $links['targetUserTalkPageUrl'],
173176 $pageEditor );
174177 $wgRequest->setVal( 'action', $action );
175178
@@ -227,7 +230,41 @@
228231 $to = new MailAddress( $user );
229232
230233 return UserMailer::send( $to, $this->from, $this->subject, $this->body, $this->replyto, $contentType = 'multipart/alternative; boundary=' . $this->mime_boundary );
231 -
232234 }
 235+
 236+ /**
 237+ * Build the link for Email, add clickTracking if available
 238+ * @return array - the links to be tracked in used in email
 239+ */
 240+ protected function buildEmailLink() {
 241+ $pageObject = array( 'feedbackPage' => SpecialPage::getTitleFor( 'FeedbackDashboard', $this->feedback ),
 242+ 'editorTalkPage' => $this->editor->getTalkPage(),
 243+ 'targetUserTalkPage' => $this->targetUser->getTalkPage() );
 244+
 245+ $links = array();
 246+
 247+ // if clickTracking is not enabled, return the full canonical url for email
 248+ if ( !class_exists( 'ApiClickTracking' ) ) {
 249+ foreach ( $pageObject AS $key => $value ) {
 250+ $links[$key.'Url'] = $value->getCanonicalURL();
 251+ }
 252+ }
 253+ else {
 254+ global $wgServer, $wgScriptPath, $wgMoodBarConfig;
 255+
 256+ $token = wfGenerateToken();
 257+ $eventid = 'ext.feedbackDashboard@' . $wgMoodBarConfig['bucketConfig']['version'] .
 258+ '-email-response_link-' . $this->type;
 259+ $clickTrackingLink = $wgServer . $wgScriptPath . '/api.php?action=clicktracking&eventid=' .
 260+ wfUrlencode( $eventid ) . '&token=' . wfUrlencode( $token );
 261+
 262+ foreach ( $pageObject AS $key => $value ) {
 263+ $links[$key.'Url'] = $clickTrackingLink . '&redirectto=' . wfUrlencode( $value->getLinkURL() ) .
 264+ '&namespacenumber=' . wfUrlencode( $value->getNamespace() );
 265+ }
 266+ }
 267+
 268+ return $links;
 269+ }
233270
234 -}
 271+}
\ No newline at end of file
Index: trunk/extensions/MoodBar/MoodBar.i18n.php
@@ -166,7 +166,7 @@
167167
168168 'moodbar-enotif-body' => 'Hello $1!
169169
170 -Welcome to {{SITENAME}}, and thanks for your [[$2|feedback]]. Another {{SITENAME}} user, [[$3|$6]], wrote the following response:
 170+Welcome to {{SITENAME}}, and thanks for your [$2 feedback]. Another {{SITENAME}} user, [$3 $6], wrote the following response:
171171
172172 $4
173173
Index: trunk/extensions/MoodBar/ApiFeedbackDashboardResponse.php
@@ -67,7 +67,7 @@
6868 global $wgLang;
6969
7070 $EMailNotif = new MoodBarHTMLEmailNotification();
71 - $EMailNotif->notifyOnRespond( $wgUser, $talkPage, wfTimestampNow(), $item->getProperty('feedback'), $wgLang->truncate( $response, 250 ) );
 71+ $EMailNotif->notifyOnRespond( $wgUser, $talkPage, wfTimestampNow(), $item->getProperty('feedback'), $wgLang->truncate( $response, 250 ), $item->getProperty('feedbackitem')->getProperty( 'type' ) );
7272
7373 }
7474

Follow-up revisions

RevisionCommit summaryAuthorDate
r107618followup to -r107617 - update function commentbsitu01:34, 30 December 2011
r107638followup to -r107617 - code style and consistency changebsitu17:45, 30 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   06:40, 30 December 2011
+			foreach ( $pageObject AS $key => $value ) {

We usually write 'as' in lower case.

+			$EMailNotif->notifyOnRespond( $wgUser, $talkPage, wfTimestampNow(), ........... );

That line is too long.

#Comment by Catrope (talk | contribs)   12:21, 4 January 2012
+			$clickTrackingLink = $wgServer . $wgScriptPath . '/api.php?action=clicktracking&eventid=' . 
+						wfUrlencode( $eventid ) . '&token=' . wfUrlencode( $token );

There's a simpler way to do that:

$clickTrackingLink = wfAppendQuery( wfScript( 'api' ), array( 'action' => 'clicktracking', 'eventid' => $eventid, 'token' => $token ) );


+				$links[$key.'Url'] = $clickTrackingLink . '&redirectto=' . wfUrlencode( $value->getLinkURL() ) . 
+							'&namespacenumber=' . wfUrlencode( $value->getNamespace() ); 

You can use wfAppendQuery() here too.

#Comment by Bsitu (talk | contribs)   19:01, 4 January 2012

Good to know, thank you! :)

Status & tagging log