Lilu has uploaded a new change for review.
https://gerrit.wikimedia.org/r/247778
Change subject: 525 Integrate BlueSpice-Notifications with Mediawiki
Echo-Extension
......................................................................
525 Integrate BlueSpice-Notifications with Mediawiki Echo-Extension
- removed Notification extension from BlueSpiceExtensions
- introduced BSNotification in BlueSpiceFoundation
- implemented EchoNotificationHandler as first NotificationHandler for
BSNotification (supports web- and email-notifications over the Echo extension)
- reworked ShoutBox, Review and ResponsibleEditors to use BSNotifications and
get rid of BsMailer and the old Notification logic
Change-Id: I63200c8cdd7aad5a647e99f091c3ecb4a3b1f8ba
---
M includes/AutoLoader.php
M includes/Core.class.php
M includes/Mailer.class.php
A includes/Notifications.class.php
A includes/notifications/EchoNotificationHandler.php
A includes/notifications/NotificationHandler.php
6 files changed, 539 insertions(+), 1 deletion(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation
refs/changes/78/247778/1
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index 99d11e9..4f50786 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -37,7 +37,7 @@
$GLOBALS['wgAutoloadClasses']['BSDebug'] = __DIR__."/Debug.php";
$GLOBALS['wgAutoloadClasses']['BsException'] = __DIR__."/Exception.class.php";
$GLOBALS['wgAutoloadClasses']['BsExtensionManager'] =
__DIR__."/ExtensionManager.class.php";
-$GLOBALS['wgAutoloadClasses']['BsMailer'] = __DIR__."/Mailer.class.php";
+$GLOBALS['wgAutoloadClasses']['BsMailer'] =
__DIR__."/Mailer.class.php";//Deprecated
$GLOBALS['wgAutoloadClasses']['BsXHRBaseResponse'] =
__DIR__."/XHRBaseResponse.class.php";
$GLOBALS['wgAutoloadClasses']['BsXHRJSONResponse'] =
__DIR__."/XHRBaseResponse.class.php";
$GLOBALS['wgAutoloadClasses']['BsXHRResponseStatus'] =
__DIR__."/XHRBaseResponse.class.php";
@@ -50,6 +50,11 @@
$GLOBALS['wgAutoloadClasses']['BsExtJSStoreParams'] =
__DIR__."/ExtJSStoreParams.php";
$GLOBALS['wgAutoloadClasses']['BsExtJSSortParam'] =
__DIR__."/ExtJSStoreParams.php";
+//notifications
+$GLOBALS['wgAutoloadClasses']['BSNotifications'] =
__DIR__."/Notifications.class.php";
+$GLOBALS['wgAutoloadClasses']['BSNotificationHandler'] =
__DIR__."/notifications/NotificationHandler.php";
+$GLOBALS['wgAutoloadClasses']['BSEchoNotificationHandler'] =
__DIR__."/notifications/EchoNotificationHandler.php";
+
//api
$GLOBALS['wgAutoloadClasses']['BSStandardAPIResponse'] =
__DIR__."/api/BSStandardAPIResponse.php";
$GLOBALS['wgAutoloadClasses']['BSApiBase'] = __DIR__."/api/BSApiBase.php";
diff --git a/includes/Core.class.php b/includes/Core.class.php
index c655d78..dc35b21 100644
--- a/includes/Core.class.php
+++ b/includes/Core.class.php
@@ -335,6 +335,10 @@
}
wfProfileOut('Performance: ' . __METHOD__ . ' - Load Settings');
+ BSNotifications::registerNotificationHandler(
+ 'BSEchoNotificationHandler'
+ );
+
wfProfileIn('Performance: ' . __METHOD__ . ' - Load and
initialize all Extensions');
BsExtensionManager::includeExtensionFiles( self::$oInstance );
wfProfileOut('Performance: ' . __METHOD__ . ' - Load and
initialize all Extensions');
@@ -355,6 +359,8 @@
$aImageExtensions = BsConfig::get( 'MW::ImageExtensions' );
$wgFileExtensions = array_merge( $aFileExtensions,
$aImageExtensions );
$wgFileExtensions = array_values( array_unique(
$wgFileExtensions ) );
+
+ BSNotifications::init();
}
/* Returns the filesystem path of the core installation
diff --git a/includes/Mailer.class.php b/includes/Mailer.class.php
index 7260f11..a19d98d 100644
--- a/includes/Mailer.class.php
+++ b/includes/Mailer.class.php
@@ -1,5 +1,6 @@
<?php
/**
+ * DEPRECATED!
* This file is part of BlueSpice for MediaWiki.
*
* @copyright Copyright (c) 2012, HalloWelt! Medienwerkstatt GmbH, All rights
reserved.
@@ -14,6 +15,7 @@
/**
* BlueSpice Mailer Component
+ * @deprecated since 2.23.2
* @package BlueSpice_Core
* @subpackage Mailer
*/
@@ -26,6 +28,7 @@
function __construct() {}
/**
+ * @deprecated since 2.23.2
* N-glton implementation for BsMailer
* @param string $name
* @param mixed $path Not used.
@@ -40,6 +43,7 @@
/**
* Sends mail(s). It makes sure that all mails sent by BlueSpice are
formatted in similar matter.
+ * @deprecated since 2.23.2
* @param mixed $vTo Either a Username, an email address or a User
object. Or an array of those.
* @param string $sSubject The plain subject. Will be prepended with
sitename.
* @param string $sMsg The plain message. Will be surrounded with
salutation and complementary close.
@@ -48,6 +52,7 @@
*/
public function send( $vTo, $sSubject, $sMsg, $oFrom = null ) {
wfProfileIn( 'BS::'.__METHOD__ );
+ wfDeprecated( __METHOD__, '2.23.2' );
$oStatus = Status::newGood(); // TODO RBV (01.03.12 12:59): Use
fatal...?
# found in mw 1.23 UserMailer.php ln 250
# Line endings need to be different on Unix and Windows due to
@@ -181,10 +186,16 @@
return $oStatus;
}
+ /*
+ * @deprecated since 2.23.2
+ */
public function getSendHTML() {
return $this->bSendHTML;
}
+ /*
+ * @deprecated since 2.23.2
+ */
public function setSendHTML( $bSendHTML ) {
$this->bSendHTML = $bSendHTML;
}
diff --git a/includes/Notifications.class.php b/includes/Notifications.class.php
new file mode 100644
index 0000000..6db05b8
--- /dev/null
+++ b/includes/Notifications.class.php
@@ -0,0 +1,224 @@
+<?php
+
+/**
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * This file is part of BlueSpice for MediaWiki
+ * For further information visit http://www.blue-spice.org
+ *
+ * @author Patric Wirth <[email protected]>
+ * @author Sebastian Ulbricht <[email protected]>
+ * @package Bluespice_Foundation
+ * @copyright Copyright (C) 2015 Hallo Welt! - Medienwerkstatt GmbH, All
rights reserved.
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or
later
+ * @filesource
+ */
+abstract class BSNotifications {
+ private static $aNotificationHandlers = array();
+
+ public static function registerNotificationHandler( $sHandler ) {
+ self::$aNotificationHandlers[] = $sHandler;
+ }
+
+ private static function getNotificationHandlerMethods( $sMethod ) {
+ $aNotificationHandlers = self::$aNotificationHandlers;
+ if ( empty( $aNotificationHandlers ) ) {
+ throw new BsException(
+ "No Notification Handler found!"
+ );
+ }
+
+ $aCallableMethods = array();
+ foreach ( $aNotificationHandlers as $sHandler ) {
+ $sCallable = "$sHandler::$sMethod";
+ if ( !is_callable( $sCallable ) ) {
+ throw new BsException(
+ "Notification Handler $sHandler does
not have a method $sMethod!"
+ );
+ }
+ $aCallableMethods[ $sHandler ] = $sMethod;
+ }
+
+ return $aCallableMethods;
+ }
+
+ public static function init() {
+ $aNotificationHandlerMethods =
self::getNotificationHandlerMethods(
+ __FUNCTION__
+ );
+
+ foreach ( $aNotificationHandlerMethods as $sHandler =>
$sCallable ) {
+ $sHandler::$sCallable();
+ }
+ }
+
+ /**
+ * @param string $sKey
+ * @param string $sLocation
+ * @param string $sLocationType
+ * @param bool $bOverride
+ *
+ * @throws BsException
+ */
+ public static function registerIcon(
+ $sKey,
+ $sLocation,
+ $sLocationType = 'path',
+ $bOverride = false
+ ) {
+ $aNotificationHandlerMethods =
self::getNotificationHandlerMethods(
+ __FUNCTION__
+ );
+
+ foreach ( $aNotificationHandlerMethods as $sHandler =>
$sCallable ) {
+ $sHandler::$sCallable(
+ $sKey,
+ $sLocation,
+ $sLocationType,
+ $bOverride
+ );
+ }
+ }
+
+ /**
+ * Registers a new notification category.
+ *
+ * @param string $sKey
+ * @param int $iPriority
+ * @param array $aNoDismiss
+ * @param string $sTooltipMsgKey
+ * @param array $aUserGroups
+ * @param array $aActiveDefaultUserOptions An array which holds a list
of all notification types that should be
+ * active on default (opt-out)
in the user options. At the moment the
+ * values 'web' and 'email'
are supported. In most cases this should not be
+ * set and opt-in should be
preferred.
+ *
+ * @throws BsException
+ */
+ public static function registerNotificationCategory(
+ $sKey,
+ $iPriority = 10,
+ $aNoDismiss = null,
+ $sTooltipMsgKey = null,
+ $aUserGroups = null,
+ $aActiveDefaultUserOptions = null
+ ) {
+ $aNotificationHandlerMethods =
self::getNotificationHandlerMethods(
+ __FUNCTION__
+ );
+
+ foreach ( $aNotificationHandlerMethods as $sHandler =>
$sCallable ) {
+ $sHandler::$sCallable(
+ $sKey,
+ $iPriority,
+ $aNoDismiss,
+ $sTooltipMsgKey,
+ $aUserGroups,
+ $aActiveDefaultUserOptions
+ );
+ }
+ }
+
+ /**
+ * @param $sKey
+ * @param $sCategory
+ * @param $sTitleMsgKey
+ * @param $aTitleParams
+ * @param $sSubjectMsgKey
+ * @param $aSubjectParams
+ * @param $sBodyMsgKey
+ * @param $aBodyParams
+ * @param $aExtraParams
+ *
+ * @throws BsException
+ */
+ public static function registerNotification(
+ $sKey,
+ $sCategory,
+ $sTitleMsgKey,
+ $aTitleParams,
+ $sSubjectMsgKey,
+ $aSubjectParams,
+ $sBodyMsgKey,
+ $aBodyParams,
+ $aExtraParams = null
+ ) {
+ $aNotificationHandlerMethods =
self::getNotificationHandlerMethods(
+ __FUNCTION__
+ );
+
+ foreach ( $aNotificationHandlerMethods as $sHandler =>
$sCallable ) {
+ $sHandler::$sCallable(
+ $sKey,
+ $sCategory,
+ $sTitleMsgKey,
+ $aTitleParams,
+ $sSubjectMsgKey,
+ $aSubjectParams,
+ $sBodyMsgKey,
+ $aBodyParams,
+ $aExtraParams
+ );
+ }
+ }
+
+ /**
+ * @param $sKey
+ *
+ * @throws BsException
+ */
+ public static function unregisterNotification(
+ $sKey
+ ) {
+ $aNotificationHandlerMethods =
self::getNotificationHandlerMethods(
+ __FUNCTION__
+ );
+
+ foreach ( $aNotificationHandlerMethods as $sHandler =>
$sCallable ) {
+ $sHandler::$sCallable(
+ $sKey
+ );
+ }
+ }
+
+ /**
+ * @param string $sKey
+ * @param User $oAgent
+ * @param Title $oTitle
+ * @param array $aExtraParams
+ *
+ * @throws BsException
+ */
+ public static function notify(
+ $sKey,
+ $oAgent = null,
+ $oTitle = null,
+ $aExtraParams = null
+ ) {
+ $aNotificationHandlerMethods =
self::getNotificationHandlerMethods(
+ __FUNCTION__
+ );
+
+ foreach ( $aNotificationHandlerMethods as $sHandler =>
$sCallable ) {
+ $sHandler::$sCallable(
+ $sKey,
+ $oAgent,
+ $oTitle,
+ $aExtraParams
+ );
+ }
+ }
+}
\ No newline at end of file
diff --git a/includes/notifications/EchoNotificationHandler.php
b/includes/notifications/EchoNotificationHandler.php
new file mode 100644
index 0000000..5568604
--- /dev/null
+++ b/includes/notifications/EchoNotificationHandler.php
@@ -0,0 +1,177 @@
+<?php
+
+/**
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * This file is part of BlueSpice for MediaWiki
+ * For further information visit http://www.blue-spice.org
+ *
+ * @author Patric Wirth <[email protected]>
+ * @package Bluespice_Foundation
+ * @copyright Copyright (C) 2015 Hallo Welt! - Medienwerkstatt GmbH, All
rights reserved.
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or
later
+ * @filesource
+ */
+class BSEchoNotificationHandler extends BSNotificationHandler {
+
+ /**
+ * @param string $sKey
+ * @param string $sLocation
+ * @param string $sLocationType
+ * @param bool $bOverride
+ */
+ public static function registerIcon( $sKey, $sLocation, $sLocationType
= 'path', $bOverride = false ) {
+ global $wgEchoNotificationIcons;
+
+ // Don't override the icon definition until the caller
explicitly wants to override it.
+ if ( is_array( $wgEchoNotificationIcons[ $sKey ] ) &&
!$bOverride ) {
+ return;
+ }
+
+ // Make sure we have a proper location type
+ if ( $sLocationType != 'path' ) {
+ $sLocationType = 'url';
+ }
+
+ $wgEchoNotificationIcons[ $sKey ] = array(
+ $sLocationType => $sLocation
+ );
+ }
+
+ /**
+ * @param string $sKey
+ * @param int $iPriority
+ * @param array $aNoDismiss
+ * @param string $sTooltipMsgKey
+ * @param array $aUserGroups
+ * @param array $aActiveDefaultUserOptions
+ */
+ public static function registerNotificationCategory(
+ $sKey,
+ $iPriority = 10,
+ $aNoDismiss = null,
+ $sTooltipMsgKey = null,
+ $aUserGroups = null,
+ $aActiveDefaultUserOptions = null
+ ) {
+ global $wgEchoNotificationCategories, $wgDefaultUserOptions;
+
+ $aCategory = array(
+ 'priority' => $iPriority
+ );
+
+ if ( $aNoDismiss && is_array( $aNoDismiss ) ) {
+ $aCategory[ 'no-dismiss' ] = $aNoDismiss;
+ }
+
+ if ( $sTooltipMsgKey ) {
+ $aCategory[ 'tooltip' ] = $sTooltipMsgKey;
+ }
+
+ if ( $aUserGroups && is_array( $aUserGroups ) ) {
+ $aCategory[ 'usergroups' ] = $aUserGroups;
+ }
+
+ $wgEchoNotificationCategories[ $sKey ] = $aCategory;
+
+ if ( $aActiveDefaultUserOptions && is_array(
$aActiveDefaultUserOptions ) ) {
+ foreach ( $aActiveDefaultUserOptions as
$sNotificationType ) {
+ $wgDefaultUserOptions[
"echo-subscriptions-{$sNotificationType}-{$sKey}" ] = true;
+ }
+ }
+ }
+
+ /**
+ * @param $sKey
+ * @param $sCategory
+ * @param $sSummaryMsgKey
+ * @param $aSummaryParams
+ * @param $sEmailSubjectMsgKey
+ * @param $aEmailSubjectParams
+ * @param $sEmailBodyMsgKey
+ * @param $aEmailBodyParams
+ * @param $aExtraParams
+ */
+ public static function registerNotification(
+ $sKey,
+ $sCategory,
+ $sSummaryMsgKey,
+ $aSummaryParams,
+ $sEmailSubjectMsgKey,
+ $aEmailSubjectParams,
+ $sEmailBodyMsgKey,
+ $aEmailBodyParams,
+ $aExtraParams = null
+ ) {
+ global $wgEchoNotifications;
+
+ if ( !is_array( $aExtraParams ) ) {
+ $aExtraParams = array();
+ }
+
+ $wgEchoNotifications[ $sKey ] = $aExtraParams + array(
+ 'category' => $sCategory,
+ 'title-message' => $sSummaryMsgKey,
+ 'title-params' => $aSummaryParams,
+ 'email-subject-message' => $sEmailSubjectMsgKey,
+ 'email-subject-params' => $aEmailSubjectParams,
+ 'email-body-batch-message' => $sEmailBodyMsgKey,
+ 'email-body-batch-params' => $aEmailBodyParams
+ );
+ }
+
+ /**
+ * @param $sKey
+ */
+ public static function unregisterNotification( $sKey ) {
+ global $wgEchoNotifications;
+ unset( $wgEchoNotifications[ $sKey ] );
+ }
+
+ /**
+ * @param string $sKey
+ * @param User $oAgent
+ * @param Title $oTitle
+ * @param array $aExtraParams
+ *
+ * @throws MWException
+ * @throws ReadOnlyError
+ */
+ public static function notify(
+ $sKey,
+ $oAgent = null,
+ $oTitle = null,
+ $aExtraParams = null
+ ) {
+ $aNotification = array(
+ 'type' => $sKey
+ );
+
+ if ( $oAgent ) {
+ $aNotification[ 'agent' ] = $oAgent;
+ }
+
+ if ( $oTitle ) {
+ $aNotification[ 'title' ] = $oTitle;
+ }
+
+ if ( $aExtraParams && is_array( $aExtraParams ) ) {
+ $aNotification[ 'extra' ] = $aExtraParams;
+ }
+
+ EchoEvent::create( $aNotification );
+ }
+}
\ No newline at end of file
diff --git a/includes/notifications/NotificationHandler.php
b/includes/notifications/NotificationHandler.php
new file mode 100644
index 0000000..b375bb3
--- /dev/null
+++ b/includes/notifications/NotificationHandler.php
@@ -0,0 +1,115 @@
+<?php
+
+/**
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * This file is part of BlueSpice for MediaWiki
+ * For further information visit http://www.blue-spice.org
+ *
+ * @author Patric Wirth <[email protected]>
+ * @package Bluespice_Foundation
+ * @copyright Copyright (C) 2015 Hallo Welt! - Medienwerkstatt GmbH, All
rights reserved.
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or
later
+ * @filesource
+ */
+interface BSNotificationHandlerInterface {
+ public static function init();
+
+ public static function registerIcon(
+ $sKey,
+ $sLocation,
+ $sLocationType,
+ $bOverride
+ );
+
+ public static function registerNotificationCategory(
+ $sKey,
+ $iPriority,
+ $aNoDismiss,
+ $sTooltipMsgKey,
+ $aUserGroups,
+ $aActiveDefaultUserOptions
+ );
+
+ public static function registerNotification(
+ $sKey,
+ $sCategory,
+ $sSummaryMsgKey,
+ $aSummaryParams,
+ $sEmailSubjectMsgKey,
+ $aEmailSubjectParams,
+ $sEmailBodyMsgKey,
+ $aEmailBodyParams,
+ $aExtraParams
+ );
+
+ public static function unregisterNotification( $sKey );
+
+ public static function notify(
+ $sKey,
+ $oAgent,
+ $oTitle,
+ $aExtraParams
+ );
+}
+
+abstract class BSNotificationHandler implements BSNotificationHandlerInterface
{
+ public static function init() {
+ return true;
+ }
+
+ public static function registerIcon(
+ $sKey,
+ $sLocation,
+ $sLocationType = 'path',
+ $bOverride = false
+ ) {
+ }
+
+ public static function registerNotificationCategory(
+ $sKey,
+ $iPriority = 10,
+ $aNoDismiss = null,
+ $sTooltipMsgKey = null,
+ $aUserGroups = null,
+ $aActiveDefaultUserOptions = null
+ ) {
+ }
+
+ public static function registerNotification(
+ $sKey,
+ $sCategory,
+ $sSummaryMsgKey,
+ $aSummaryParams,
+ $sEmailSubjectMsgKey,
+ $aEmailSubjectParams,
+ $sEmailBodyMsgKey,
+ $aEmailBodyParams,
+ $aExtraParams
+ ) {
+ }
+
+ public static function unregisterNotification( $sKey ) {
+ }
+
+ public static function notify(
+ $sKey,
+ $oAgent = null,
+ $oTitle = null,
+ $aExtraParams = null
+ ) {
+ }
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/247778
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I63200c8cdd7aad5a647e99f091c3ecb4a3b1f8ba
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Lilu <[email protected]>
Gerrit-Reviewer: Pwirth <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits