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

Change subject: Normalize links in Special:Notifications formatter
......................................................................


Normalize links in Special:Notifications formatter

Change-Id: I35354a3b27a59ee9740c6330bb3df22a8f7d6093
---
M autoload.php
M includes/formatters/EchoFlyoutFormatter.php
A includes/formatters/LinkNormalizer.php
M includes/formatters/SpecialNotificationsFormatter.php
4 files changed, 64 insertions(+), 54 deletions(-)

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



diff --git a/autoload.php b/autoload.php
index ddb80dd..dd2867d 100644
--- a/autoload.php
+++ b/autoload.php
@@ -57,6 +57,7 @@
        'EchoHTMLEmailFormatter' => __DIR__ . '/includes/EmailFormatter.php',
        'EchoHooks' => __DIR__ . '/Hooks.php',
        'EchoIteratorDecorator' => __DIR__ . 
'/includes/iterator/IteratorDecorator.php',
+       'EchoLinkNormalizer' => __DIR__ . 
'/includes/formatters/LinkNormalizer.php',
        'EchoLocalCache' => __DIR__ . '/includes/cache/LocalCache.php',
        'EchoMentionFormatter' => __DIR__ . 
'/includes/formatters/MentionFormatter.php',
        'EchoMentionPresentationModel' => __DIR__ . 
'/includes/formatters/MentionPresentationModel.php',
diff --git a/includes/formatters/EchoFlyoutFormatter.php 
b/includes/formatters/EchoFlyoutFormatter.php
index 96d9540..4f7e378 100644
--- a/includes/formatters/EchoFlyoutFormatter.php
+++ b/includes/formatters/EchoFlyoutFormatter.php
@@ -1,4 +1,5 @@
 <?php
+use EchoLinkNormalizer;
 
 /**
  * A formatter for the notification flyout popup
@@ -39,7 +40,7 @@
                );
 
                $footerItems = array( $ts );
-               $secondaryLinks = $this->normalizeSecondaryLinks( 
$model->getSecondaryLinks() );
+               $secondaryLinks = EchoLinkNormalizer::normalizeSecondaryLinks( 
$model->getSecondaryLinks() );
                foreach ( $secondaryLinks as $link ) {
                        $footerItems[] = Html::element( 'a', array( 'href' => 
$link['url'] ), $link['label'] );
                }
@@ -52,7 +53,7 @@
                // Add the primary link afterwards, if it has one
                $primaryLink = $model->getPrimaryLink();
                if ( $primaryLink !== false ) {
-                       $primaryLink = $this->normalizePrimaryLink( 
$primaryLink );
+                       $primaryLink = 
EchoLinkNormalizer::normalizePrimaryLink( $primaryLink );
                        $html .= Html::element(
                                'a',
                                array( 'class' => 
'mw-echo-notification-primary-link', 'href' => $primaryLink['url'] ),
@@ -76,52 +77,4 @@
                );
        }
 
-       /**
-        * Utility method to ensure B/C compat with previous getPrimaryLink 
return
-        * types, until all of them have been fixed.
-        *
-        * @deprecated
-        * @param string|array|bool $link
-        * @return string|bool
-        */
-       protected function normalizePrimaryLink( $link ) {
-               // B/C for old format: [url, label]
-               if ( !isset( $link['url'] ) ) {
-                       return array(
-                               'url' => $link[0],
-                               'label' => $link[1],
-                       );
-               }
-
-               // current primary link format: ['url' => ..., 'label' => ...]
-               return $link;
-       }
-
-       /**
-        * Utility method to ensure B/C compat with previous getSecondaryLinks
-        * return types, until all of them have been fixed.
-        *
-        * @deprecated
-        * @param array $link
-        * @return array
-        */
-       protected function normalizeSecondaryLinks( array $link ) {
-               // B/C for old secondary links format: [url => label, ...]
-               if ( !isset( $link[0] ) || !isset( $link[0]['url'] ) ) {
-                       $links = array();
-                       foreach ( $link as $url => $text ) {
-                               $links[] = array(
-                                       'url' => $url,
-                                       'label' => $text,
-                                       'description' => '',
-                                       'icon' => false,
-                                       'prioritized' => false,
-                               );
-                       }
-                       return $links;
-               }
-
-               // current secondary links format: [['url' => ..., 'label' => 
..., ...], ...]
-               return $link;
-       }
 }
diff --git a/includes/formatters/LinkNormalizer.php 
b/includes/formatters/LinkNormalizer.php
new file mode 100644
index 0000000..107548d
--- /dev/null
+++ b/includes/formatters/LinkNormalizer.php
@@ -0,0 +1,56 @@
+<?php
+
+class EchoLinkNormalizer {
+
+       /**
+        * Utility method to ensure B/C compat with previous getPrimaryLink 
return
+        * types, until all of them have been fixed.
+        *
+        * @deprecated
+        * @param string|array|bool $link
+        * @return string|bool
+        */
+       public static function normalizePrimaryLink( $link ) {
+               // B/C for old format: [url, label]
+               if ( !isset( $link['url'] ) ) {
+                       return array(
+                               'url' => $link[0],
+                               'label' => $link[1],
+                       );
+               }
+
+               // current primary link format: ['url' => ..., 'label' => ...]
+               return $link;
+       }
+
+       /**
+        * Utility method to ensure B/C compat with previous getSecondaryLinks
+        * return types, until all of them have been fixed.
+        *
+        * @deprecated
+        * @param array $link
+        * @return array
+        */
+       public static function normalizeSecondaryLinks( array $link ) {
+               // B/C for old secondary links format: [url => label, ...]
+               if ( !isset( $link[0] ) || !isset( $link[0]['url'] ) ) {
+                       $links = array();
+                       foreach ( $link as $url => $text ) {
+                               $links[] = array(
+                                       'url' => $url,
+                                       'label' => $text,
+                                       'description' => '',
+                                       'icon' => false,
+                                       'prioritized' => true,
+                               );
+                       }
+                       return $links;
+               }
+
+               // current secondary links format: [['url' => ..., 'label' => 
..., ...], ...]
+               return $link;
+       }
+
+
+
+}
diff --git a/includes/formatters/SpecialNotificationsFormatter.php 
b/includes/formatters/SpecialNotificationsFormatter.php
index aa1d2a8..cfe5867 100644
--- a/includes/formatters/SpecialNotificationsFormatter.php
+++ b/includes/formatters/SpecialNotificationsFormatter.php
@@ -40,11 +40,11 @@
                $links = array();
                $primaryLink = $model->getPrimaryLink();
                if ( $primaryLink !== false ) {
-                       $links[$primaryLink[0]] = $primaryLink[1];
+                       $links[] = EchoLinkNormalizer::normalizePrimaryLink( 
$primaryLink );
                }
-               $links += $model->getSecondaryLinks();
-               foreach ( $links as $target => $text ) {
-                       $footerItems[] = Html::element( 'a', array( 'href' => 
$target ), $text );
+               $links = array_merge( $links, 
EchoLinkNormalizer::normalizeSecondaryLinks( $model->getSecondaryLinks() ) );
+               foreach ( $links as $link ) {
+                       $footerItems[] = Html::element( 'a', array( 'href' => 
$link['url'] ), $link['label'] );
                }
 
                $html .= Xml::tags(

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I35354a3b27a59ee9740c6330bb3df22a8f7d6093
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Sbisson <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Sbisson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to