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

Change subject: Sanitized entity initialization
......................................................................


Sanitized entity initialization

Sanitizes change Iab129054fef513bbdfbb8a8322103f2de26a4b60.

Change-Id: I217d6d915479ee2beb58ab2bf33291e61d2e9c48
---
M repo/resources/Resources.php
M repo/resources/wikibase.EntityInitializer.js
M repo/resources/wikibase.ui.entityViewInit.js
M repo/resources/wikibase.ui.initTermBox.js
4 files changed, 153 insertions(+), 91 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/resources/Resources.php b/repo/resources/Resources.php
index 1414964..542b592 100644
--- a/repo/resources/Resources.php
+++ b/repo/resources/Resources.php
@@ -66,6 +66,10 @@
                                'wikibase',
                                'wikibase.datamodel',
                                'wikibase.serialization',
+                               // FIXME: Resolve implicitly required 
wikibase.serialization.entities dependency.
+                               // wikibase.serialization.entities 
self-registers to the SerializerFactory provided
+                               // by wikibase.serialization which is why 
wikibase.serialization.entities is
+                               // implicitly required as dependency.
                                'wikibase.serialization.entities',
                        ),
                ),
diff --git a/repo/resources/wikibase.EntityInitializer.js 
b/repo/resources/wikibase.EntityInitializer.js
index d5cc397..24b4bac 100644
--- a/repo/resources/wikibase.EntityInitializer.js
+++ b/repo/resources/wikibase.EntityInitializer.js
@@ -1,62 +1,97 @@
 /**
- * Entity initialization.
- * Unserializes the entity passed to JavaScript via mw.config variable.
- * @since 0.5
  * @licence GNU GPL v2+
  *
+ * @author Adrian Lang <adrian.l...@wikimedia.de>
  * @author: H. Snater < mediaw...@snater.com >
  */
