r114128 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114127‎ | r114128 | r114129 >
Date:11:30, 19 March 2012
Author:amire80
Status:resolved (Comments)
Tags:i18nreview 
Comment:
Added TranslationNotificationsHooks and a callback for logging.
Added very basic logging.
Renamed form fields variables and function name to something more meaningful.
Added loading of autocomplete module.
Modified paths:
  • /trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php (modified) (history)
  • /trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php (modified) (history)
  • /trunk/extensions/TranslationNotifications/TranslationNotifications.php (modified) (history)
  • /trunk/extensions/TranslationNotifications/TranslationNotificationsHooks.php (added) (history)

Diff [purge]

Index: trunk/extensions/TranslationNotifications/TranslationNotificationsHooks.php
@@ -0,0 +1,38 @@
 2+<?php
 3+/**
 4+ * Some hooks for TranslationNotifications extension.
 5+ *
 6+ * @file
 7+ * @author Amir E. Aharoni
 8+ * @copyright Copyright © 2012, Amir E. Aharoni
 9+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 10+ */
 11+
 12+/**
 13+ * Some hooks for TranslationNotifications extension.
 14+ */
 15+class TranslationNotificationsHooks {
 16+ public static function formatTranslationNotificationLogEntry( $type, $action, $title, $forUI, $params ) {
 17+ global $wgLang, $wgContLang;
 18+
 19+ $language = $forUI === null ? $wgContLang : $wgLang;
 20+
 21+ $notifiedLanguages = $params[0];
 22+ $sentSuccess = $params[1];
 23+ $sentFail = $params[2];
 24+
 25+ $link = $forUI ?
 26+ Linker::link( $title, null, array(), array( 'oldid' => $params[0] ) ) :
 27+ $title->getPrefixedText();
 28+ return wfMessage( 'logentry-translationnotifications-sent' )->params(
 29+ '', // User link in the new system
 30+ '#', // User name for gender in the new system
 31+ Message::rawParam( $link ),
 32+ $notifiedLanguages,
 33+ SpecialNotifyTranslators::$deadlineDate,
 34+ SpecialNotifyTranslators::$priority,
 35+ $sentSuccess,
 36+ $sentFail
 37+ )->inLanguage( $language )->text();
 38+ }
 39+}
