mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-11 17:00:10 +00:00
Add a rasterized email icons to Echo modules for email
Make sure we send rasterized png emails instead of SVGs in the email formatter. Bug: T127794 Change-Id: Ia28757bda521ec182f75458c8e52d54847d15681
This commit is contained in:
parent
c4121e7ff8
commit
5fefbe4b03
|
@ -353,6 +353,11 @@ $wgResourceModules += array(
|
|||
'selectorWithoutVariant' => '.oo-ui-icon-{name}',
|
||||
'selectorWithVariant' => '.oo-ui-image-{variant}.oo-ui-icon-{name}',
|
||||
),
|
||||
'ext.echo.emailicons' => array(
|
||||
'class' => 'ResourceLoaderEchoImageModule',
|
||||
'selector' => '.mw-echo-icon-{name}',
|
||||
'localBasePath' => $wgExtensionDirectory, // Extension path
|
||||
) + $echoResourceTemplate,
|
||||
);
|
||||
|
||||
unset( $echoResourceTemplate );
|
||||
|
|
|
@ -113,6 +113,7 @@ $wgAutoloadClasses += [
|
|||
'RemoveInvalidNotification' => __DIR__ . '/maintenance/removeInvalidNotification.php',
|
||||
'RemoveInvalidTargetPage' => __DIR__ . '/maintenance/removeInvalidTargetPage.php',
|
||||
'RemoveOrphanedEvents' => __DIR__ . '/maintenance/removeOrphanedEvents.php',
|
||||
'ResourceLoaderEchoImageModule' => __DIR__ . '/includes/ResourceLoaderEchoImageModule.php',
|
||||
'SpecialDisplayNotificationsConfiguration' => __DIR__ . '/includes/special/SpecialDisplayNotificationsConfiguration.php',
|
||||
'SpecialNotifications' => __DIR__ . '/includes/special/SpecialNotifications.php',
|
||||
'SpecialNotificationsFormatter' => __DIR__ . '/includes/formatters/SpecialNotificationsFormatter.php',
|
||||
|
|
59
includes/ResourceLoaderEchoImageModule.php
Normal file
59
includes/ResourceLoaderEchoImageModule.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?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.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
/**
|
||||
* A sibling of secret special sauce.
|
||||
* @see ResourceLoaderOOUIImageModule for familial resemblence
|
||||
*/
|
||||
class ResourceLoaderEchoImageModule extends ResourceLoaderImageModule {
|
||||
protected function loadFromDefinition() {
|
||||
global $wgEchoNotificationIcons;
|
||||
|
||||
if ( $this->definition === null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$images = array();
|
||||
foreach ( $wgEchoNotificationIcons as $iconName => $definition ) {
|
||||
// FIXME: We also have a 'site' icon which is "magical"
|
||||
// and uses witchcraft and should be handled specifically
|
||||
$paths = '';
|
||||
if ( isset( $definition[ 'path' ] ) ) {
|
||||
if ( is_array( $definition[ 'path' ] ) ) {
|
||||
foreach ( $definition[ 'path' ] as $dir => $p ) {
|
||||
// Has both rtl and ltr definitions
|
||||
$paths[ $dir ] = $p;
|
||||
}
|
||||
} else {
|
||||
$paths = $definition[ 'path' ];
|
||||
}
|
||||
|
||||
if ( !empty( $paths ) ) {
|
||||
$images[ $iconName ][ 'file' ] = $paths;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->definition[ 'images' ] = $images;
|
||||
$this->definition[ 'selector' ] = '.oo-ui-icon-{name}';
|
||||
// Parent
|
||||
parent::loadFromDefinition();
|
||||
}
|
||||
}
|
|
@ -175,9 +175,10 @@ EOF;
|
|||
*/
|
||||
protected function applyStyleToEvent( EchoEventPresentationModel $model ) {
|
||||
$iconUrl = wfExpandUrl(
|
||||
EchoIcon::getUrl( $model->getIconType(), $this->language->getDir() ),
|
||||
EchoIcon::getRasterizedUrl( $model->getIconType(), $this->language->getCode() ),
|
||||
PROTO_CANONICAL
|
||||
);
|
||||
|
||||
$imgSrc = Sanitizer::encodeAttribute( $iconUrl );
|
||||
|
||||
// notification text
|
||||
|
|
|
@ -6,7 +6,6 @@ class EchoHtmlEmailFormatter extends EchoEventFormatter {
|
|||
const SECONDARY_LINK_STYLE = 'text-decoration: none;font-size: 10px;font-family: Arial, Helvetica, sans-serif; color: #808184;';
|
||||
|
||||
protected function formatModel( EchoEventPresentationModel $model ) {
|
||||
|
||||
$subject = $model->getSubjectMessage()->parse();
|
||||
|
||||
$intro = $model->getHeaderMessage()->parse();
|
||||
|
@ -26,7 +25,7 @@ class EchoHtmlEmailFormatter extends EchoEventFormatter {
|
|||
}
|
||||
|
||||
$iconUrl = wfExpandUrl(
|
||||
EchoIcon::getUrl( $model->getIconType(), $this->language->getDir() ),
|
||||
EchoIcon::getRasterizedUrl( $model->getIconType(), $this->language->getCode() ),
|
||||
PROTO_CANONICAL
|
||||
);
|
||||
|
||||
|
|
|
@ -46,4 +46,43 @@ class EchoIcon {
|
|||
return $iconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a link to a rasterized version of the icon
|
||||
*
|
||||
* @param string $icon Icon name
|
||||
* @param string $lang Language
|
||||
* @return string URL to the rasterized version of the icon
|
||||
*/
|
||||
public static function getRasterizedUrl( $icon, $lang ) {
|
||||
global $wgEchoNotificationIcons;
|
||||
if ( !isset( $wgEchoNotificationIcons[$icon] ) ) {
|
||||
throw new InvalidArgumentException( "The $icon icon is not registered" );
|
||||
}
|
||||
|
||||
$url = isset( $wgEchoNotificationIcons[ $icon ][ 'url' ] ) ?
|
||||
$wgEchoNotificationIcons[ $icon ][ 'url' ] :
|
||||
null;
|
||||
|
||||
// If the defined URL is explicitly false, use placeholder
|
||||
if ( $url === false ) {
|
||||
$icon = 'placeholder';
|
||||
}
|
||||
|
||||
// If the URL is null or false call the resource loader
|
||||
// rasterizing module
|
||||
if ( $url === false || $url === null ) {
|
||||
$iconUrl = wfScript( 'load' ) . '?' . wfArrayToCgi( array(
|
||||
'modules' => 'ext.echo.emailicons',
|
||||
'image' => $icon,
|
||||
'lang' => $lang,
|
||||
'format' => 'rasterized'
|
||||
) );
|
||||
} else {
|
||||
// For icons that are defined by URL
|
||||
$iconUrl = $wgEchoNotificationIcons[ $icon ][ 'url' ];
|
||||
}
|
||||
|
||||
return $iconUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue