https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114128
Revision: 114128
Author: amire80
Date: 2012-03-19 11:30:08 +0000 (Mon, 19 Mar 2012)
Log Message:
-----------
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
trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php
trunk/extensions/TranslationNotifications/TranslationNotifications.php
Added Paths:
-----------
trunk/extensions/TranslationNotifications/TranslationNotificationsHooks.php
Modified: trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php
===================================================================
--- trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php
2012-03-19 11:17:27 UTC (rev 114127)
+++ trunk/extensions/TranslationNotifications/SpecialNotifyTranslators.php
2012-03-19 11:30:08 UTC (rev 114128)
@@ -17,11 +17,11 @@
*/
class SpecialNotifyTranslators extends SpecialPage {
- private static $right = 'translate-manage';
- private static $notificationText = '';
- private static $translatablePageTitle = '';
- private static $deadlineDate = '';
- private static $priority = '';
+ public static $right = 'translate-manage';
+ public static $notificationText = '';
+ public static $translatablePageTitle = '';
+ public static $deadlineDate = '';
+ public static $priority = '';
public function __construct() {
parent::__construct( 'NotifyTranslators' );
@@ -35,7 +35,7 @@
throw new PermissionsError( self::$right );
}
- $htmlFormDataModel = $this->getDataModel();
+ $htmlFormDataModel = $this->getFormFields();
if ( !is_array( $htmlFormDataModel ) ) {
$wgOut->addWikiMsg( $htmlFormDataModel );
@@ -43,7 +43,7 @@
}
$context = $this->getContext();
- $htmlForm = new HtmlForm( $this->getDataModel(), $context,
'translationnotifications' );
+ $htmlForm = new HtmlForm( $this->getFormFields(), $context,
'translationnotifications' );
$htmlForm->setId( 'notifytranslators-form' );
$htmlForm->setSubmitText( $context->msg(
'translationnotifications-send-notification-button' )->text() );
$htmlForm->setSubmitID(
'translationnotifications-send-notification-button' );
@@ -58,7 +58,7 @@
*
* @return array or string with an error message key in case of error
*/
- private function getDataModel() {
+ private function getFormFields() {
// Translatable pages dropdown
$translatablePagesIDs =
TranslatablePage::getTranslatablePages();
@@ -71,7 +71,9 @@
$translatablePagesOptions[Title::newFromID(
$translatablePagesID )->getText()] = $translatablePagesID;
}
- $m['TranslatablePage'] = array(
+ $formFields = array();
+
+ $formFields['TranslatablePage'] = array(
'type' => 'select',
'label-message' => array(
'translationnotifications-translatablepage-title' ),
'options' => $translatablePagesOptions,
@@ -79,7 +81,7 @@
);
// Languages to notify input box
- $m['LanguagesToNotify'] = array(
+ $formFields['LanguagesToNotify'] = array(
'type' => 'text',
'rows' => 20,
'cols' => 80,
@@ -96,7 +98,7 @@
$priorityOptions[$priorityMessage] = $priority;
}
- $m['Priority'] = array(
+ $formFields['Priority'] = array(
'type' => 'select',
'label-message' => array(
'translationnotifications-priority' ),
'options' => $priorityOptions,
@@ -104,21 +106,21 @@
);
// Deadline date input box with datepicker
- $m['DeadlineDate'] = array(
+ $formFields['DeadlineDate'] = array(
'type' => 'text',
'size' => 20,
'label-message' =>
'translationnotifications-deadline-label',
);
// Custom text
- $m['NotificationText'] = array(
+ $formFields['NotificationText'] = array(
'type' => 'textarea',
'rows' => 20,
'cols' => 80,
'label-message' => 'emailmessage',
);
- return $m;
+ return $formFields;
}
/**
@@ -127,6 +129,8 @@
* TODO: document
*/
public function submitNotifyTranslatorsForm( $formData, $form ) {
+ global $wgUser;
+
self::$translatablePageTitle = Title::newFromID(
$formData['TranslatablePage'] )->getText();
self::$notificationText = $formData['NotificationText'];
self::$priority = $formData['Priority'];
@@ -148,10 +152,31 @@
'DISTINCT'
);
+ $sentSuccess = 0;
+ $sentFail = 0;
foreach ( $translators as $row ) {
- $this->sendTranslationNotificationEmail( $row->up_user
);
+ $status = $this->sendTranslationNotificationEmail(
$row->up_user );
+ if ( $status->isGood() ) {
+ $sentSuccess++;
+ } else {
+ $sentFail++;
+ }
}
+ $logger = new LogPage( 'notifytranslators' );
+ $logParams = array(
+ $formData['LanguagesToNotify'],
+ $sentSuccess,
+ $sentFail,
+ );
+ $logger->addEntry(
+ 'sent',
+ Title::newFromText( self::$translatablePageTitle ),
+ '', // No comments
+ $logParams,
+ $wgUser
+ );
+
self::$translatablePageTitle = '';
self::$notificationText = '';
self::$deadlineDate = '';
Modified:
trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php
===================================================================
--- trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php
2012-03-19 11:17:27 UTC (rev 114127)
+++ trunk/extensions/TranslationNotifications/TranslationNotifications.i18n.php
2012-03-19 11:30:08 UTC (rev 114128)
@@ -68,6 +68,7 @@
{{SITENAME}} staff',
'translationnotifications-email-priority' => 'The priority of this page
is $1.',
'translationnotifications-email-deadline' => 'The deadline for
translating this page is $1.',
+ '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',
);
/** Message documentation (Message documentation)
@@ -125,6 +126,15 @@
* $7 - A custom message that can be added by the notification sender.",
'translationnotifications-email-priority' => 'Used in
{{msg-mw|translationnotifications-email-body}}',
'translationnotifications-email-deadline' => 'Used in
{{msg-mw|translationnotifications-email-body}}',
+ 'logentry-translationnotifications-sent' => '{{logentry}}
+* $1 - username
+* $2 - username for gender
+* $3 - translatable page title
+* $4 - languages list
+* $5 - deadline
+* $6 - priority
+* $7 - number of recipients to whom the notification was sent successfully
+* $8 - number of recipients to whom sending the notification failed',
);
/** Ṫuroyo (Ṫuroyo)
Modified: trunk/extensions/TranslationNotifications/TranslationNotifications.php
===================================================================
--- trunk/extensions/TranslationNotifications/TranslationNotifications.php
2012-03-19 11:17:27 UTC (rev 114127)
+++ trunk/extensions/TranslationNotifications/TranslationNotifications.php
2012-03-19 11:30:08 UTC (rev 114128)
@@ -32,12 +32,23 @@
$wgExtensionMessagesFiles['TranslationNotificationsAlias'] =
"$dir/TranslationNotifications.alias.php";
$wgAutoloadClasses['SpecialTranslatorSignup'] =
"$dir/SpecialTranslatorSignup.php";
$wgAutoloadClasses['SpecialNotifyTranslators'] =
"$dir/SpecialNotifyTranslators.php";
+$wgAutoloadClasses['TranslationNotificationsHooks'] =
"$dir/TranslationNotificationsHooks.php";
$resourcePaths = array(
'localBasePath' => dirname( __FILE__ ),
'remoteExtPath' => 'TranslationNotifications'
);
+// For language list autocompletion
+$wgResourceModules['ext.translate.special.pagetranslation'] = array(
+ 'scripts' =>
'../Translate/resources/ext.translate.special.pagetranslation.js',
+ 'styles' =>
'../Translate/resources/ext.translate.special.pagetranslation.css',
+ 'dependencies' => array(
+ 'jquery.ui.autocomplete',
+ ),
+ 'position' => 'top',
+) + $resourcePaths;
+
$wgResourceModules['ext.translationnotifications.notifytranslators'] = array(
'scripts' =>
'resources/ext.translationnotifications.notifytranslators.js',
'dependencies' => array(
@@ -52,3 +63,6 @@
'feed' => false,
'no' => true,
);
+
+$wgLogTypes[] = 'notifytranslators';
+$wgLogActionsHandlers['notifytranslators/sent'] =
'TranslationNotificationsHooks::formatTranslationNotificationLogEntry';
Added:
trunk/extensions/TranslationNotifications/TranslationNotificationsHooks.php
===================================================================
--- trunk/extensions/TranslationNotifications/TranslationNotificationsHooks.php
(rev 0)
+++ trunk/extensions/TranslationNotifications/TranslationNotificationsHooks.php
2012-03-19 11:30:08 UTC (rev 114128)
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Some hooks for TranslationNotifications extension.
+ *
+ * @file
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
2.0 or later
+ */
+
+/**
+ * Some hooks for TranslationNotifications extension.
+ */
+class TranslationNotificationsHooks {
+ public static function formatTranslationNotificationLogEntry( $type,
$action, $title, $forUI, $params ) {
+ global $wgLang, $wgContLang;
+
+ $language = $forUI === null ? $wgContLang : $wgLang;
+
+ $notifiedLanguages = $params[0];
+ $sentSuccess = $params[1];
+ $sentFail = $params[2];
+
+ $link = $forUI ?
+ Linker::link( $title, null, array(), array( 'oldid' =>
$params[0] ) ) :
+ $title->getPrefixedText();
+ return wfMessage( 'logentry-translationnotifications-sent'
)->params(
+ '', // User link in the new system
+ '#', // User name for gender in the new system
+ Message::rawParam( $link ),
+ $notifiedLanguages,
+ SpecialNotifyTranslators::$deadlineDate,
+ SpecialNotifyTranslators::$priority,
+ $sentSuccess,
+ $sentFail
+ )->inLanguage( $language )->text();
+ }
+}
Property changes on:
trunk/extensions/TranslationNotifications/TranslationNotificationsHooks.php
___________________________________________________________________
Added: svn:eol-style
+ native
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs