jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/340274 )

Change subject: Initial checkin of version 1.8 of the EmailDiff extension
......................................................................


Initial checkin of version 1.8 of the EmailDiff extension

Change-Id: I6131ac952819d45c2ab05f5ad3b797f711a5d833
---
M EmailDiff_body.php
M README
M extension.json
3 files changed, 108 insertions(+), 17 deletions(-)

Approvals:
  Umherirrender: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/EmailDiff_body.php b/EmailDiff_body.php
index f4e11ce..560409f 100644
--- a/EmailDiff_body.php
+++ b/EmailDiff_body.php
@@ -8,20 +8,22 @@
  * @author Greg Sabino Mullane <g...@endpoint.com>
  * @link http://www.mediawiki.org/wiki/Extension:EmailDiff Documentation
  *
- * @copyright Copyright © 2015-2016, Greg Sabino Mullane
+ * @copyright Copyright © 2015-2017, Greg Sabino Mullane
  * @license The MIT License  http://opensource.org/licenses/mit-license.php
  */
+
 class EmailDiff {
+
        static private $emaildiff_text, $emaildiff_subject_original;
 
        static private $emaildiff_hasdiff = false;
 
        /**
-        * SendPersonalizedNotificationEmail hook
+        * SendNotificationEmail hook
         *
         * Allows adding text diff to the body of the outgoing email
         *
-        * @param User $watchingUser current user
+        * @param User $watchingUser current user (null if impersonal)
         * @param integer $oldid the old revision id
         * @param Title $title current article title
         * @param string $header Additional headers - not used by this extension
@@ -29,7 +31,7 @@
         * @param string $body Actual email body to be sent
         * @return bool
         */
-       public static function SendPersonalizedNotificationEmailDiff( 
$watchingUser, $oldid, $title, &$header, &$subject, &$body ) {
+       public static function SendNotificationEmailDiff( $watchingUser, 
$oldid, $title, &$header, &$subject, &$body ) {
                global $wgEmailDiffCommand, $wgEmailDiffSubjectSuffix;
 
                // Store the original subject line the first time we are called
@@ -42,7 +44,8 @@
 
                // Only show diffs if the user has set in in their preferences
                // This will appear in the "Email options" section
-               if ( $watchingUser->getOption( 'enotifshowdiff' ) ) {
+               // watchingUser can be null if this is called via sendImpersonal
+               if ( $watchingUser === null || $watchingUser->getOption( 
'enotifshowdiff' ) ) {
 
                        // The goal is to only generate the diff once, no 
matter how many users we are emailing
                        if ( self::$emaildiff_text === null ) {
@@ -66,7 +69,7 @@
                                                // Put the new page text into a 
temporary file:
                                                $new_file = tempnam( $tempdir, 
'mediawikiemaildiffnew' );
                                                $fh = fopen( $new_file, 'w' ) 
or die( "Could not open file $new_file" );
-                                               fwrite( $fh, "$newtext\n" );
+                                               fputs( $fh, "$newtext\n" );
                                                fclose( $fh );
 
                                                // Put the old page text into a 
different temporary file:
@@ -74,7 +77,7 @@
                                                $oldtext = $oldrev->getText();
                                                $old_file = tempnam( $tempdir, 
'mediawikiemaildiffold' );
                                                $fh = fopen( $old_file, 'w' ) 
or die( "Could not open file $old_file" );
-                                               fwrite( $fh, "$oldtext\n" );
+                                               fputs( $fh, "$oldtext\n" );
                                                fclose( $fh );
 
                                                // Create a destination file, 
then run the diff command
diff --git a/README b/README
index 382a930..c56b940 100644
--- a/README
+++ b/README
@@ -8,23 +8,34 @@
 
 http://www.mediawiki.org/wiki/Extension:EmailDiff
 
-Note that this extension may have serious performance issues on 
-very large sites, where "large" means thousands of users making 
-near-constant edits.
+This extension will only work on MediaWiki version 1.25 or better.
+
+EmailDiff is very useful on small wikis when used with 
$wgUsersNotifiedOnAllChanges
 
 INSTALLATION
 ============
 
-This extension will only work on MediaWiki version 1.25 or better.
+1. Install the files
 
 Unpack the tarball to your MediaWiki 'extensions' folder as usual.
 
-A new hook will need to be added to the file 
includes/mail/EmailNotification.php
+2. Add hooks to EmailNotification.php
+
+A new hook may need to be added in two places inside the file 
includes/mail/EmailNotification.php
 
 Inside the function sendPersonalized, right before the "return" line, add:
 
-Hooks::run( 'SendPersonalizedNotificationEmail',
+Hooks::run( 'SendNotificationEmail',
     [ $watchingUser, $this->oldid, $this->title, &$headers, &$this->subject, 
&$body ] );
+
+Inside the function sendImpersonal, right before the "return" line, add:
+
+$headers = [];
+Hooks::run( 'SendNotificationEmail',
+    [ null, $this->oldid, $this->title, &$headers, &$this->subject, &$body ] );
+
+
+3. Modify LocalSettings.php
 
 Next, add 'EmailDiff' to your list of modules to load inside your 
LocalSettings.php 
 file via wfLoadExtension:
@@ -32,7 +43,7 @@
 wfLoadExtension( 'EmailDiff' );
 
 If you need to change any of the configuration values, do so right 
-beneath the wfLoadExtension line. There are currently three 
+beneath the wfLoadExtension line. There are currently two 
 configuration values:
 
 * $wgEmailDiffSubjectSuffix
@@ -51,6 +62,9 @@
 If you need to change it, make sure you keep the UPPERCASE items, which 
 are replaced before the command is run with temporary files.
 
+
+4. Modify the outgoing email template
+
 One final change is needed to make this extension work: you must 
 add the string "$PAGEDIFF" (without the quotes) to the template 
 for outgoing notification emails. This can be done by visiting 
@@ -67,3 +81,77 @@
 
 $NEWPAGE
 
+5. Set users to view diffs
+
+If you are using "impersonal" emails by setting $wgEnotifImpersonal true in 
your LocalSettings.php, 
+then everyone will receive a diff.
+
+Otherwise, users must set their preferences to receive email diffs. Go to 
Preferences, then 
+find the "Email options" section and select "Send a diff of changes"
+
+Alternatively, you can simpy turn this on for all users by adding the 
+following line to your LocalSettings.php file:
+
+$wgDefaultUserOptions['enotifshowdiff'] = true;
+
+
+ADVANCED OPTIONS
+================
+
+* Receive email about your own edits
+
+If you wish to get an email for all edits, even those made by yourself, do the 
following:
+
+Add this to your LocalSettings.php file:
+
+$wgEnotifSelfEdits = true;
+
+Edit the file includes/mail/EmailNotification.php. Find the function 
actuallyNotifyOnPageChange, 
+then add $wgEnotifSelfEdits to the list of global variables at the top of the 
function. It should 
+look similar to this after the change:
+
+  global $wgEnotifMinorEdits, $wgEnotifUserTalk, $wgEnotifSelfEdits;
+
+Search for the string 'editor->getName', and change this block of code:
+
+  if ( $editor->getName() == $name ) {
+    // No point notifying the user that actually made the change!              
                                                                                
                     
+    continue;
+  }
+
+into this:
+
+  if ( $editor->getName() == $name && ! $wgEnotifSelfEdits) {
+    // No point notifying the user that actually made the change!              
                                                                                
                     
+    continue;
+  }
+
+You should now receive emails on every change, even those done yourself.
+
+
+* Do not receive emails when a bot makes an edit
+
+It can be a pain if your username is inside $wgUsersNotifiedOnAllChanges and 
+a bot comes along and updates hundreds of pages at once. The best way to 
+prevent this is to restrict email to non-bots only.
+
+Add this to your LocalSettings.php file:
+
+$wgEnotifBotEdits = false;
+
+Edit the file includes/mail/EmailNotification.php. Find the function 
notifyOnPageChange, 
+then add $wgEnotifBotEdits to the list of global variables at the top of the 
function. It should 
+look similar to this after the change:
+
+  global $wgEnotifMinorEdits, $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk, 
$wgEnotifBotEdits;
+
+
+Find the line that has "$sendEmail = true;" and add this block of code before 
that line:
+
+
+  // May not want to get emails when a bot edits a page
+  if ( $editor->isAllowed( 'bot' ) && ! $wgEnotifBotEdits ) {
+    return;
+  }
+
+Once that is done, bot edits should not trigger email notifications.
diff --git a/extension.json b/extension.json
index 8047d86..e446c14 100644
--- a/extension.json
+++ b/extension.json
@@ -5,7 +5,7 @@
        "author": [
                "Greg Sabino Mullane"
        ],
-       "version": "1.7",
+       "version": "1.8",
        "url": "https://www.mediawiki.org/wiki/Extension:EmailDiff";,
        "descriptionmsg": "emaildiff-desc",
        "license-name": "MIT",
@@ -16,8 +16,8 @@
                "EmailDiff": "EmailDiff_body.php"
        },
        "Hooks": {
-               "SendPersonalizedNotificationEmail": [
-                       "EmailDiff::SendPersonalizedNotificationEmailDiff"
+               "SendNotificationEmail": [
+                       "EmailDiff::SendNotificationEmailDiff"
                ],
                "GetPreferences": [
                        "EmailDiff::SetEmailDiffPref"

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6131ac952819d45c2ab05f5ad3b797f711a5d833
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/EmailDiff
Gerrit-Branch: master
Gerrit-Owner: Greg Sabino Mullane <g...@turnstep.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: Umherirrender <umherirrender_de...@web.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to