Tobias Gritschacher has uploaded a new change for review. https://gerrit.wikimedia.org/r/85982
Change subject: (bug 54492) Display a custom sitename for specific site groups ...................................................................... (bug 54492) Display a custom sitename for specific site groups This will allow to specify a message for a sitename for special sites as e.g. Wikimedia Commons which then gets displayed instead of the language name in the first column of the sitelinks table. This requires to add the sitegroup to $wgWBSettings['specialSiteLinkGroups'] and specify a message. Change-Id: Id6ba4e138794ae2aba8d2d96bc9a1154f2c38308 --- M lib/WikibaseLib.i18n.php M lib/includes/modules/SitesModule.php M repo/includes/ItemView.php 3 files changed, 33 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/82/85982/1 diff --git a/lib/WikibaseLib.i18n.php b/lib/WikibaseLib.i18n.php index d909e10..7b8bfd8 100644 --- a/lib/WikibaseLib.i18n.php +++ b/lib/WikibaseLib.i18n.php @@ -67,6 +67,7 @@ 'wikibase-validator-bad-url-scheme' => 'Unsupported URL scheme: $1', 'wikibase-validator-bad-http-url' => 'Malformed HTTP URL: $1', 'wikibase-validator-bad-mailto-url' => 'Malformed mailto URL: $1', + 'wikibase-sitelinks-sitename-commons' => 'Wikimedia Commons', 'datatypes-type-wikibase-item' => 'Item', 'datatypes-type-commonsMedia' => 'Commons media file', 'version-wikibase' => 'Wikibase', @@ -231,6 +232,7 @@ Parameters: * $1 - the malformed URL {{Related|Wikibase-validator}}', + 'wikibase-sitelinks-sitename-commons' => 'Name that should be shown in the first column of the sitelink table for wikimedia commons links.', 'datatypes-type-wikibase-item' => 'The name of a data type for items in Wikibase. {{Identical|Item}}', 'datatypes-type-commonsMedia' => 'The name of a data type for media files on Wikimedia Commons (proper name, capitalised in English; first letter capitalised anyway in this message and relatives).', diff --git a/lib/includes/modules/SitesModule.php b/lib/includes/modules/SitesModule.php index e5b48f2..e0c7386 100644 --- a/lib/includes/modules/SitesModule.php +++ b/lib/includes/modules/SitesModule.php @@ -49,6 +49,13 @@ $groups = Settings::get( "siteLinkGroups" ); + // wrapping in a try-catch to handle nonexisting setting gracefully + try { + $specialGroups = Settings::get( "specialSiteLinkGroups" ); + } catch ( \OutOfBoundsException $e ) { + $specialGroups = null; + } + /** * @var MediaWikiSite $site */ @@ -56,7 +63,12 @@ $group = $site->getGroup(); if ( $site->getType() === Site::TYPE_MEDIAWIKI && in_array( $group, $groups ) ) { - $languageName = Utils::fetchLanguageName( $site->getLanguageCode() ); + // FIXME: this is a quickfix to allow a custom site-name for groups defined in $wgSpecialSiteLinkGroups instead of showing the language-name + if ( is_array( $specialGroups ) && in_array( $group, $specialGroups ) ) { + $languageName = wfMessage( 'wikibase-sitelinks-sitename-' . $group )->parse(); + } else { + $languageName = Utils::fetchLanguageName( $site->getLanguageCode() ); + } $globalId = $site->getGlobalId(); // Use protocol relative URIs, as it's safe to assume that all wikis support the same protocol diff --git a/repo/includes/ItemView.php b/repo/includes/ItemView.php index 05e2ab4..849e964 100644 --- a/repo/includes/ItemView.php +++ b/repo/includes/ItemView.php @@ -1,6 +1,7 @@ <?php namespace Wikibase; + use Html, ParserOutput, Title, Language, OutputPage, Sites, MediaWikiSite; use Wikibase\DataModel\SimpleSiteLink; use Wikibase\Repo\WikibaseRepo; @@ -43,7 +44,8 @@ * @return string */ public function getHtmlForSiteLinks( EntityContent $item, Language $lang = null, $editable = true ) { - $groups = Settings::get( "siteLinkGroups" ); + $groups = WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( "siteLinkGroups" ); + #$groups = Settings::get( "siteLinkGroups" ); $html = ''; foreach ( $groups as $group ) { @@ -69,6 +71,13 @@ * @var ItemContent $itemContent */ $allSiteLinks = $itemContent->getItem()->getSimpleSiteLinks(); + + // wrapping in a try-catch to handle nonexisting setting gracefully + try { + $specialGroups = WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( "specialSiteLinkGroups" ); + } catch( \OutOfBoundsException $e ) { + $specialGroups = null; + } $siteLinks = array(); // site links of the currently handled site group @@ -144,6 +153,13 @@ } else { $languageCode = $site->getLanguageCode(); $escapedSiteId = htmlspecialchars( $site->getGlobalId() ); + // FIXME: this is a quickfix to allow a custom site-name for groups defined in $wgSpecialSiteLinkGroups instead of showing the language-name + if ( is_array( $specialGroups ) && in_array( $group, $specialGroups ) ) { + $siteName = wfMessage( 'wikibase-sitelinks-sitename-' . $group )->parse(); + } else { + // TODO: get an actual site name rather then just the language + $siteName = htmlspecialchars( Utils::fetchLanguageName( $languageCode ) ); + } // TODO: for non-JS, also set the dir attribute on the link cell; // but do not build language objects for each site since it causes too much load @@ -151,7 +167,7 @@ $tbody .= wfTemplate( 'wb-sitelink', $languageCode, $alternatingClass, - htmlspecialchars( Utils::fetchLanguageName( $languageCode ) ), // TODO: get an actual site name rather then just the language + $siteName, $escapedSiteId, // displayed site ID htmlspecialchars( $link->getUrl() ), htmlspecialchars( $link->getPage() ), -- To view, visit https://gerrit.wikimedia.org/r/85982 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id6ba4e138794ae2aba8d2d96bc9a1154f2c38308 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Tobias Gritschacher <tobias.gritschac...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits