jenkins-bot has submitted this change and it was merged.

Change subject: Change icons to use img tags, allowing easier customization:
......................................................................


Change icons to use img tags, allowing easier customization:

* Icon can be defined using a path or a URL
* Extensions don't need custom CSS, but add icon through BeforeCreateEchoEvent
* Sites set their notification icon in LocalSettings.php or equivalent

Bug: 46585
Change-Id: Ifc02b653d07de19229dfb2604305e32f3bd595fe
---
M Echo.php
M Hooks.php
M formatters/BasicFormatter.php
M modules/base/ext.echo.base.css
D modules/icons/icons.css
M special/SpecialNotifications.php
6 files changed, 79 insertions(+), 67 deletions(-)

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



diff --git a/Echo.php b/Echo.php
index 3021a31..c6aea70 100644
--- a/Echo.php
+++ b/Echo.php
@@ -128,7 +128,6 @@
                        'mediawiki.api',
                        'mediawiki.jqueryMsg',
                        'jquery.badge',
-                       'ext.echo.icons',
                        'mediawiki.ui',
                ),
                'messages' => array(
@@ -151,16 +150,12 @@
                        'ext.echo.base',
                        'mediawiki.api',
                        'mediawiki.jqueryMsg',
-                       'ext.echo.icons',
                ),
                'messages' => array(
                        'echo-load-more-error',
                        'echo-more-info',
                        'echo-feedback',
                ),
-       ),
-       'ext.echo.icons' => $echoResourceTemplate + array(
-               'styles' => 'icons/icons.css',
        ),
 );
 
@@ -296,6 +291,56 @@
        ),
 );
 
+$echoIconPath = "Echo/modules/icons";
+
+// Defines icons, which are 30x30 images. This is passed to 
BeforeCreateEchoEvent so
+// extensions can define their own icons with the same structure.  It is 
recommended that
+// extensions prefix their icon key. An example is myextension-name.  This 
will help
+// avoid namespace conflicts.
+//
+// You can use either a path or a url, but not both.
+// The value of 'path' is relative to $wgExtensionAssetsPath.
+//
+// The value of 'url' should be a URL.
+//
+// You should customize the site icon URL, which is:
+// $wgEchoNotificationIcons['site']['url']
+$wgEchoNotificationIcons = array(
+       'placeholder' => array(
+               'path' => "$echoIconPath/Generic.png",
+       ),
+       'trash' => array(
+               'path' => "$echoIconPath/Deletion.png",
+       ),
+       'chat' => array(
+               'path' => "$echoIconPath/Talk.png",
+       ),
+       'linked' => array(
+               'path' => "$echoIconPath/CrossReferenced.png",
+       ),
+       'featured' => array(
+               'path' => "$echoIconPath/Featured.png",
+       ),
+       'reviewed' => array(
+               'path' => "$echoIconPath/Reviewed.png",
+       ),
+       'tagged' => array(
+               'path' => "$echoIconPath/ReviewedWithTags.png",
+       ),
+       'revert' => array(
+               'path' => "$echoIconPath/Revert.png",
+       ),
+       'checkmark' => array(
+               'path' => "$echoIconPath/Reviewed.png",
+       ),
+       'gratitude' => array(
+               'path' => "$echoIconPath/Gratitude.png",
+       ),
+       'site' => array(
+               'url' => false
+       ),
+);
+
 // Definitions of the notification event types built into Echo.
 // If formatter-class isn't specified, defaults to EchoBasicFormatter.
 $wgEchoNotifications = array(
@@ -304,6 +349,7 @@
                'group' => 'system',
                'title-message' => 'notification-new-user',
                'title-params' => array( 'agent' ),
+               'icon' => 'site',
        ),
        'edit-user-talk' => array(
                'category' => 'edit-user-talk',
@@ -399,6 +445,7 @@
                'email-body-params' => array( 'agent', 'user-rights-list', 
'email-footer' ),
                'email-body-batch-message' => 
'notification-user-rights-email-batch-body',
                'email-body-batch-params' => array( 'agent', 'user-rights-list' 
),
+               'icon' => 'site',
        ),
 );
 
