mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 09:40:41 +00:00
Merge "Display human-readable wiki names for cross-wiki notifications"
This commit is contained in:
commit
6b36375ded
|
@ -157,6 +157,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.",
|
||||
|
|
|
@ -178,6 +178,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}}",
|
||||
|
|
|
@ -134,15 +134,53 @@ class EchoForeignNotifications {
|
|||
|
||||
$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;
|
||||
|
||||
$msg = wfMessage( 'project-localized-name-'.$wikiId );
|
||||
// check if WikimediaMessages localized project names are available
|
||||
if ( $msg->exists() ) {
|
||||
return $msg->text();
|
||||
} else {
|
||||
// don't fetch $site, $langCode if known already
|
||||
if ( $siteFromDB === null ) {
|
||||
$siteFromDB = $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, $wgLang->getCode() );
|
||||
|
||||
if ( !$langName ) {
|
||||
// if we can't find a language name (in language-agnostic
|
||||
// project like mediawikiwiki), including the language name
|
||||
// doesn't make much sense
|
||||
return $wikiName;
|
||||
}
|
||||
|
||||
// ... or use generic fallback
|
||||
return wfMessage( 'echo-foreign-wiki-lang', $wikiName, $langName )->text();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,15 @@ class EchoForeignPresentationModel extends EchoEventPresentationModel {
|
|||
$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'];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue