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

Change subject: Always display "In other languages" section
......................................................................


Always display "In other languages" section

(bug 49079)
Now, the "In other languages" section is displayed always. If the user has no 
languages configured
using the Babel extension, ULS is queried for frequent languages filling the 
section.
In order to improve modularity along with implementing that new functionality, 
MediaWiki's hook
mechanism is used instead of using the document ready handler.

DEPLOYMENT: due to how dependencies are handled, this only works when ULS is 
loaded BEFORE wikibase is loaded.

Needs https://gerrit.wikimedia.org/r/#/c/106689/ to work properly for anon users

Change-Id: I1978e78cc170c1adb81655eda3d41246fa33f4d4
---
M repo/resources/Resources.php
M repo/resources/wikibase.ui.entityViewInit.js
A repo/resources/wikibase.ui.initEntity.js
A repo/resources/wikibase.ui.initTermBox.js
4 files changed, 233 insertions(+), 63 deletions(-)

Approvals:
  Tobias Gritschacher: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/resources/Resources.php b/repo/resources/Resources.php
index 4dfd934..11c3006 100644
--- a/repo/resources/Resources.php
+++ b/repo/resources/Resources.php
@@ -23,17 +23,16 @@
                                'wikibase.ui.entityViewInit.js' // should 
probably be adjusted for more modularity
                        ),
                        'dependencies' => array(
+                               'mediawiki.api',
                                'mediawiki.user',
                                'wikibase.ui.PropertyEditTool',
                                'jquery.wikibase.entityview',
                                'jquery.wikibase.toolbarcontroller',
                                'jquery.wikibase.wbtooltip',
-                               'wikibase.datamodel',
-                               'jquery.json',
                                'jquery.cookie',
-                               'wikibase.serialization.entities',
-                               'wikibase.serialization.fetchedcontent',
-                               'jquery.wikibase.claimgrouplabelscroll'
+                               'jquery.wikibase.claimgrouplabelscroll',
+                               'wikibase.ui.initEntity',
+                               'wikibase.ui.initTermBox',
                        ),
                        'messages' => array(
                                'wikibase-statements',
@@ -43,6 +42,39 @@
                                'wikibase-entity-property',
                                'wikibase-restrictionedit-tooltip-message',
                                'wikibase-blockeduser-tooltip-message',
+                       )
+               ),
+
+               'wikibase.ui.initEntity' => $moduleTemplate + array(
+                       'scripts' => array(
+                               'wikibase.ui.initEntity.js',
+                       ),
+                       'dependencies' => array(
+                               'jquery.json',
+                               'wikibase',
+                               'wikibase.datamodel',
+                               'wikibase.serialization',
+                               'wikibase.serialization.entities',
+                               'wikibase.serialization.fetchedcontent',
+                               'wikibase.store.FetchedContent',
+                       ),
+               ),
+
+               'wikibase.ui.initTermBox' => $moduleTemplate + array(
+                       'scripts' => array(
+                               'wikibase.ui.initTermBox.js',
+                       ),
+                       'dependencies' => array(
+                               'jquery.wikibase.toolbar',
+                               'jquery.wikibase.toolbareditgroup',
+                               'mediawiki.Title',
+                               'wikibase',
+                               'wikibase.templates',
+                               'wikibase.ui.initEntity',
+                               'wikibase.ui.PropertyEditTool',
+                       ),
+                       'messages' => array(
+                               'wikibase-terms',
                        )
                ),
 
@@ -111,6 +143,8 @@
        );
 
        if ( defined( 'ULS_VERSION' ) ) {
+               $modules['wikibase.ui.initTermBox']['dependencies'][] = 
'ext.uls.displaysettings';
+               $modules['wikibase.ui.initTermBox']['dependencies'][] = 
'jquery.uls.data';
                
$modules['wikibase.special.itemDisambiguation']['dependencies'][] = 
'jquery.uls.data';
                $modules['wikibase.special.entitiesWithout']['dependencies'][] 
= 'jquery.uls.data';
        }
diff --git a/repo/resources/wikibase.ui.entityViewInit.js 
b/repo/resources/wikibase.ui.entityViewInit.js
index 1375d30..21f1646 100644
--- a/repo/resources/wikibase.ui.entityViewInit.js
+++ b/repo/resources/wikibase.ui.entityViewInit.js
@@ -16,7 +16,8 @@
        'use strict';
        /* jshint nonew: false */
 