-( function( $, mw, wb, undefined ) {
+( function( $, mw, wb ) {
        'use strict';
 
+       /**
+        * Entity initializer.
+        * Unserializes the entity passed to JavaScript via mw.config variable.
+        * @constructor
+        * @since 0.5
+        *
+        * @param {string} configVarName
+        *
+        * @throws {Error} if required parameter is not specified properly.
+        */
        var EntityInitializer = wb.EntityInitializer = function( configVarName 
) {
+               if( typeof configVarName !== 'string' ) {
+                       throw new Error( 'Config variable name needs to be 
specified' );
+               }
                this._configVarName = configVarName;
        };
 
        $.extend( EntityInitializer.prototype, {
-
+               /**
+                * Name of the mw.config variable featuring the serialized 
entity.
+                * @type {string}
+                */
                _configVarName: null,
 
-               _value: undefined,
+               /**
+                * @type {wikibase.datamodel.Entity|null}
+                */
+               _value: null,
 
+               /**
+                * Retrieves an entity from mw.config.
+                *
+                * @return {Object} jQuery Promise
+                *         Resolved parameters:
+                *         - {wikibase.datamodel.Entity}
+                *         No rejected parameters.
+                */
                getEntity: function() {
-                       var self = this;
-                       var promise = $.Deferred();
+                       var self = this,
+                               deferred = $.Deferred();
 
-                       if( typeof this._value === 'undefined' ){
-                               this._getFromConfig().done( function( value ) {
-                                       self._value = value;
-                                       promise.resolve( self._value );
-                               } ).fail( $.proxy( promise.reject, promise ) );
-                       } else {
-                               promise.resolve( this._value );
+                       if( this._value ) {
+                               return deferred.resolve( this._value 
).promise();
                        }
 
-                       return promise;
+                       this._getFromConfig()
+                       .done( function( value ) {
+                               self._value = value;
+                               deferred.resolve( self._value );
+                       } )
+                       .fail( $.proxy( deferred.reject, deferred ) );
+
+                       return deferred.promise();
                },
 
+               /**
+                * @return {Object} jQuery promise
+                *         Resolved parameters:
+                *         - {wikibase.datamodel.Entity}
+                *         No rejected parameters.
+                */
                _getFromConfig: function() {
-                       var self = this;
-                       var promise = $.Deferred();
+                       var self = this,
+                               deferred = $.Deferred();
 
                        mw.hook( 'wikipage.content' ).add( function() {
                                var serializedEntity = mw.config.get( 
self._configVarName );
 
                                if( serializedEntity === null ) {
-                                       promise.reject();
+                                       deferred.reject();
                                        return;
                                }
 
                                var entityJSON = JSON.parse( serializedEntity ),
                                        unserializerFactory = new 
wb.serialization.SerializerFactory(),
-                                       entityUnserializer = 
unserializerFactory.newUnserializerFor( wb.datamodel.Entity );
+                                       entityUnserializer = 
unserializerFactory.newUnserializerFor(
+                                               wb.datamodel.Entity
+                                       );
 
-                               promise.resolve( 
entityUnserializer.unserialize( entityJSON ) );
+                               deferred.resolve( 
entityUnserializer.unserialize( entityJSON ) );
                                entityJSON = null;
                        } );
 
-                       return promise;
+                       return deferred.promise();
                }
        } );
 
-} )( jQuery, mediaWiki, wikibase, void 0 );
+} )( jQuery, mediaWiki, wikibase );
diff --git a/repo/resources/wikibase.ui.entityViewInit.js 
b/repo/resources/wikibase.ui.entityViewInit.js
index 2f25e9e..69b7a18 100644
--- a/repo/resources/wikibase.ui.entityViewInit.js
+++ b/repo/resources/wikibase.ui.entityViewInit.js
@@ -108,64 +108,7 @@
                        var entityInitializer = new wb.EntityInitializer( 
'wbEntity' );
 
                        entityInitializer.getEntity().done( function( entity ) {
-                               // FIXME: Initializing entityview on $claims 
leads to the claim section inserted as
-                               // child of $claims. It should be direct child 
of ".wb-entity".
-                               var abstractedRepoApi = new 
wb.AbstractedRepoApi();
-                               var entityStore = new wb.store.EntityStore( 
abstractedRepoApi );
-                               wb.compileEntityStoreFromMwConfig( entityStore 
);
-
-                               // FIXME: Initializing entityview on $claims 
leads to the claim section inserted as
-                               // child of $claims. It should be direct child 
of ".wb-entity".
-                               $claims.entityview( {
-                                       value: entity,
-                                       entityStore: entityStore,
-                                       valueViewBuilder: new 
wb.ValueViewBuilder(
-                                               experts,
-                                               getFormatterStore( repoApi, 
dataTypes ),
-                                               getParserStore( repoApi ),
-                                               mw
-                                       )
-                               } ).appendTo( $claimsParent );
-
-                               // This is here to be sure there is never a 
duplicate id
-                               $( '.wb-claimgrouplistview' )
-                                       .prev( '.wb-section-heading' )
-                                       .first()
-                                       .attr( 'id', 'claims' );
-
-                               // removing site links heading to rebuild it 
with value counter
-                               $( 'table.wb-sitelinks' ).each( function() {
-                                       var group = $( this ).data( 
'wb-sitelinks-group' ),
-                                               $sitesCounterContainer = $( 
'<span/>' );
-
-                                       $( this ).prev().append( 
$sitesCounterContainer );
-
-                                       // actual initialization
-                                       new wb.ui.SiteLinksEditTool( $( this ), 
{
-                                               allowedSites: 
wb.sites.getSitesOfGroup( group ),
-                                               counterContainers: 
$sitesCounterContainer,
-                                               api: repoApi
-                                       } );
-                               } );
-
-                               $( '.wb-entity' ).claimgrouplabelscroll();
-
-                               $( wb ).on( 'startItemPageEditMode', function( 
event, origin, options ) {
-                                       // Display anonymous user edit warning:
-                                       if ( mw.user && mw.user.isAnon()
-                                               && $.find( 
'.mw-notification-content' ).length === 0
-                                               && !$.cookie( 
'wikibase-no-anonymouseditwarning' )
-                                       ) {
-                                               mw.notify(
-                                                       mw.msg( 
'wikibase-anonymouseditwarning',
-                                                               mw.msg( 
'wikibase-entity-' + entity.getType() )
-                                                       )
-                                               );
-                                       }
-                               } );
-
-                               wb.ui.initTermBox( entity, repoApi );
-
+                               createEntityDom( entity, $claims, 
$claimsParent, repoApi );
                        } );
                }
 
@@ -337,6 +280,74 @@
 
        } );
 
+       /**
+        * Creates the entity DOM structure.
+        *
+        * @param {wikibase.datamodel.Entity} entity
+        * @param {jQuery} $claims
+        * @param {jQuery} $claimsParent
+        * @param {wikibase.RepoApi} repoApi
+        */
+       function createEntityDom( entity, $claims, $claimsParent, repoApi ) {
+               // FIXME: Initializing entityview on $claims leads to the claim 
section inserted as
+               // child of $claims. It should be direct child of ".wb-entity".
+               var abstractedRepoApi = new wb.AbstractedRepoApi();
+               var entityStore = new wb.store.EntityStore( abstractedRepoApi );
+               wb.compileEntityStoreFromMwConfig( entityStore );
+
+               // FIXME: Initializing entityview on $claims leads to the claim 
section inserted as
+               // child of $claims. It should be direct child of ".wb-entity".
+               $claims.entityview( {
+                       value: entity,
+                       entityStore: entityStore,
+                       valueViewBuilder: new wb.ValueViewBuilder(
+                               experts,
+                               getFormatterStore( repoApi, dataTypes ),
+                               getParserStore( repoApi ),
+                               mw
+                       )
+               } ).appendTo( $claimsParent );
+
+               // This is here to be sure there is never a duplicate id
+               $( '.wb-claimgrouplistview' )
+                       .prev( '.wb-section-heading' )
+                       .first()
+                       .attr( 'id', 'claims' );
+
+               // removing site links heading to rebuild it with value counter
+               $( 'table.wb-sitelinks' ).each( function() {
+                       var group = $( this ).data( 'wb-sitelinks-group' ),
+                               $sitesCounterContainer = $( '<span/>' );
+
+                       $( this ).prev().append( $sitesCounterContainer );
+
+                       // actual initialization
+                       new wb.ui.SiteLinksEditTool( $( this ), {
+                               allowedSites: wb.sites.getSitesOfGroup( group ),
+                               counterContainers: $sitesCounterContainer,
+                               api: repoApi
+                       } );
+               } );
+
+               $( '.wb-entity' ).claimgrouplabelscroll();
+
+               $( wb ).on( 'startItemPageEditMode', function( event, origin, 
options ) {
+                       // Display anonymous user edit warning:
+                       if ( mw.user && mw.user.isAnon()
+                               && $.find( '.mw-notification-content' ).length 
=== 0
+                               && !$.cookie( 
'wikibase-no-anonymouseditwarning' )
+                       ) {
+                               mw.notify(
+                                       mw.msg( 'wikibase-anonymouseditwarning',
+                                               mw.msg( 'wikibase-entity-' + 
entity.getType() )
+                                       )
+                               );
+                       }
+               } );
+
+               wb.ui.initTermBox( entity, repoApi );
+       }
+
 } )(
        jQuery,
        mediaWiki,
diff --git a/repo/resources/wikibase.ui.initTermBox.js 
b/repo/resources/wikibase.ui.initTermBox.js
index 62db400..aebd478 100644
--- a/repo/resources/wikibase.ui.initTermBox.js
+++ b/repo/resources/wikibase.ui.initTermBox.js
@@ -1,7 +1,4 @@
 /**
- * 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 >
@@ -9,13 +6,23 @@
 ( function( $, mw, wb ) {
        'use strict';
 
+       /**
+        * Term box initialization.
+        * The term box displays label and description in languages other than 
the user language.
+        * @since 0.5
+        *
+        * @param {wikibase.datamodel.Entity} entity
+        * @param {wikibase.RepoApi} api
+        */
        wb.ui.initTermBox = function( entity, api ) {
                mw.hook( 'wikibase.domready' ).add( function() {
                        var termsValueTools = [],
                                $termBoxRows = $( 'tr.wb-terms-label, 
tr.wb-terms-description' ),
                                userSpecifiedLanguages = mw.config.get( 
'wbUserSpecifiedLanguages' ),
                                hasSpecifiedLanguages = userSpecifiedLanguages 
&& userSpecifiedLanguages.length,
-                               isUlsDefined = mw.uls !== undefined && $.uls 
!== undefined && $.uls.data !== undefined;
+                               isUlsDefined = mw.uls !== undefined
+                                       && $.uls !== undefined
+                                       && $.uls.data !== undefined;
 
                        // Skip if having no extra languages is what the user 
wants
                        if( !$termBoxRows.length && !hasSpecifiedLanguages && 
isUlsDefined ) {
@@ -31,7 +38,9 @@
                                }
 
                                var $sectionHeading = addTermBoxSection();
-                               $sectionHeading.after( renderTermBox( title, 
entity, languageCodes.slice( 1, 4 ) ) );
+                               $sectionHeading.after(
+                                       renderTermBox( title, entity, 
languageCodes.slice( 1, 4 ) )
+                               );
 
                                $termBoxRows = $( 'tr.wb-terms-label, 
tr.wb-terms-description' );
                        }
@@ -39,11 +48,14 @@
                        $termBoxRows.each( function() {
                                var $termsRow = $( this ),
                                        editTool = wb.ui.PropertyEditTool[
-                                               $termsRow.hasClass( 
'wb-terms-label' ) ? 'EditableLabel' : 'EditableDescription'
+                                               $termsRow.hasClass( 
'wb-terms-label' )
+                                                       ? 'EditableLabel'
+                                                       : 'EditableDescription'
                                        ],
                                        $toolbar = mw.template( 
'wikibase-toolbar', '', '' ).toolbar(),
                                        toolbar = $toolbar.data( 'toolbar' ),
-                                       $editGroup = mw.template( 
'wikibase-toolbareditgroup', '', '' ).toolbareditgroup();
+                                       $editGroup = mw.template( 
'wikibase-toolbareditgroup', '', '' )
+                                               .toolbareditgroup();
 
                                toolbar.addElement( $editGroup );
 
@@ -57,8 +69,8 @@
 
                        $( wb )
                        .on( 'startItemPageEditMode', function( event, origin ) 
{
-                               // 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
+                               // 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 )
@@ -117,7 +129,7 @@
 
        /**
         * @param {mediaWiki.Title} title
-        * @param {wb.datamodel.Entity} entity
+        * @param {wikibase.datamodel.Entity} entity
         * @param {string[]} languageCodes
         * @return {jQuery|undefined}
         */

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I217d6d915479ee2beb58ab2bf33291e61d2e9c48
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: WikidataJenkins <wikidata-servi...@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