Matthias Mullie has uploaded a new change for review.

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

Change subject: Display human-readable wiki names for cross-wiki notifications
......................................................................

Display human-readable wiki names for cross-wiki notifications

Bug: T121936
Change-Id: Ic14fe65f4ecc6db94fc6774ca0c39d1c2a47db9d
---
M i18n/en.json
M i18n/qqq.json
M includes/ForeignNotifications.php
M includes/formatters/EchoForeignPresentationModel.php
4 files changed, 54 insertions(+), 3 deletions(-)


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

diff --git a/i18n/en.json b/i18n/en.json
index e7e16ee..450c4d4 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -140,6 +140,7 @@
        "echo-rev-deleted-text-view": "This page revision has been suppressed.",
        "notification-header-foreign-alert": "More alerts from $3 
{{PLURAL:$4|and one other wiki|and $4 other wikis|0=}}",
        "notification-header-foreign-message": "More messages from $3 
{{PLURAL:$4|and one other wiki|and $4 other wikis|0=}}",
+       "echo-foreign-wiki-lang": "$1 - $2",
        "apihelp-echomarkread-description": "Mark notifications as read for the 
current user.",
        "apihelp-echomarkread-param-list": "A list of notification IDs to mark 
as read.",
        "apihelp-echomarkread-param-all": "If set, marks all of a user's 
notifications as read.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 7b5f4b9..1bbc44a 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -161,6 +161,7 @@
        "echo-rev-deleted-text-view": "Short message displayed instead of edit 
content when revision text is suppressed.",
        "notification-header-foreign-alert": "Flyout-specific format for 
displaying notification header of having alert notifications on foreign 
wikis.\n\nParameters:\n* $1 - the formatted username of the current user.\n* $2 
- the username for GENDER\n* $3 - 1 of the foreign wikis you have notifications 
on\n* $4 - the amount of remaining other wikis you have notifications on",
        "notification-header-foreign-message": "Flyout-specific format for 
displaying notification header of having message notifications on foreign 
wikis.\n\nParameters:\n* $1 - the formatted username of the current user.\n* $2 
- the username for GENDER\n* $3 - 1 of the foreign wikis you have notifications 
on\n* $4 - the amount of remaining other wikis you have notifications on",
+       "echo-foreign-wiki-lang": "Title of the wiki for which you're seeing 
foreign notifications:\n\nParameters:\n* $1 - the name of the site (e.g. 
'Wikipedia', 'Wikiversity', ...)\n* $2 - the language of the website (e.g. 
'English', 'Deutsch', ...)",
        "apihelp-echomarkread-description": 
"{{doc-apihelp-description|echomarkread}}",
        "apihelp-echomarkread-param-list": 
"{{doc-apihelp-param|echomarkread|list}}",
        "apihelp-echomarkread-param-all": 
"{{doc-apihelp-param|echomarkread|all}}",
diff --git a/includes/ForeignNotifications.php 
b/includes/ForeignNotifications.php
index 42e26e4..0fbabfc 100644
--- a/includes/ForeignNotifications.php
+++ b/includes/ForeignNotifications.php
@@ -134,15 +134,58 @@
 
                $data = array();
                foreach ( $wikis as $wiki ) {
-                       list( $major, $minor ) = $wgConf->siteFromDB( $wiki );
+                       $siteFromDB = $wgConf->siteFromDB( $wiki );
+                       list( $major, $minor ) = $siteFromDB;
                        $server = $wgConf->get( 'wgServer', $wiki, $major, 
array( 'lang' => $minor, 'site' => $major ) );
                        $scriptPath = $wgConf->get( 'wgScriptPath', $wiki, 
$major, array( 'lang' => $minor, 'site' => $major ) );
+
                        $data[$wiki] = array(
-                               'title' => $wiki,
+                               'title' => $this->getWikiTitle( $wiki, 
$siteFromDB ),
                                'url' => $server . $scriptPath . '/api.php',
                        );
                }
 
                return $data;
        }
+
+       /**
+        * @param string $wikiId
+        * @param array $siteFromDB $wgConf->siteFromDB( $wikiId ) result
+        * @return mixed|string
+        */
+       protected function getWikiTitle( $wikiId, array $siteFromDB = null ) {
+               global $wgConf, $wgLang;
+
+               // don't re-fetch current wiki's data if we've already done so 
before
+               static $current = array();
+               if ( !$current ) {
+                       $current = $wgConf->siteFromDB( wfWikiID() );
+               }
+
+               // don't fetch $site, $langCode if known already
+               if ( $siteFromDB === null ) {
+                       $wgConf->siteFromDB( $wikiId );
+               }
+               list( $site, $langCode ) = $siteFromDB;
+
+               // try to fetch site name for this specific wiki, or fallback 
to the
+               // general project's sitename if there is no override
+               $wikiName = $wgConf->get( 'wgSitename', $wikiId ) ?: 
$wgConf->get( 'wgSitename', $site );
+               $langName = $wgLang->fetchLanguageName( $langCode );
+
+               if ( $site === $current[0] ) {
+                       // if we're on the same website type, don't include the 
website
+                       // name in the title (e.g. only show "English" when 
looking at
+                       // English wikipedia notifications from another 
wikipedia)
+                       return $langName;
+               } elseif ( !$langName ) {
+                       // if we can't find a language name, we must be in a 
language-
+                       // agnostic project (e.g. Commons), where it doesn't 
make sense
+                       // to include the language name
+                       return $wikiName;
+               } else {
+                       // in all other cases, display both site name + language
+                       return wfMessage( 'echo-foreign-wiki-lang', $wikiName, 
$langName )->text();
+               }
+       }
 }
diff --git a/includes/formatters/EchoForeignPresentationModel.php 
b/includes/formatters/EchoForeignPresentationModel.php
index 0e7b00d..db86eab 100644
--- a/includes/formatters/EchoForeignPresentationModel.php
+++ b/includes/formatters/EchoForeignPresentationModel.php
@@ -20,9 +20,15 @@
                $msg = parent::getHeaderMessage();
 
                $data = $this->event->getExtra();
-               $msg->params( reset( $data['wikis'] ) );
+               $msg->params( $this->getWikiName( reset( $data['wikis'] ) ) );
                $msg->numParams( count( $data['wikis'] ) - 1 );
 
                return $msg;
        }
+
+       protected function getWikiName( $wiki ) {
+               $foreign = new EchoForeignNotifications( new User );
+               $data = $foreign->getApiEndpoints( array( $wiki ) );
+               return $data[$wiki]['title'];
+       }
 }

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

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

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

Reply via email to