-       $( document ).ready( function() {
+       mw.hook( 'wikipage.content' ).add( function() {
+               // TODO: Remove global DOM adjustments
                // remove HTML edit links with links to special pages
                // for site-links we don't want to remove the table cell 
representing the edit section
                $( 'td.wb-editsection' ).empty();
@@ -25,6 +26,12 @@
 
                // remove all infos about empty values which are displayed in 
non-JS
                $( '.wb-value-empty' ).empty().removeClass( 'wb-value-empty' );
+
+               // Since the DOM is altered for the property edit tools to 
property initialize, the
+               // following hook informs about these operations having 
finished.
+               // TODO: This hook is not supposed to be permanent. Remove it 
as soon as no more global DOM
+               // adjustments are necessary.
+               mw.hook( 'wikibase.domready' ).fire();
 
                // add an edit tool for the main label. This will be integrated 
into the heading nicely:
                if ( $( '.wb-firstHeading' ).length ) { // Special pages do not 
have a custom wb heading
@@ -57,45 +64,7 @@
                        }
                } );
 
-               var termsValueTools = [];
-
-               $( 'tr.wb-terms-label, tr.wb-terms-description' ).each( 
function() {
-                       var $termsRow = $( this ),
-                               editTool = wb.ui.PropertyEditTool[
-                                       $termsRow.hasClass( 'wb-terms-label' )
-                                               ? 'EditableLabel'
-                                               : 'EditableDescription'
-                               ],
-                               $toolbar = mw.template( 'wikibase-toolbar', '', 
'' ).toolbar(),
-                               toolbar = $toolbar.data( 'toolbar' ),
-                               $editGroup = mw.template( 
'wikibase-toolbareditgroup', '', '' ).toolbareditgroup();
-
-                       toolbar.addElement( $editGroup );
-                       toolbar.$editGroup = $editGroup; // TODO: EditableLabel 
should not assume that this is set
-
-                       termsValueTools.push( editTool.newFromDom( $termsRow, 
{}, toolbar ) );
-               } );
-
                if( mw.config.get( 'wbEntity' ) !== null ) {
-                       var entityJSON = $.evalJSON( mw.config.get( 'wbEntity' 
) ),
-                               usedEntitiesJSON = $.evalJSON( mw.config.get( 
'wbUsedEntities' ) ),
-                               unserializerFactory = new 
wb.serialization.SerializerFactory(),
-                               entityUnserializer = 
unserializerFactory.newUnserializerFor( wb.Entity );
-
-                       // unserializer for fetched content whose content is a 
wb.Entity:
-                       var fetchedEntityUnserializer = 
unserializerFactory.newUnserializerFor(
-                               wb.store.FetchedContent, {
-                                       contentUnserializer: entityUnserializer
-                               }
-                       );
-
-                       wb.entity = entityUnserializer.unserialize( entityJSON 
);
-                       entityJSON = null;
-
-                       $.each( usedEntitiesJSON, function( id, 
fetchedEntityJSON ) {
-                               wb.fetchedEntities[ id ] = 
fetchedEntityUnserializer.unserialize( fetchedEntityJSON );
-                       } );
-
                        // if there are no aliases yet, the DOM structure for 
creating new ones is created manually since it is not
                        // needed for running the page without JS
                        $( '.wb-aliases-empty' )
@@ -214,18 +183,6 @@
                }
 
                $( wb ).on( 'startItemPageEditMode', function( event, origin, 
options ) {
-                       // disable language terms table's editable value or 
mark it as the active one if it is
-                       // the one being edited by the user and therefore the 
origin of the event
-                       $.each( termsValueTools, function( i, termValueTool ) {
-                               if ( !( origin instanceof 
wb.ui.PropertyEditTool.EditableValue )
-                                       || origin.getSubject() !== 
termValueTool.getSubject()
-                               ) {
-                                       termValueTool.disable();
-                               } else if ( origin && origin.getSubject() === 
termValueTool.getSubject() ) {
-                                       $( 'table.wb-terms' ).addClass( 
'wb-edit' );
-                               }
-                       } );
-
                        // Display anonymous user edit warning:
                        if ( mw.user && mw.user.isAnon()
                                && $.find( '.mw-notification-content' ).length 
=== 0
@@ -326,13 +283,6 @@
                                        $messageAnchor.data( 'wbtooltip' 
).degrade( true );
                                } );
                        }
-               } );
-
-               $( wb ).on( 'stopItemPageEditMode', function( event ) {
-                       $( 'table.wb-terms' ).removeClass( 'wb-edit' );
-                       $.each( termsValueTools, function( i, termValueTool ) {
-                               termValueTool.enable();
-                       } );
                } );
 
                // remove loading spinner after JavaScript has kicked in
