r113052 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113051‎ | r113052 | r113053 >
Date:18:04, 5 March 2012
Author:emsmith
Status:ok (Comments)
Tags:
Comment:
bug 34090 - remaining backend feature in requirements, oversight email generation with job
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5MailerJob.php (added) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
@@ -385,23 +385,20 @@
386386 Best wishes, and thank you,
387387 The {{SITENAME}} team',
388388
389 - 'articlefeedbackv5-emailcapture-request-oversight' => 'Hello!
 389+ 'articlefeedbackv5-email-request-oversight-subject' => '$1 has requested oversight on $2',
 390+ 'articlefeedbackv5-email-request-oversight-body' => 'Hello!
390391
391392 A request for oversight has been made by
392393
393 -$1 : $2
 394+$4 : $1
394395
395 -on feedback item
396 -
397 -$3 : $4
398 -
399396 for page
400397
401 -$5 : $6
 398+$5 : $2
402399
403 -Please visit
 400+Please visit feedback item
404401
405 -$7
 402+$3
406403
407404 to decline or approve this oversight request.
408405
@@ -666,6 +663,15 @@
667664 * <code>$1</code> – URL of the confirmation link
668665 * <code>$2</code> – URL to type in the confirmation code manually.
669666 * <code>$3</code> – Confirmation code for the user to type in',
 667+ 'articlefeedbackv5-email-request-oversight-subject' => 'Subject line for email sent to oversight mailing list when an oversight request has been made.
 668+* <code>$1</code> – User name of requestor
 669+* <code>$2</code> – Page name of item with feedback requiring oversight.',
 670+ 'articlefeedbackv5-email-request-oversight-body' => 'Body of an email sent to the oversight mailing list when an oversight request has been made.
 671+* <code>$1</code> – URL of user who requested oversight
 672+* <code>$2</code> – URL of page with feedback requiring oversight
 673+* <code>$3</code> – URL directly to feedback location
 674+* <code>$4</code> – User name of requestor
 675+* <code>$5</code> – Page name of item with feedback requiring oversight.',
670676 );
671677
672678 /** Afrikaans (Afrikaans)
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
@@ -12,6 +12,15 @@
1313
1414 /* Configuration */
1515
 16+// Email address to send oversight request emails to, if set to null no emails are sent
 17+$wgArticleFeedbackv5OversightEmails = null;
 18+
 19+// Should eventually be this, let's NOT flood that list with bogus emails
 20+// $wgArticleFeedbackv5OversightEmails = 'stewards@wikimedia.org';
 21+
 22+// Name to send oversight request emails to
 23+$wgArticleFeedbackv5OversightEmailName = 'Oversighters';
 24+
1625 // How long text-based feedback is allowed to be before returning an error.
1726 // Set to 0 to disable length checking entirely.
1827 $wgArticleFeedbackv5MaxCommentLength = 0;
@@ -272,6 +281,7 @@
273282 $wgAutoloadClasses['ApiFlagFeedbackArticleFeedbackv5'] = $dir . 'api/ApiFlagFeedbackArticleFeedbackv5.php';
274283 $wgAutoloadClasses['ApiViewActivityArticleFeedbackv5'] = $dir . 'api/ApiViewActivityArticleFeedbackv5.php';
275284 $wgAutoloadClasses['ArticleFeedbackv5Hooks'] = $dir . 'ArticleFeedbackv5.hooks.php';
 285+$wgAutoloadClasses['ArticleFeedbackv5MailerJob'] = $dir . 'ArticleFeedbackv5MailerJob.php';
276286 $wgAutoloadClasses['SpecialArticleFeedbackv5'] = $dir . 'SpecialArticleFeedbackv5.php';
277287 $wgExtensionMessagesFiles['ArticleFeedbackv5'] = $dir . 'ArticleFeedbackv5.i18n.php';
278288 $wgExtensionMessagesFiles['ArticleFeedbackv5Alias'] = $dir . 'ArticleFeedbackv5.alias.php';
@@ -303,6 +313,9 @@
304314 $wgAvailableRights[] = 'aftv5-see-deleted-feedback';
305315 $wgAvailableRights[] = 'aftv5-see-hidden-feedback';
306316
 317+// Jobs
 318+$wgJobClasses['ArticleFeedbackv5MailerJob'] = 'ArticleFeedbackv5MailerJob';
 319+
307320 // Logging
308321 $wgLogTypes[] = 'articlefeedbackv5';
309322 $wgLogNames['articlefeedbackv5'] = 'articlefeedbackv5-log-name';
Index: trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php
@@ -253,6 +253,13 @@
254254 $results['hide_user'] = 0;
255255 $results['hide_timestamp'] = $timestamp;
256256 }
 257+
 258+ // IF the previous setting was 0, send an email
 259+ if ( $record->af_oversight_count < 1) {
 260+
 261+ $this->sendOversightEmail( $record->af_page_id , $feedbackId );
 262+
 263+ }
257264 } elseif($direction == 'decrease') {
258265 $activity = 'unrequest';
259266 $filters['needsoversight'] = -1;
@@ -429,6 +436,7 @@
430437 'aft_article_feedback',
431438 array(
432439 'af_id',
 440+ 'af_page_id',
433441 'af_abuse_count',
434442 'af_is_hidden',
435443 'af_helpful_count',
@@ -598,4 +606,51 @@
599607
600608 public function isWriteMode() { return true; }
601609 public function mustBePosted() { return true; }
 610+
 611+ /**
 612+ * Helper function to dig out page url and title, feedback permalink, and
 613+ * requestor page url and name - if all this data can be retrieved properly
 614+ * it shoves an email job into the queue for sending ot the oversightor's
 615+ * mailing list - only works on NEW oversight requests
 616+ *
 617+ * @param int $page_id page id to grab info on
 618+ * @param int $feedback_id identifier for the feedback item
 619+ */
 620+ protected function sendOversightEmail( $page_id, $feedback_id) {
 621+ global $wgUser;
 622+
 623+ // jobs need a title object
 624+ $title_object = Title::newFromID( $page_id );
 625+
 626+ if ( !$title_object ) {
 627+ return; // no title object, no mail
 628+ }
 629+
 630+ // get the string name of the page
 631+ $page_name = $title_object->getDBKey();
 632+
 633+ // make a title out of our user (sigh)
 634+ $user_page = Title::makeTitle( NS_USER, $wgUser->getName() );
 635+
 636+ if ( !$user_page ) {
 637+ return; // no user title object, no mail
 638+ }
 639+
 640+ // to build our permalink, use the feedback entry key + the page name (isn't page name a title? but title is an object? confusing)
 641+ $permalink = SpecialPage::getTitleFor( 'ArticleFeedbackv5', "$page_name/$feedback_id" );
 642+
 643+ if ( !$permalink ) {
 644+ return; // no proper permalink? no mail
 645+ }
 646+
 647+ // build our params
 648+ $params = array( 'user_name' => $wgUser->getName(),
 649+ 'user_url' => $user_page->getCanonicalUrl(),
 650+ 'page_name' => $title_object->getText(),
 651+ 'page_url' => $title_object->getCanonicalUrl(),
 652+ 'permalink' => $permalink->getCanonicalUrl());
 653+
 654+ $job = new ArticleFeedbackv5MailerJob( $title_object, $params );
 655+ $job->insert();
 656+ }
602657 }
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5MailerJob.php
@@ -0,0 +1,103 @@
 2+<?php
 3+/**
 4+ * SpecialArticleFeedbackv5 class
 5+ *
 6+ * @package ArticleFeedback
 7+ * @subpackage Job
 8+ * @author Elizabeth M Smith <elizabeth@omniti.com>
 9+ * @version $Id$
 10+ */
 11+
 12+/**
 13+ * This is a job to do mailings for oversight requests
 14+ *
 15+ * @package ArticleFeedback
 16+ * @subpackage Job
 17+ */
 18+class ArticleFeedbackv5MailerJob extends Job {
 19+
 20+ /**
 21+ * Passthrough that sends the name of the class as the name of the job
 22+ *
 23+ * @param $command
 24+ * @param $title
 25+ * @param $params array
 26+ * @param int $id
 27+ */
 28+ function __construct( $title, $params, $id = 0 ) {
 29+ parent::__construct( __CLASS__, $title, $params, $id );
 30+ }
 31+
 32+ /**
 33+ * Run the job
 34+ * @return boolean success
 35+ */
 36+ function run() {
 37+ global $wgArticleFeedbackv5OversightEmails, $wgArticleFeedbackv5OversightEmailName;
 38+ global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress;
 39+
 40+ $params = $this->params;
 41+
 42+ // if the oversight email address is empty we're going to just skip all this, but return true
 43+ if ( null === $wgArticleFeedbackv5OversightEmails ) {
 44+ return true;
 45+ }
 46+
 47+ // if we don't have the right params set return false, job can't run
 48+ if ( !array_key_exists( 'user_name', $params)
 49+ || !array_key_exists( 'user_url', $params)
 50+ || !array_key_exists( 'page_name', $params)
 51+ || !array_key_exists( 'page_url', $params)
 52+ || !array_key_exists( 'permalink', $params)) {
 53+ return false;
 54+ }
 55+
 56+ // get our addresses
 57+ $to = new MailAddress( $wgArticleFeedbackv5OversightEmails, $wgArticleFeedbackv5OversightEmailName );
 58+ $from = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
 59+ $replyto = new MailAddress( $wgNoReplyAddress );
 60+
 61+ // get our text
 62+ list($subject, $body) = $this->composeMail($params['user_name'],
 63+ $params['user_url'],
 64+ $params['page_name'],
 65+ $params['page_url'],
 66+ $params['permalink']);
 67+
 68+ return UserMailer::send( $to, $from, $subject,
 69+ $body, $replyto );
 70+ }
 71+
 72+ /**
 73+ * Generate the "an oversight request has been made" email for sending
 74+ * to the mailing list
 75+ *
 76+ * @param string $requestor_name user name
 77+ * @param string $requestor_url link to user page
 78+ * @param string $page_name page title
 79+ * @param string $page_url page url
 80+ * @param string $feedback_permalink permalink url to feedback
 81+ */
 82+ protected function composeMail( $requestor_name, $requestor_url, $page_name, $page_url, $feedback_permalink ) {
 83+ global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress, $wgRequest;
 84+
 85+ // build the subject
 86+ $subject = wfMessage( 'articlefeedbackv5-email-request-oversight-subject' )->params(
 87+ $requestor_name,
 88+ $page_name )->escaped();
 89+
 90+ //text version, no need to escape since client will interpret it as plain text
 91+ $body = wfMessage( 'articlefeedbackv5-email-request-oversight-body' )
 92+ ->rawParams(
 93+ $requestor_url,
 94+ $page_url,
 95+ $feedback_permalink)
 96+ ->params(
 97+ $requestor_name,
 98+ $page_name)
 99+ ->text();
 100+
 101+ return array($subject, $body);
 102+ }
 103+
 104+}
\ No newline at end of file
Property changes on: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5MailerJob.php
___________________________________________________________________
Added: svn:keywords
1105 + Id

Follow-up revisions

RevisionCommit summaryAuthorDate
r113062bug 34090 - follow up to r110520 1. change index 2. default of null for conti...emsmith18:54, 5 March 2012
r113073bug 34090 - follow up to r111472 part 1 - change to use getDbKey, check for b...emsmith19:48, 5 March 2012
r113082bug 34090 - follow up to r111471 - changed to use text()emsmith20:42, 5 March 2012
r113083bug 34090 - follow up to rr111472 part 2 - only use log_id for orderingemsmith20:48, 5 March 2012
r113104bug 34090 - follow up to rr111472 part 3 - totally redo the continue function...emsmith23:10, 5 March 2012
r113159bug 34090 - follow up to rr111472 part 4 and follow up to r111596 (same issue...emsmith17:37, 6 March 2012
r113160bug 34090 - follow up to rr111472 part 5 plural and number format action countemsmith17:48, 6 March 2012
r113161bug 34090 - follow up to rr111472 part 6 last of lego messagesemsmith17:53, 6 March 2012
r113163bug 34090 - two additional configuration settings (help url and admin user ur...emsmith18:02, 6 March 2012
r113186Fix a few doc comment typos in r113052catrope22:17, 6 March 2012
r113193bug 34090 - followup to r113104 - only sort by timestamp (sorting by log id w...emsmith22:56, 6 March 2012
r113228bug 34090 - followup to r113160emsmith14:05, 7 March 2012
r113247bug 34090 - db issue, remove one of the sorts from the query, use the ids arr...emsmith16:52, 7 March 2012
r113269bug 34090 - followup to r113247emsmith19:01, 7 March 2012
r113273bug 34090 - add javascript level hiding on request oversight IF autohidden is...emsmith19:22, 7 March 2012
r113287bug 34090 - usernames and formatted timestamps into red lines for hidden/over...emsmith20:22, 7 March 2012
r113311bug 34090 - fixing the username bugs - apparently using the data- stuff with ...emsmith22:34, 7 March 2012
r113317bug 34090 - js and css voodoo to make the element with the red lines appear a...emsmith23:01, 7 March 2012
r113370bug 34090 - make different titles for masking appear if it's been hidden or o...emsmith16:43, 8 March 2012
r113371bug 34090 - fixes for oversighter view for hide/oversight panelsemsmith17:51, 8 March 2012
r113383bug 34090 - not entirely necessary, but keeps $2 from showing up in hiders pa...emsmith19:25, 8 March 2012
r113384bug 34090 - fix for double red line issues when hiding an oversighted post ha...emsmith19:28, 8 March 2012
r113390bug 34090 - adding translation for "automatic hider" useremsmith19:44, 8 March 2012
r113392bug 34090 - followup to r113287 - adjusted localization documentationemsmith20:03, 8 March 2012
r113393bug 34090 - followup to r113370 - adjusted localization documentationemsmith20:05, 8 March 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111211bug 34090 - Added a log namespace and log types for the Article Feedback v5 e...emsmith22:53, 10 February 2012
r111472bug 34090 - Added an additional column in the main feedback table to keep a c...emsmith19:14, 14 February 2012
r111474bug 34090 - remove a todo - take the note from the flag submission and save i...emsmith19:57, 14 February 2012
r111552bug 34090 - split activity notes into their own config for maximum length (th...emsmith16:07, 15 February 2012
r111557bug 34090 - changed structure of the link classes and ids per the following f...emsmith16:47, 15 February 2012
r111570bug 34090 - request oversight is now a counter - so you can request/unrequest...emsmith19:53, 15 February 2012
r111573bug 34090 - removed the "header" portion of the html generation from the acti...emsmith20:18, 15 February 2012
r111645bug 34090 - updated the filter count update script to get requested oversight...emsmith15:45, 16 February 2012
r112038bug 34090 - added additional counts for filters including unhidden, undeleted...emsmith20:28, 21 February 2012
r112039bug 34090 - fixed issue noted : if $feedback is false return nothing - not th...emsmith20:50, 21 February 2012
r112041bug 34090 - kill the -1 issue by never letting it get below 0emsmith21:08, 21 February 2012
r112115bug 34090 - no code changes, just fixing/adding keyword svn propertiesemsmith16:31, 22 February 2012
r112119bug 34090 - cast the naughty column so it can be signed, the greatest still k...emsmith16:57, 22 February 2012
r112142bug 34090 - toggle for atomic un/helpful changing (and elimination of an extr...emsmith20:37, 22 February 2012
r112147bug 34090 - note to self, watch the copy and paste errors...emsmith21:01, 22 February 2012
r112149bug 34090 - no upper limit, only lower limit - we can't get any worse then 0emsmith21:21, 22 February 2012
r112154bug 34090 - quick and dirty helper script to get missing documentation keysemsmith21:57, 22 February 2012
r112156bug 34090 - only send the activity header if continue < 1, make the more div ...emsmith22:14, 22 February 2012
r112161bug 34090 - fix limit and use old continue to determine if we do the headeremsmith23:15, 22 February 2012
r112218bug 34090 - make sure the name are right for hidden/unhidden logging (argh)emsmith16:44, 23 February 2012
r112225bug 34090 - unhidden and unoversight logic adjustmentsemsmith18:06, 23 February 2012
r112228bug 34090 - fix filter - needsoversight are always autohiddenemsmith19:16, 23 February 2012
r112230bug 34090 - let's try this again - needsoversight and declined will have hidd...emsmith19:38, 23 February 2012
r112232bug 34090 - hide and show shouldn't fiddle with oversight counts or declined ...emsmith19:48, 23 February 2012
r112599bug 34090 - follow up to r111211 - rename things to make them "less confusin...emsmith14:43, 28 February 2012
r112603bug 34090 - Add the logging of automated hide/show errors by the "Article Fee...emsmith15:21, 28 February 2012
r112604bug 34090 - can't believe there were no permissions checks in this - only del...emsmith15:38, 28 February 2012
r112610bug 34090 - change all sql updates to use escaping except for explicitly comm...emsmith16:22, 28 February 2012
r112611bug 34090 - take out implicit show and add returning user that hid/oversighte...emsmith17:02, 28 February 2012
r112627bug 34090 - follow up to r112599 - change to use getText since it's going int...emsmith18:53, 28 February 2012
r112825bug 34090 - insert custom attributes (sigh) for the user and formatted timest...emsmith18:14, 1 March 2012
r112830bug 34090 - follow up to r111474 - use truncate for choppingemsmith19:42, 1 March 2012

Comments

#Comment by Catrope (talk | contribs)   22:22, 6 March 2012
+ // make a title out of our user (sigh)
+ $user_page = Title::makeTitle( NS_USER, $wgUser->getName() );

There's a $wgUser->getUserPage() method for this. It also cannot fail, because of the nature of makeTitle() and because User objects with invalid names cannot exist.

+ 'page_name' => $title_object->getText(),

This should be ->getPrefixedText() so it includes the namespace prefix. All those Title accessors are kind of confusing.

Status & tagging log