01tonythomas has uploaded a new change for review. https://gerrit.wikimedia.org/r/224984
Change subject: Added Mailgun extension for Mediawiki ...................................................................... Added Mailgun extension for Mediawiki Todo: Still requires exception handling Bug: T105781 Change-Id: I12951a9397d80b2a4929afaba1e170616e44473b --- A MailgunHooks.php A composer.json A extension.json 3 files changed, 107 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Mailgun refs/changes/84/224984/1 diff --git a/MailgunHooks.php b/MailgunHooks.php new file mode 100644 index 0000000..128b6a7 --- /dev/null +++ b/MailgunHooks.php @@ -0,0 +1,76 @@ +<?php +/** + * Hooks for Mailgun extension for Mediawiki + * + * 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. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @author Tony Thomas <[email protected]> + * @license GPL-2.0 + * @ingroup Extensions +*/ +class MailgunHooks { + /** + * Function to be run on startup in $wgExtensionFunctions + */ + public static function onRegistration() { + if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { + require_once __DIR__ . '/vendor/autoload.php'; + } + + } + + /** + * Send a mail using Mailgun API + * + * @param array $headers + * @param array $to + * @param MailAddress $from + * @param $subject + * @param $body + * @return bool + */ + public static function onAlternateUserMailer( array $headers, array $to, MailAddress $from, $subject, $body ) { + global $wgMailgunAPIKey, $wgMailgunDomain; + + try { + $mailgunTransport = new \Mailgun\Mailgun( $wgMailgunAPIKey ); + } catch( Exception $e ) { + return $e->getMessage(); + } + + foreach( $to as $recip ) { + $message = $mailgunTransport->MessageBuilder(); + + $message->setFromAddress( $from ); + $message->addToRecipient( $recip ); + $message->setSubject( $subject ); + $message->setTextBody( $body ); + + foreach( $headers as $headerName => $headerValue ) { + $message->addCustomHeader( $headerName, $headerValue ); + } + + try { + $mailgunTransport->sendMessage( $wgMailgunDomain, $message->getMessage() ); + } catch( Exception $e ){ + return $e->getMessage(); + } + } + + return false; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6acf437 --- /dev/null +++ b/composer.json @@ -0,0 +1,8 @@ +{ + "name": "mediawiki/mailgun", + "require": { + "mailgun/mailgun-php": "1.7.2" + }, + "prepend-autoloader": false, + "optimize-autoloader": true +} \ No newline at end of file diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..89121d1 --- /dev/null +++ b/extension.json @@ -0,0 +1,23 @@ +{ + "name": "Mailgun", + "version": "1.0", + "author": [ + "Tony Thomas" + ], + "url": "https://www.mediawiki.org/wiki/Extension:Mailgun", + "AutoloadClasses": { + "MailgunHooks": "MailgunHooks.php" + }, + "Hooks": { + "AlternateUserMailer": [ + "MailgunHooks::onAlternateUserMailer" + ] + }, + "callback": "MailgunHooks::onRegistration", + "config": { + "MailgunAPIKey": "key-8fad6f8f77944d7d7abb9b7c66185476", + "MailgunDomain": "amritafoss.in" + }, + "manifest_version": 1 + +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/224984 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I12951a9397d80b2a4929afaba1e170616e44473b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Mailgun Gerrit-Branch: master Gerrit-Owner: 01tonythomas <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
