Bsitu has uploaded a new change for review.

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

Change subject: Add emailsubject as a distribution type
......................................................................

Add emailsubject as a distribution type

so that we could skip parameters escaping  when formatting email
subject. This is not a great solution but works for now.

Probably should re-think all the use case of echo formatting and
refactor the formatter

Change-Id: Ic1f6aa0f72d637558466db5cb2ee8d36038dd0b2
---
M formatters/BasicFormatter.php
M formatters/NotificationFormatter.php
2 files changed, 15 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/40/159840/1

diff --git a/formatters/BasicFormatter.php b/formatters/BasicFormatter.php
index b9235cf..761c274 100644
--- a/formatters/BasicFormatter.php
+++ b/formatters/BasicFormatter.php
@@ -282,12 +282,19 @@
 
                // Echo single email
                $emailSingle = new EchoEmailSingle( $this, $event, $user );
-
                $textEmailFormatter = new EchoTextEmailFormatter( $emailSingle 
);
+               // Update the distribution type to emailsubject when formatting
+               // email subject
+               // @FIXME - Find a better way to do this
+               $distributionType = $this->distributionType;
+               $this->setDistributionType( 'emailsubject' );
+               $subject = $this->formatFragment( $this->email['subject'], 
$event, $user )->text();
+               $this->setDistributionType( $distributionType );
+
                $content = array(
                        // Single email subject, there is no need to to escape 
it for either html
                        // or text email since it's always treated as plain 
text by mail client
-                       'subject' => $this->formatFragment( 
$this->email['subject'], $event, $user )->text(),
+                       'subject' => $subject,
                        // Single email text body
                        'body' => $textEmailFormatter->formatEmail(),
                );
@@ -660,13 +667,15 @@
        }
 
        /**
-        * Process a param that should be escaped
+        * Process a parameter that should be escaped for display except for use
+        * cases like plain text email and email subject
+        *
         * @param $message Message
         * @param $paramContent string
         */
        protected function processParamEscaped( $message, $paramContent ) {
-               // Plain text email does not need escape
-               if ( $this->outputFormat !== 'email' ) {
+               // Plain text email and email subject do not need to be escaped
+               if ( $this->outputFormat !== 'email' && $this->distributionType 
!== 'emailsubject' ) {
                        $paramContent = htmlspecialchars( $paramContent );
                }
 
diff --git a/formatters/NotificationFormatter.php 
b/formatters/NotificationFormatter.php
index 9ca8e05..2604ea3 100644
--- a/formatters/NotificationFormatter.php
+++ b/formatters/NotificationFormatter.php
@@ -17,7 +17,7 @@
        /**
         * List of valid distribution type
         */
-       protected $validDistributionType = array( 'web', 'email', 'emaildigest' 
);
+       protected $validDistributionType = array( 'web', 'email', 
'emaildigest', 'emailsubject' );
 
        /**
         * Current output format, default is 'text'

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic1f6aa0f72d637558466db5cb2ee8d36038dd0b2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Bsitu <[email protected]>

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

Reply via email to