Daniel Werner has uploaded a new change for review.

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


Change subject: new wb.utilities.ui.buildPrettyEntityLabel and cleaned up 
message dependencies
......................................................................

new wb.utilities.ui.buildPrettyEntityLabel and cleaned up message dependencies

This introduces a new utility function wb.utilities.ui.buildPrettyEntityLabel 
which provides a nice
link to a Entity. By having this we get rid of some redundant code in 
wikibaseItem.js.
Also cleaned up some weird message dependencies and instead of using hard coded 
spaces, we now use
the 'word-separator' message.

Change-Id: I95a530f25f6c393ce2058993815feb0ec4d582cd
---
M lib/resources/Resources.php
M lib/resources/jquery.valueview.views/wikibaseItem.js
M lib/resources/wikibase.utilities/wikibase.utilities.ui.js
3 files changed, 44 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/81/53881/1

diff --git a/lib/resources/Resources.php b/lib/resources/Resources.php
index e71fc37..d65bb51 100644
--- a/lib/resources/Resources.php
+++ b/lib/resources/Resources.php
@@ -193,7 +193,11 @@
                        'messages' => array(
                                'wikibase-ui-pendingquantitycounter-nonpending',
                                'wikibase-ui-pendingquantitycounter-pending',
-                               
'wikibase-ui-pendingquantitycounter-pending-pendingsubpart'
+                               
'wikibase-ui-pendingquantitycounter-pending-pendingsubpart',
+                               'wikibase-label-empty',
+                               'wikibase-deletedentity',
+                               'word-separator',
+                               'parentheses',
                        )
                ),
 
@@ -564,10 +568,8 @@
                                'wikibase.templates',
                        ),
                        'messages' => array(
-                               'wikibase-label-empty',
-                               'parentheses',
-                               'wikibase-deletedentity',
                                'wikibase-entity-property',
+                               'wikibase.utilities'
                        )
                ),
 
@@ -613,9 +615,9 @@
                                'dataTypes.jquery.valueview',
                                'wikibase.parsers',
                                'jquery.eachchange',
+                               'wikibase.utilities',
                        ),
                        'messages' => array(
-                               'parentheses',
                                'wikibase-entity-item',
                        )
                ),
diff --git a/lib/resources/jquery.valueview.views/wikibaseItem.js 
b/lib/resources/jquery.valueview.views/wikibaseItem.js
index b3eaeef..6488764 100644
--- a/lib/resources/jquery.valueview.views/wikibaseItem.js
+++ b/lib/resources/jquery.valueview.views/wikibaseItem.js
@@ -152,17 +152,7 @@
                        if( !fetchedItem ) {
                                return wb.utilities.ui.buildMissingEntityInfo( 
itemId, wb.Item );
                        }
-
-                       var label = fetchedItem.getContent().getLabel();
-
-                       if( !label ) {
-                               return $( document.createTextNode( itemId ) 
).add(
-                                       $( '<span/>', { 'class': 
'wb-entity-undefinedinfo' } )
-                                               .text( ' ' + mw.msg( 
'parentheses', mw.msg( 'wikibase-label-empty' ) ) )
-                               );
-                       }
-
-                       return label;
+                       return wb.utilities.ui.buildPrettyEntityLabel( 
fetchedItem.getContent() );
                },
 
                /**
diff --git a/lib/resources/wikibase.utilities/wikibase.utilities.ui.js 
b/lib/resources/wikibase.utilities/wikibase.utilities.ui.js
index a6f26ba..46d0f3a 100644
--- a/lib/resources/wikibase.utilities/wikibase.utilities.ui.js
+++ b/lib/resources/wikibase.utilities/wikibase.utilities.ui.js
@@ -9,6 +9,12 @@
        'use strict';
 
        /**
+        * Just a space in the user's language.
+        * @type string
+        */
+       var SPACE = mw.msg( 'word-separator' );
+
+       /**
         * Class for toggle elements icons
         * @type {String} 'ui-icon-triangle-1-e' or 'ui-icon-triangle-1-w'
         */
@@ -114,18 +120,39 @@
        wb.utilities.ui.buildLinkToEntityPage = function( entity, url ) {
                var label = entity.getLabel();
                var $entityLink = $( '<a/>', {
-                       href: url,
-                       text: label || entity.getId()
+                       href: url
                } );
 
+               return $entityLink.append( 
wb.utilities.ui.buildPrettyEntityLabel( entity ) );
+       };
+
+       /**
+        * Creates a pretty label for an Entity. This means if the Entity 
doesn't actually have a label,
+        * some alternative information will be shown (the ID + some 
information that the label is not
+        * set).
+        *
+        * @since 0.4
+        *
+        * @param {wb.Entity} entity
+        * @return {jQuery} Construct of one or many HTML elements
+        */
+       wb.utilities.ui.buildPrettyEntityLabel = function( entity ) {
+               var label = entity.getLabel(),
+                       text = label || entity.getId() || '', // TODO: nicely 
handle new entities without ID
+                       $label = $( document.createTextNode( text ) );
+
                if( !label ) {
-                       $entityLink.append( $( '<span/>', {
+                       if( text ) { // empty if entity without ID
+                               $label[0].textContent += SPACE;
+                       }
+                       var $undefinedInfo = $( '<span/>', {
                                'class': 'wb-entity-undefinedinfo',
-                               'text': ' (' + mw.msg( 'wikibase-label-empty' ) 
+ ')'
-                       } ) );
+                               'text': mw.msg( 'parentheses', mw.msg( 
'wikibase-label-empty' ) )
+                       } );
+                       $label = $label.add( $undefinedInfo );
                }
 
-               return $entityLink;
+               return $label;
        };
 
        /**
@@ -142,15 +169,11 @@
        wb.utilities.ui.buildMissingEntityInfo = function( entityId, entityType 
) {
                entityType = typeof entityType === 'string' ? entityType : 
entityType.TYPE;
 
-               return $( '<span/>' ).text( entityId ).append(
-                       $( '<span>', { 'class': 'wb-entity-undefinedinfo' } 
).text( ' ' +
+               return $( '<span/>' ).text( entityId + SPACE ).append(
+                       $( '<span>', { 'class': 'wb-entity-undefinedinfo' } 
).text(
                                mw.msg( 'parentheses',
                                        mw.msg( 'wikibase-deletedentity',
-                                               mw.msg( 'wikibase-entity-' + 
entityType )
-                                       )
-                               )
-                       )
-               );
+                                               mw.msg( 'wikibase-entity-' + 
entityType ) ) ) ) );
 
        };
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I95a530f25f6c393ce2058993815feb0ec4d582cd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>

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

Reply via email to