01tonythomas has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/172242

Change subject: Removed Wikimedia specific configuratoins from BounceHandler 
extension
......................................................................

Removed Wikimedia specific configuratoins from BounceHandler extension

As per the plan, the bouncehandler extension will get installe in all
WMF wikis, and having $wgDomainPart = 'meta.wikimedia.org' will make it
difficult later as each of them needs to get changed to $wgServerName.
It is important that VERP address from a wiki have the wiki domain as $domain
part. Now, the $domain part defaults to $wgServerName, which can be changed 
later.

Bug: 73043
Change-Id: I8bdbac798e62be527eb90781dd89636cc9290fe1
---
M BounceHandler.php
M BounceHandlerHooks.php
M includes/VerpAddressGenerator.php
M tests/ApiBounceHandlerTest.php
M tests/UnSubscribeUserTest.php
M tests/VERPEncodeDecodeTest.php
6 files changed, 25 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BounceHandler 
refs/changes/42/172242/1

diff --git a/BounceHandler.php b/BounceHandler.php
index 8b8e90f..308cdf3 100644
--- a/BounceHandler.php
+++ b/BounceHandler.php
@@ -50,15 +50,17 @@
 /**
  * VERP Configurations
  * wgVERPprefix - The prefix of the VERP address.
+ * wgVERPdomainPart - The domain part of the VERP email address, defaults to 
$wgServerName
  * wgVERPalgorithm - Algorithm to hash the return path address.Possible 
algorithms are
  * md2. md4, md5, sha1, sha224, sha256, sha384, ripemd128, ripemd160, 
whirlpool and more.
  * wgVERPsecret - The secret key to hash the return path address
+ * wgBounceHandlerUnconfirmUsers - Toggle the user un-subscribe action
  */
 $wgVERPprefix = 'wiki';
-$wgVERPdomainPart = 'meta.wikimedia.org';
+$wgVERPdomainPart = null; //set this only if you want the domain part of your 
email different from your wgServerName
 $wgVERPalgorithm = 'md5';
 $wgVERPsecret = 'MediawikiVERP';
-$wgBounceHandlerUnconfirmUsers = false; // Toggle the user un-subscribe action
+$wgBounceHandlerUnconfirmUsers = false;
 $wgVERPAcceptTime = 259200; //3 days time
 $wgBounceRecordPeriod = 604800; // 60 * 60 * 24 * 7 - 7 days bounce activity 
are considered before un-subscribing
 $wgBounceRecordLimit = 10; // If there are more than 10 bounces in the 
$wgBounceRecordPeriod, the user is un-subscribed
diff --git a/BounceHandlerHooks.php b/BounceHandlerHooks.php
index 58dd223..8139481 100644
--- a/BounceHandlerHooks.php
+++ b/BounceHandlerHooks.php
@@ -29,7 +29,7 @@
         * @return bool true
         */
        protected static function generateVerp( MailAddress $to, &$returnPath ) 
{
-               global $wgVERPprefix, $wgVERPalgorithm, $wgVERPsecret, 
$wgVERPdomainPart;
+               global $wgVERPprefix, $wgVERPalgorithm, $wgVERPsecret, 
$wgVERPdomainPart, $wgServerName;
                $user = User::newFromName( $to->name );
                if ( !$user ) {
                        return true;
@@ -40,7 +40,8 @@
                } else {
                        return true;
                }
-               $verpAddress = new VerpAddressGenerator( $wgVERPprefix, 
$wgVERPalgorithm, $wgVERPsecret, $wgVERPdomainPart );
+               $verpAddress = new VerpAddressGenerator( $wgVERPprefix,
+                       $wgVERPalgorithm, $wgVERPsecret, $wgVERPdomainPart, 
$wgServerName );
                $returnPath = $verpAddress->generateVERP( $uid );
 
                return true;
diff --git a/includes/VerpAddressGenerator.php 
b/includes/VerpAddressGenerator.php
index 22aef1c..a7dbd7d 100644
--- a/includes/VerpAddressGenerator.php
+++ b/includes/VerpAddressGenerator.php
@@ -50,16 +50,23 @@
        protected $domain;
 
        /**
+        * @var string
+        */
+       protected $serverName;
+
+       /**
         * @param string $prefix
         * @param string $algorithm
         * @param string $secretKey
         * @param string $domain
+        * @param string $serverName
         */
-       public function __construct( $prefix, $algorithm, $secretKey, $domain ) 
{
+       public function __construct( $prefix, $algorithm, $secretKey, $domain, 
$serverName ) {
                $this->prefix = $prefix;
                $this->algorithm = $algorithm;
                $this->secretKey = $secretKey;
                $this->domain = $domain;
+               $this->serverName = $serverName;
        }
 
        /**
@@ -78,7 +85,7 @@
        public function generateVERP( $uid ) {
                // Get the time in Unix timestamp to compare with seconds
                $timeNow = wfTimestamp();
-               $email_domain = $this->domain;
+               $email_domain = $this->domain ? : $this->serverName;
                // Creating the VERP address prefix as wikiId-base36( $UserID 
)-base36( $Timestamp )
                // and the generated VERP return path is of the form :
                // wikiId-base36( $UserID )-base36( $Timestamp )-hash( 
$algorithm, $key, $prefix )@$email_domain
diff --git a/tests/ApiBounceHandlerTest.php b/tests/ApiBounceHandlerTest.php
index 94da074..e46f09e 100644
--- a/tests/ApiBounceHandlerTest.php
+++ b/tests/ApiBounceHandlerTest.php
@@ -37,6 +37,7 @@
                $algorithm = 'md5';
                $secretKey = 'mySecret';
                $domain = 'testwiki.org';
+               $serverName = 'testwiki.org';
                $bounceRecordPeriod = 604800;
                $bounceRecordLimit = 3;
 
@@ -46,6 +47,7 @@
                                'wgVERPalgorithm' => $algorithm,
                                'wgVERPsecret' => $secretKey,
                                'wgVERPdomainPart' => $domain,
+                               'wgServerName' => $serverName,
                                'wgBounceHandlerUnconfirmUsers' => true,
                                'wgBounceRecordPeriod' => $bounceRecordPeriod,
                                'wgBounceRecordLimit' => $bounceRecordLimit,
diff --git a/tests/UnSubscribeUserTest.php b/tests/UnSubscribeUserTest.php
index 143ecbe..b8d6835 100644
--- a/tests/UnSubscribeUserTest.php
+++ b/tests/UnSubscribeUserTest.php
@@ -23,6 +23,7 @@
                $algorithm = 'md5';
                $secretKey = 'mySecret';
                $domain = 'testwiki.org';
+               $serverName = 'testwiki.org';
                $bounceRecordPeriod = 604800;
                $bounceRecordLimit = 3;
 
@@ -32,6 +33,7 @@
                                'wgVERPalgorithm' => $algorithm,
                                'wgVERPsecret' => $secretKey,
                                'wgVERPdomainPart' => $domain,
+                               'wgServerName' => $serverName,
                                'wgBounceHandlerUnconfirmUsers' => true,
                                'wgBounceRecordPeriod' => $bounceRecordPeriod,
                                'wgBounceRecordLimit' => $bounceRecordLimit
@@ -40,7 +42,7 @@
 
                $this->setMwGlobals( 'wgVERPAcceptTime', 259200 );
 
-               $encodeVERP = new VerpAddressGenerator( $prefix, $algorithm, 
$secretKey, $domain );
+               $encodeVERP = new VerpAddressGenerator( $prefix, $algorithm, 
$secretKey, $domain, $serverName );
                $encodedAddress = $encodeVERP->generateVERP( $uid );
 
                $emailHeaders['to'] = $encodedAddress;
diff --git a/tests/VERPEncodeDecodeTest.php b/tests/VERPEncodeDecodeTest.php
index 7b07a15..f660ef0 100644
--- a/tests/VERPEncodeDecodeTest.php
+++ b/tests/VERPEncodeDecodeTest.php
@@ -22,18 +22,20 @@
                $algorithm = 'md5';
                $secretKey = 'mySecret';
                $domain = 'testwiki.org';
+               $serverName = 'testwiki.org';
 
                $this->setMwGlobals(
                        array(
                                'wgVERPprefix' => $prefix,
                                'wgVERPalgorithm' => $algorithm,
                                'wgVERPsecret' => $secretKey,
-                               'wgVERPdomainPart' => $domain
+                               'wgVERPdomainPart' => $domain,
+                               'wgServerName' => $serverName
                        )
                );
                $this->setMwGlobals( 'wgVERPAcceptTime', 259200 );
 
-               $encodeVERP = new VerpAddressGenerator( $prefix, $algorithm, 
$secretKey, $domain );
+               $encodeVERP = new VerpAddressGenerator( $prefix, $algorithm, 
$secretKey, $domain, $serverName );
                $encodedAddress = $encodeVERP->generateVERP( $uid );
 
                $decodeVERPwithRegex = new ProcessBounceWithRegex();

-- 
To view, visit https://gerrit.wikimedia.org/r/172242
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8bdbac798e62be527eb90781dd89636cc9290fe1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BounceHandler
Gerrit-Branch: master
Gerrit-Owner: 01tonythomas <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to