diff --git a/repo/resources/wikibase.ui.initEntity.js 
b/repo/resources/wikibase.ui.initEntity.js
new file mode 100644
index 0000000..c1ae20d
--- /dev/null
+++ b/repo/resources/wikibase.ui.initEntity.js
@@ -0,0 +1,38 @@
+/**
+ * Entity initialization.
+ * Unserializes the entities passed to JavaScript via mw.config variables.
+ * @since 0.5
+ * @licence GNU GPL v2+
+ *
+ * @author: H. Snater < mediaw...@snater.com >
+ */
+( function( $, mw, wb ) {
+       'use strict';
+
+       mw.hook( 'wikipage.content' ).add( function() {
+
+               if( mw.config.get( 'wbEntity' ) === null ) {
+                       return;
+               }
+
+               var entityJSON = $.evalJSON( mw.config.get( 'wbEntity' ) ),
+                       usedEntitiesJSON = $.evalJSON( mw.config.get( 
'wbUsedEntities' ) ),
+                       unserializerFactory = new 
wb.serialization.SerializerFactory(),
+                       entityUnserializer = 
unserializerFactory.newUnserializerFor( wb.Entity );
+
+               // Unserializer for fetched content whose content is a 
wb.Entity:
+               var fetchedEntityUnserializer = 
unserializerFactory.newUnserializerFor(
+                       wb.store.FetchedContent,
+                       { contentUnserializer: entityUnserializer }
+               );
+
+               wb.entity = entityUnserializer.unserialize( entityJSON );
+               entityJSON = null;
+
+               $.each( usedEntitiesJSON, function( id, fetchedEntityJSON ) {
+                       wb.fetchedEntities[id] = 
fetchedEntityUnserializer.unserialize( fetchedEntityJSON );
+               } );
+
+       } );
+
+} )( jQuery, mediaWiki, wikibase );
\ No newline at end of file
diff --git a/repo/resources/wikibase.ui.initTermBox.js 
b/repo/resources/wikibase.ui.initTermBox.js
new file mode 100644
index 0000000..79ced99
--- /dev/null
+++ b/repo/resources/wikibase.ui.initTermBox.js
@@ -0,0 +1,148 @@
+/**
+ * Term box initialisation.
+ * The term box displays label and description in languages other than the 
user language.
+ * @since 0.5
+ * @licence GNU GPL v2+
+ *
+ * @author: H. Snater < mediaw...@snater.com >
+ */
+( function( $, mw, wb ) {
+       'use strict';
+
+       mw.hook( 'wikibase.domready' ).add( function() {
+               var termsValueTools = [],
+                       $termBoxRows = $( 'tr.wb-terms-label, 
tr.wb-terms-description' ),
+                       ulsIsDefined = mw.uls !== undefined && $.uls !== 
undefined && $.uls.data !== undefined;
+
+               if( $termBoxRows.length === 0 && ulsIsDefined ) {
+                       // No term box present; Ask ULS to provide languages 
and generate plain HTML:
+                       var languageCodes = mw.uls.getFrequentLanguageList(),
+                               title = new mw.Title(
+                                       mw.config.get( 'wgTitle' ),
+                                       mw.config.get( 'wgNamespaceNumber' )
+                               );
+
+                       if( languageCodes.length === 0 ) {
+                               return;
+                       }
+
+                       var $sectionHeading = addTermBoxSection();
+                       $sectionHeading.after( renderTermBox( title, wb.entity, 
languageCodes.slice( 1, 4 ) ) );
+
+                       $termBoxRows = $( 'tr.wb-terms-label, 
tr.wb-terms-description' );
+               }
+
+               $termBoxRows.each( function() {
+                       var $termsRow = $( this ),
+                               editTool = wb.ui.PropertyEditTool[
+                                       $termsRow.hasClass( 'wb-terms-label' ) 
? 'EditableLabel' : 'EditableDescription'
+                               ],
+                               $toolbar = mw.template( 'wikibase-toolbar', '', 
'' ).toolbar(),
+                               toolbar = $toolbar.data( 'toolbar' ),
+                               $editGroup = mw.template( 
'wikibase-toolbareditgroup', '', '' ).toolbareditgroup();
+
+                       toolbar.addElement( $editGroup );
+
+                       // TODO: EditableLabel should not assume that this is 
set:
+                       toolbar.$editGroup = $editGroup;
+
+                       termsValueTools.push( editTool.newFromDom( $termsRow, 
{}, toolbar ) );
+               } );
+
+               $( wb )
+               .on( 'startItemPageEditMode', function( event, origin, options 
) {
+                       // disable language terms table's editable value or 
mark it as the active one if it is
+                       // the one being edited by the user and therefore the 
origin of the event
+                       $.each( termsValueTools, function( i, termValueTool ) {
+                               if(
+                                       !( origin instanceof 
wb.ui.PropertyEditTool.EditableValue )
+                                       || origin.getSubject() !== 
termValueTool.getSubject()
+                               ) {
+                                       termValueTool.disable();
+                               } else if( origin && origin.getSubject() === 
termValueTool.getSubject() ) {
+                                       $( 'table.wb-terms' ).addClass( 
'wb-edit' );
+                               }
+                       } );
+               } )
+               .on( 'stopItemPageEditMode', function( event ) {
+                       $( 'table.wb-terms' ).removeClass( 'wb-edit' );
+                       $.each( termsValueTools, function( i, termValueTool ) {
+                               termValueTool.enable();
+                       } );
+               } );
+
+       } );
+
+       /**
+        * @return {jQuery}
+        */
+       function addTermBoxSection() {
+               var $sectionHeading = mw.template( 'wb-terms-heading', mw.msg( 
'wikibase-terms' ) ),
+                       $toc = $( '#toc' ),
+                       $precedingNode;
+
+               if( $toc.length > 0 ) {
+                       $toc
+                       .children( 'ul' ).prepend(
+                               $( '<li/>' )
+                               .addClass( 'toclevel-1' )
+                               .append(
+                                       $( '<a/>' )
+                                       .attr( 'href', '#wb-terms' )
+                                       .text( mw.msg( 'wikibase-terms' ) )
+                               )
+                       )
+                       .find( 'li' ).each( function( i, li ) {
+                               $( li )
+                               .removeClass( 'tocsection-' + i )
+                               .addClass( 'tocsection-' + ( i + 1 ) );
+                       } );
+
+                       $precedingNode = $toc;
+               } else {
+                       $precedingNode = $( '.wb-aliases' );
+               }
+
+               $precedingNode.after( $sectionHeading );
+
+               return $sectionHeading;
+       }
+
+       /**
+        * @param {mediaWiki.Title} title
+        * @param {wikibase.Entity} entity
+        * @param {string[]} languageCodes
+        * @return {jQuery|undefined}
+        */
+       function renderTermBox( title, entity, languageCodes ) {
+               if( languageCodes === undefined ) {
+                       return;
+               }
+               var labels = entity.getLabels(),
+                       descriptions = entity.getDescriptions(),
+                       rowNumber = 0,
+                       $tbody = $( '<tbody/>' );
+
+               for( var i = 0; i < languageCodes.length; i++ ) {
+                       var languageCode = languageCodes[i],
+                               alternatingClass = ( rowNumber++ % 2 ) ? 'even' 
: 'uneven';
+
+                       $tbody.append( mw.template( 'wb-term',
+                               languageCode,
+                               alternatingClass,
+                               $.uls.data.getAutonym( languageCode ),
+                               ( labels[languageCode] !== undefined ) ? 
labels[languageCode] : '',
+                               ( descriptions[languageCode] !== undefined ) ? 
descriptions[languageCode] : '',
+                               '',
+                               '',
+                               '',
+                               '',
+                               title.getUrl() + '?setlang=' + languageCode
+                       ) );
+               }
+
+               return mw.template( 'wb-terms-table', $tbody );
+       }
+
+
+} )( jQuery, mediaWiki, wikibase );
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1978e78cc170c1adb81655eda3d41246fa33f4d4
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de>
Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to