Property changes on: trunk/extensions/TranslationNotifications/TranslationNotificationsHooks.php
___________________________________________________________________
Added: svn:eol-style
140 + native
Index: trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php
@@ -17,11 +17,11 @@
1818 */
1919
2020 class SpecialNotifyTranslators extends SpecialPage {
21 - private static $right = 'translate-manage';
22 - private static $notificationText = '';
23 - private static $translatablePageTitle = '';
24 - private static $deadlineDate = '';
25 - private static $priority = '';
 21+ public static $right = 'translate-manage';
 22+ public static $notificationText = '';
 23+ public static $translatablePageTitle = '';
 24+ public static $deadlineDate = '';
 25+ public static $priority = '';
2626
2727 public function __construct() {
2828 parent::__construct( 'NotifyTranslators' );
@@ -35,7 +35,7 @@
3636 throw new PermissionsError( self::$right );
3737 }
3838
39 - $htmlFormDataModel = $this->getDataModel();
 39+ $htmlFormDataModel = $this->getFormFields();
4040
4141 if ( !is_array( $htmlFormDataModel ) ) {
4242 $wgOut->addWikiMsg( $htmlFormDataModel );
@@ -43,7 +43,7 @@
4444 }
4545
4646 $context = $this->getContext();
47 - $htmlForm = new HtmlForm( $this->getDataModel(), $context, 'translationnotifications' );
 47+ $htmlForm = new HtmlForm( $this->getFormFields(), $context, 'translationnotifications' );
4848 $htmlForm->setId( 'notifytranslators-form' );
4949 $htmlForm->setSubmitText( $context->msg( 'translationnotifications-send-notification-button' )->text() );
5050 $htmlForm->setSubmitID( 'translationnotifications-send-notification-button' );
@@ -58,7 +58,7 @@
5959 *
6060 * @return array or string with an error message key in case of error
6161 */
62 - private function getDataModel() {
 62+ private function getFormFields() {
6363
6464 // Translatable pages dropdown
6565 $translatablePagesIDs = TranslatablePage::getTranslatablePages();
@@ -71,7 +71,9 @@
7272 $translatablePagesOptions[Title::newFromID( $translatablePagesID )->getText()] = $translatablePagesID;
7373 }
7474
75 - $m['TranslatablePage'] = array(
 75+ $formFields = array();
 76+
 77+ $formFields['TranslatablePage'] = array(
7678 'type' => 'select',
7779 'label-message' => array( 'translationnotifications-translatablepage-title' ),
7880 'options' => $translatablePagesOptions,
@@ -79,7 +81,7 @@
8082 );
8183
8284 // Languages to notify input box
83 - $m['LanguagesToNotify'] = array(
 85+ $formFields['LanguagesToNotify'] = array(
8486 'type' => 'text',
8587 'rows' => 20,
8688 'cols' => 80,
@@ -96,7 +98,7 @@
9799 $priorityOptions[$priorityMessage] = $priority;
98100 }
99101
100 - $m['Priority'] = array(
 102+ $formFields['Priority'] = array(
101103 'type' => 'select',
102104 'label-message' => array( 'translationnotifications-priority' ),
103105 'options' => $priorityOptions,
@@ -104,21 +106,21 @@
105107 );
106108
107109 // Deadline date input box with datepicker
108 - $m['DeadlineDate'] = array(
 110+ $formFields['DeadlineDate'] = array(
109111 'type' => 'text',
110112 'size' => 20,
111113 'label-message' => 'translationnotifications-deadline-label',
112114 );
113115
114116 // Custom text
115 - $m['NotificationText'] = array(
 117+ $formFields['NotificationText'] = array(
116118 'type' => 'textarea',
117119 'rows' => 20,
118120 'cols' => 80,
119121 'label-message' => 'emailmessage',
120122 );
121123
122 - return $m;
 124+ return $formFields;
123125 }
124126
125127 /**
@@ -127,6 +129,8 @@
128130 * TODO: document
129131 */
130132 public function submitNotifyTranslatorsForm( $formData, $form ) {
 133+ global $wgUser;
 134+
131135 self::$translatablePageTitle = Title::newFromID( $formData['TranslatablePage'] )->getText();
132136 self::$notificationText = $formData['NotificationText'];
133137 self::$priority = $formData['Priority'];
@@ -148,10 +152,31 @@
149153 'DISTINCT'
150154 );
151155
 156+ $sentSuccess = 0;
 157+ $sentFail = 0;
152158 foreach ( $translators as $row ) {
153 - $this->sendTranslationNotificationEmail( $row->up_user );
 159+ $status = $this->sendTranslationNotificationEmail( $row->up_user );
 160+ if ( $status->isGood() ) {
 161+ $sentSuccess++;
 162+ } else {
 163+ $sentFail++;
 164+ }
154165 }
155166
 167+ $logger = new LogPage( 'notifytranslators' );
 168+ $logParams = array(
 169+ $formData['LanguagesToNotify'],
 170+ $sentSuccess,
 171+ $sentFail,
 172+ );
 173+ $logger->addEntry(
 174+ 'sent',
 175+ Title::newFromText( self::$translatablePageTitle ),
 176+ '', // No comments
 177+ $logParams,
 178+ $wgUser
 179+ );
 180+
156181 self::$translatablePageTitle = '';
157182 self::$notificationText = '';
158183 self::$deadlineDate = '';
Index: trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php
@@ -68,6 +68,7 @@
6969 {{SITENAME}} staff',
7070 'translationnotifications-email-priority' => 'The priority of this page is $1.',
7171 'translationnotifications-email-deadline' => 'The deadline for translating this page is $1.',
 72+ 'logentry-translationnotifications-sent' => '$1 {{GENDER:$2|sent}} a notification about translating page $3 to languages $4 with deadline $5, with $6 priority, to {{PLURAL:$7|one recipient|$7 recipients}} successfully, to {{PLURAL:$8|one recipient|$8 recipients}} unsuccessfully',
7273 );
7374
7475 /** Message documentation (Message documentation)
@@ -125,6 +126,15 @@
126127 * $7 - A custom message that can be added by the notification sender.",
127128 'translationnotifications-email-priority' => 'Used in {{msg-mw|translationnotifications-email-body}}',
128129 'translationnotifications-email-deadline' => 'Used in {{msg-mw|translationnotifications-email-body}}',
 130+ 'logentry-translationnotifications-sent' => '{{logentry}}
 131+* $1 - username
 132+* $2 - username for gender
 133+* $3 - translatable page title
 134+* $4 - languages list
 135+* $5 - deadline
 136+* $6 - priority
 137+* $7 - number of recipients to whom the notification was sent successfully
 138+* $8 - number of recipients to whom sending the notification failed',
129139 );
130140
131141 /** Ṫuroyo (Ṫuroyo)
Index: trunk/extensions/TranslationNotifications/TranslationNotifications.php
@@ -32,12 +32,23 @@
3333 $wgExtensionMessagesFiles['TranslationNotificationsAlias'] = "$dir/TranslationNotifications.alias.php";
3434 $wgAutoloadClasses['SpecialTranslatorSignup'] = "$dir/SpecialTranslatorSignup.php";
3535 $wgAutoloadClasses['SpecialNotifyTranslators'] = "$dir/SpecialNotifyTranslators.php";
 36+$wgAutoloadClasses['TranslationNotificationsHooks'] = "$dir/TranslationNotificationsHooks.php";
3637
3738 $resourcePaths = array(
3839 'localBasePath' => dirname( __FILE__ ),
3940 'remoteExtPath' => 'TranslationNotifications'
4041 );
4142
 43+// For language list autocompletion
 44+$wgResourceModules['ext.translate.special.pagetranslation'] = array(
 45+ 'scripts' => '../Translate/resources/ext.translate.special.pagetranslation.js',
 46+ 'styles' => '../Translate/resources/ext.translate.special.pagetranslation.css',
 47+ 'dependencies' => array(
 48+ 'jquery.ui.autocomplete',
 49+ ),
 50+ 'position' => 'top',
 51+) + $resourcePaths;
 52+
4253 $wgResourceModules['ext.translationnotifications.notifytranslators'] = array(
4354 'scripts' => 'resources/ext.translationnotifications.notifytranslators.js',
4455 'dependencies' => array(
@@ -52,3 +63,6 @@
5364 'feed' => false,
5465 'no' => true,
5566 );
 67+
 68+$wgLogTypes[] = 'notifytranslators';
 69+$wgLogActionsHandlers['notifytranslators/sent'] = 'TranslationNotificationsHooks::formatTranslationNotificationLogEntry';

Follow-up revisions

RevisionCommit summaryAuthorDate
r114251Using the refactored multiselectautocomplete module.amire8010:59, 20 March 2012

Comments

#Comment by Nikerabbit (talk | contribs)   12:07, 19 March 2012

Why static variables?

#Comment by Amire80 (talk | contribs)   11:05, 20 March 2012

Because they are not changed and they are used from the hooks class. Or is it a bad practice and they should be regular members with accessors etc.?

#Comment by 😂 (talk | contribs)   03:10, 21 March 2012

Public static variables are just global variables in disguise--regular members with accessors is much better.

#Comment by Santhosh.thottingal (talk | contribs)   12:40, 19 March 2012

Commit missed ext.translate.special.pagetranslation.js and ext.translate.special.pagetranslation.css

#Comment by Amire80 (talk | contribs)   11:04, 20 March 2012

Addressed in r114251.

Status & tagging log