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

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.

Needs https://gerrit.wikimedia.org/r/#/c/85986/ to be
merged into WikimediaMessages

Change-Id: Id6ba4e138794ae2aba8d2d96bc9a1154f2c38308
---
M lib/WikibaseLib.i18n.php
M lib/config/WikibaseLib.default.php
M lib/includes/modules/SitesModule.php
M lib/resources/Resources.php
M lib/resources/wikibase.ui.SiteLinksEditTool.js
M repo/includes/ItemView.php
6 files changed, 70 insertions(+), 21 deletions(-)

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



diff --git a/lib/WikibaseLib.i18n.php b/lib/WikibaseLib.i18n.php
index c58786b..f057d31 100644
--- a/lib/WikibaseLib.i18n.php
+++ b/lib/WikibaseLib.i18n.php
@@ -50,6 +50,7 @@
        'wikibase-replicationnote' => 'Please notice that it can take several 
minutes until the changes are visible on all wikis.',
        'wikibase-sitelinks-wikipedia' => 'Wikipedia pages linked to this item',
        'wikibase-sitelinks-sitename-columnheading' => 'Language',
+       'wikibase-sitelinks-sitename-columnheading-special' => 'Site',
        'wikibase-sitelinks-siteid-columnheading' => 'Code',
        'wikibase-sitelinks-link-columnheading' => 'Linked article',
        'wikibase-tooltip-error-details' => 'Details',