diff --git a/Hooks.php b/Hooks.php
index 8858fdc..44d36f4 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -12,10 +12,10 @@
         */
        public static function initEchoExtension() {
                global $wgEchoBackend, $wgEchoBackendName, $wgEchoNotifications,
-                       $wgEchoNotificationCategories, $wgEchoConfig;
+                       $wgEchoNotificationCategories, 
$wgEchoNotificationIcons, $wgEchoConfig;
 
                // allow extensions to define their own event
-               wfRunHooks( 'BeforeCreateEchoEvent', array( 
&$wgEchoNotifications, &$wgEchoNotificationCategories ) );
+               wfRunHooks( 'BeforeCreateEchoEvent', array( 
&$wgEchoNotifications, &$wgEchoNotificationCategories, 
&$wgEchoNotificationIcons ) );
 
                $wgEchoBackend = MWEchoBackend::factory( $wgEchoBackendName );
 
diff --git a/formatters/BasicFormatter.php b/formatters/BasicFormatter.php
index d276ccb..84ec03d 100644
--- a/formatters/BasicFormatter.php
+++ b/formatters/BasicFormatter.php
@@ -143,7 +143,7 @@
         * @return array|string
         */
        public function format( $event, $user, $type ) {
-               global $wgEchoNotificationCategories;
+               global $wgEchoNotificationCategories, $wgExtensionAssetsPath, 
$wgEchoNotificationIcons;
 
                // Use the bundle message if use-bundle is true and there is a 
bundle message
                $this->generateBundleData( $event, $user, $type );
@@ -159,11 +159,24 @@
                        return $this->formatNotificationTitle( $event, $user 
)->text();
                }
 
+               $iconInfo = $wgEchoNotificationIcons[$this->icon];
+               if ( isset( $iconInfo['url'] ) && $iconInfo['url'] ) {
+                       $iconUrl = $iconInfo['url'];
+               } else {
+                       if ( !isset( $iconInfo['path'] ) || !$iconInfo['path'] 
) {
+                               // Fallback in case icon is not configured; 
mainly intended for 'site'
+                               $iconInfo = 
$wgEchoNotificationIcons['placeholder'];
+                       }
+                       $iconUrl = "$wgExtensionAssetsPath/{$iconInfo['path']}";
+               }
+
                // Assume html as the format for the notification
-               $output = Xml::tags(
-                       'div',
-                       array( 'class' => "mw-echo-icon 
mw-echo-icon-{$this->icon}" ),
-                       ' '
+               $output = Html::element(
+                       'img',
+                       array(
+                               'class' => "mw-echo-icon",
+                               'src' => $iconUrl,
+                       )
                );
 
                // Add the hidden dismiss interface if the notification is 
dismissable
diff --git a/modules/base/ext.echo.base.css b/modules/base/ext.echo.base.css
index e2a981f..27e1cbd 100644
--- a/modules/base/ext.echo.base.css
+++ b/modules/base/ext.echo.base.css
@@ -71,3 +71,10 @@
 .mw-echo-notification span.autocomment {
        color: inherit;
 }
+.mw-echo-icon {
+       width: 30px;
+       height: 30px;
+       float: left;
+       margin-right: 10px;
+       margin-left: 10px;
+}
diff --git a/modules/icons/icons.css b/modules/icons/icons.css
deleted file mode 100644
index a8c1ac2..0000000
--- a/modules/icons/icons.css
+++ /dev/null
@@ -1,54 +0,0 @@
-.mw-echo-icon {
-       width: 30px;
-       height: 30px;
-       float: left;
-       margin-right: 10px;
-       margin-left: 10px;
-       background: no-repeat center right;
-       background-size: 80%;
-}
-
-.mw-echo-icon-placeholder {
-       /* @embed */
-       background-image: url(Generic.png);
-}
-.mw-echo-icon-trash {
-       /* @embed */
-       background-image: url(Deletion.png);
-}
-.mw-echo-icon-chat {
-       /* @embed */
-       background-image: url(Talk.png);
-}
-.mw-echo-icon-linked {
-       /* @embed */
-       background-image: url(CrossReferenced.png);
-}
-.mw-echo-icon-featured {
-       /* @embed */
-       background-image: url(Featured.png);
-}
-.mw-echo-icon-reviewed {
-       /* @embed */
-       background-image: url(Reviewed.png);
-}
-.mw-echo-icon-tagged {
-       /* @embed */
-       background-image: url(ReviewedWithTags.png);
-}
-.mw-echo-icon-w {
-       /* @embed */
-       background-image: url(W.png);
-}
-.mw-echo-icon-revert {
-       /* @embed */
-       background-image: url(Revert.png);
-}
-.mw-echo-icon-checkmark {
-       /* @embed */
-       background-image: url(Reviewed.png);
-}
-.mw-echo-icon-gratitude {
-       /* @embed */
-       background-image: url(Gratitude.png);
-}
diff --git a/special/SpecialNotifications.php b/special/SpecialNotifications.php
index 44e9aa8..3a5a048 100644
--- a/special/SpecialNotifications.php
+++ b/special/SpecialNotifications.php
@@ -114,7 +114,6 @@
                // For no-js support
                global $wgExtensionAssetsPath;
                $out->addExtensionStyle( 
"$wgExtensionAssetsPath/Echo/modules/base/ext.echo.base.css" );
-               $out->addExtensionStyle( 
"$wgExtensionAssetsPath/Echo/modules/icons/icons.css" );
                // Mark items as read
                if ( $unread ) {
                        EchoNotificationController::markRead( $user, $unread );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc02b653d07de19229dfb2604305e32f3bd595fe
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to