@@ -153,6 +154,8 @@
 See also Wikidatas glossary for [[d:Wikidata:Glossary#sitelinks|site links]] 
and [[d:Wikidata:Glossary#Item|item]].',
        'wikibase-sitelinks-sitename-columnheading' => 'Site links table column 
heading for the column containing the language names.
 {{Identical|Language}}',
+       'wikibase-sitelinks-sitename-columnheading-special' => 'Site links 
table column heading for the sitename column for special sites such as e.g. 
Commons.
+{{Identical|Language}}',
        'wikibase-sitelinks-siteid-columnheading' => 'Site links table column 
heading for the column containing the language codes.
 {{Identical|Code}}',
        'wikibase-sitelinks-link-columnheading' => 'Site links table column 
heading for the column containg the title/link of/to the referenced (wiki) 
page.',
diff --git a/lib/config/WikibaseLib.default.php 
b/lib/config/WikibaseLib.default.php
index aa58ca2..7b63972 100644
--- a/lib/config/WikibaseLib.default.php
+++ b/lib/config/WikibaseLib.default.php
@@ -51,6 +51,8 @@
                        'wikipedia',
                ),
 
+               'specialSiteLinkGroups' => array(),
+
                // local by default. Set to something LBFactory understands.
                'changesDatabase' => false,
 
diff --git a/lib/includes/modules/SitesModule.php 
b/lib/includes/modules/SitesModule.php
index e5b48f2..cfd70e4 100644
--- a/lib/includes/modules/SitesModule.php
+++ b/lib/includes/modules/SitesModule.php
@@ -48,6 +48,7 @@
                $sites = array();
 
                $groups = Settings::get( "siteLinkGroups" );
+               $specialGroups = Settings::get( "specialSiteLinkGroups" );
 
                /**
                 * @var MediaWikiSite $site
@@ -56,7 +57,15 @@
                        $group = $site->getGroup();
 
                        if ( $site->getType() === Site::TYPE_MEDIAWIKI && 
in_array( $group, $groups ) ) {
-                               $languageName = Utils::fetchLanguageName( 
$site->getLanguageCode() );
+                               // FIXME: quickfix to allow a custom site-name 
/ handling for groups defined in $wgSpecialSiteLinkGroups
+                               if ( in_array( $group, $specialGroups ) ) {
+                                       $languageNameMsg = wfMessage( 
'wikibase-sitelinks-sitename-' . $site->getGlobalId() );
+                                       $languageName = 
$languageNameMsg->exists() ? $languageNameMsg->parse() : $site->getGlobalId();
+                                       $groupName = 'special';
+                               } else {
+                                       $languageName = 
Utils::fetchLanguageName( $site->getLanguageCode() );
+                                       $groupName = $group;
+                               }
                                $globalId = $site->getGlobalId();
 
                                // Use protocol relative URIs, as it's safe to 
assume that all wikis support the same protocol
@@ -80,7 +89,7 @@
                                        'pageUrl' => $pageUrl,
                                        'apiUrl' => $apiUrl,
                                        'languageCode' => 
$site->getLanguageCode(),
-                                       'group' => $group
+                                       'group' => $groupName
                                );
                        }
                }
diff --git a/lib/resources/Resources.php b/lib/resources/Resources.php
index 3a4623e..0812d82 100644
--- a/lib/resources/Resources.php
+++ b/lib/resources/Resources.php
@@ -369,6 +369,7 @@
                                'wikibase-description-input-help-message',
                                'wikibase-sitelinks-input-help-message',
                                'wikibase-sitelinks-sitename-columnheading',
+                               
'wikibase-sitelinks-sitename-columnheading-special',
                                'wikibase-sitelinks-siteid-columnheading',
                                'wikibase-sitelinks-link-columnheading',
                                'wikibase-remove',
diff --git a/lib/resources/wikibase.ui.SiteLinksEditTool.js 
b/lib/resources/wikibase.ui.SiteLinksEditTool.js
index d35fc7a..94615b0 100644
--- a/lib/resources/wikibase.ui.SiteLinksEditTool.js
+++ b/lib/resources/wikibase.ui.SiteLinksEditTool.js
@@ -135,21 +135,7 @@
         * @return {wb.ui.PropertyEditTool.EditableValue}
         */
        enterNewValue: function( value ) {
-               var $siteLinksTable = this._subject;
-
-               // Attach the headers before initializing the new value in 
order to not have the license
-               // information tooltip appear in the wrong spot. (The new 
value's table row would be shifted
-               // after adding the headers.)
-               if ( this._editableValues.length === 0 ) {
-                       // This would be the first site link -> attach column 
headers.
-                       $siteLinksTable.children( 'thead' ).append(
-                               mw.template( 'wb-sitelinks-thead',
-                                       mw.message( 
'wikibase-sitelinks-sitename-columnheading' ).escaped(),
-                                       mw.message( 
'wikibase-sitelinks-siteid-columnheading' ).escaped(),
-                                       mw.message( 
'wikibase-sitelinks-link-columnheading' ).escaped()
-                               )
-                       );
-               }
+               this._initializeSiteLinksTableHeader();
 
                // Have the editableValues prototype regenerated each time a 
new value is about to be
                // entered in order to reflect any change to the set of site 
links (in the means of
@@ -162,6 +148,7 @@
 
                $( newValue ).on( 'afterStopEditing', function( event, save, 
wasPending ) {
                        if ( save ) {
+                               var $siteLinksTable = this._subject;
                                // move appended site link into the table body 
to have it included in sorting
                                this.getSubject().appendTo( 
$siteLinksTable.children( 'tbody' ) );
 
@@ -181,6 +168,34 @@
        },
 
        /**
+        * Initializes the Table of the SiteLinksTable
+        */
+       _initializeSiteLinksTableHeader: function() {
+               var $siteLinksTable = this._subject;
+
+               // Attach the headers before initializing the new value in 
order to not have the license
+               // information tooltip appear in the wrong spot. (The new 
value's table row would be shifted
+               // after adding the headers.)
+               if ( this._editableValues.length === 0 ) {
+                       var siteNameMessageKey = 
'wikibase-sitelinks-sitename-columnheading';
+
+                       // FIXME: quickfix to allow a custom site-name / 
handling for groups defined in $wgSpecialSiteLinkGroups
+                       if ( $siteLinksTable.data( 'wb-sitelinks-group' ) === 
'special' ) {
+                               siteNameMessageKey += '-special';
+                       }
+
+                       // This would be the first site link -> attach column 
headers.
+                       $siteLinksTable.children( 'thead' ).append(
+                               mw.template( 'wb-sitelinks-thead',
+                                       mw.message( siteNameMessageKey 
).escaped(),
+                                       mw.message( 
'wikibase-sitelinks-siteid-columnheading' ).escaped(),
+                                       mw.message( 
'wikibase-sitelinks-link-columnheading' ).escaped()
+                               )
+                       );
+               }
+       },
+
+       /**
         * Determines if all sites are in use.
         * @see wikibase.ui.PropertyEditTool.isFull
         *
diff --git a/repo/includes/ItemView.php b/repo/includes/ItemView.php
index ee8b9d4..e24d768 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;
@@ -44,7 +45,7 @@
         * @return string
         */
        public function getHtmlForSiteLinks( Item $item, Language $lang, 
$editable = true ) {
-               $groups = Settings::get( "siteLinkGroups" );
+               $groups = 
WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( "siteLinkGroups" 
);
                $html = '';
 
                foreach ( $groups as $group ) {
@@ -67,6 +68,8 @@
         */
        public function getHtmlForSiteLinkGroup( Item $item, $group, Language 
$lang, $editable = true ) {
                $allSiteLinks = $item->getSimpleSiteLinks();
+
+               $specialGroups = 
WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( 
"specialSiteLinkGroups" );
 
                $siteLinks = array(); // site links of the currently handled 
site group
 
@@ -94,9 +97,15 @@
                        // TODO: support entity-id as prefix for element IDs.
                );
 
+               // FIXME: quickfix to allow a custom site-name / handling for 
groups defined in $wgSpecialSiteLinkGroups
+               $siteNameMessageKey = 
'wikibase-sitelinks-sitename-columnheading';
+               if ( in_array( $group, $specialGroups ) ) {
+                       $siteNameMessageKey .= '-special';
+               }
+
                if( !empty( $siteLinks ) ) {
                        $thead = wfTemplate( 'wb-sitelinks-thead',
-                               wfMessage( 
'wikibase-sitelinks-sitename-columnheading' )->parse(),
+                               wfMessage( $siteNameMessageKey )->parse(),
                                wfMessage( 
'wikibase-sitelinks-siteid-columnheading' )->parse(),
                                wfMessage( 
'wikibase-sitelinks-link-columnheading' )->parse()
                        );
@@ -143,6 +152,14 @@
                        } 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 ( in_array( $group, $specialGroups ) ) {
+                                       $siteNameMsg = wfMessage( 
'wikibase-sitelinks-sitename-' . $site->getGlobalId() );
+                                       $siteName = $siteNameMsg->exists() ? 
$siteNameMsg->parse() : $site->getGlobalId();
+                               } 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
@@ -150,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() ),
@@ -168,12 +185,14 @@
                        $this->getHtmlForEditSection( $item, $lang, $editLink, 
'td', 'add', !$isFull )
                );
 
+               $groupName = in_array( $group, $specialGroups ) ? 'special' : 
$group;
+
                return $html . wfTemplate(
                        'wb-sitelinks-table',
                        $thead,
                        $tbody,
                        $tfoot,
-                       htmlspecialchars( $group )
+                       htmlspecialchars( $groupName )
                );
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id6ba4e138794ae2aba8d2d96bc9a1154f2c38308
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to