Henning Snater has submitted this change and it was merged.

Change subject: (bug 46383) correct constructor fields for prototypes not using 
wb.utilities.inherit
......................................................................


(bug 46383) correct constructor fields for prototypes not using 
wb.utilities.inherit

Since the object literal was used for those constructors prototypes, the 
original prototype's
"constructor" field has not been there. Now we extend the original prototype 
(which is also
just a plain object with the "constructor" field set) instead of overwriting it.
Also did some renaming and general cleanup around the constructors.

Change-Id: Ied01e553d16dd0b161fa97ea25d33d9f4efd0447
---
M lib/resources/jquery.wikibase/jquery.wikibase.snakview/snakview.ViewState.js
M 
lib/resources/jquery.wikibase/jquery.wikibase.snakview/snakview.variations.Variation.js
M lib/resources/wikibase.datamodel/datamodel.entities/wikibase.Entity.js
M lib/resources/wikibase.datamodel/wikibase.Claim.js
M lib/resources/wikibase.datamodel/wikibase.PropertyNoValueSnak.js
M lib/resources/wikibase.datamodel/wikibase.PropertySomeValueSnak.js
M lib/resources/wikibase.datamodel/wikibase.PropertyValueSnak.js
M lib/resources/wikibase.datamodel/wikibase.Reference.js
M lib/resources/wikibase.datamodel/wikibase.Snak.js
M lib/resources/wikibase.datamodel/wikibase.SnakList.js
M lib/resources/wikibase.datamodel/wikibase.Statement.js
M lib/resources/wikibase.serialization/serialization.Serializer.js
M lib/resources/wikibase.serialization/serialization.Unserializer.js
13 files changed, 63 insertions(+), 64 deletions(-)

Approvals:
  Henning Snater: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git 
a/lib/resources/jquery.wikibase/jquery.wikibase.snakview/snakview.ViewState.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.snakview/snakview.ViewState.js
index 8b98cb4..ab85ff5 100644
--- 
a/lib/resources/jquery.wikibase/jquery.wikibase.snakview/snakview.ViewState.js
+++ 
b/lib/resources/jquery.wikibase/jquery.wikibase.snakview/snakview.ViewState.js
@@ -25,7 +25,7 @@
                }
                this._view = snakView;
        };
-       SELF.prototype = {
+       $.extend( SELF.prototype, {
                /**
                 * The widget object whose status is represented.
                 * @type jQuery.wikibase.snakview
@@ -69,6 +69,6 @@
                isDisabled: function() {
                        return this._view.isDisabled();
                }
-       };
+       } );
 
 }( mediaWiki, wikibase, jQuery ) );
diff --git 
a/lib/resources/jquery.wikibase/jquery.wikibase.snakview/snakview.variations.Variation.js
 
b/lib/resources/jquery.wikibase/jquery.wikibase.snakview/snakview.variations.Variation.js
index a3863bd..97f8cf0 100644
--- 
a/lib/resources/jquery.wikibase/jquery.wikibase.snakview/snakview.variations.Variation.js
+++ 
b/lib/resources/jquery.wikibase/jquery.wikibase.snakview/snakview.variations.Variation.js
@@ -45,7 +45,7 @@
 
                this._init();
        };
-       SELF.prototype = {
+       $.extend( SELF.prototype, {
                /**
                 * A unique class for this variation. Will be set by the 
variations factory when creating a
                 * new variation definition.
@@ -173,6 +173,6 @@
                 * @since 0.4
                 */
                blur: function() {}
-       };
+       } );
 
 }( mediaWiki, wikibase, jQuery ) );
diff --git 
a/lib/resources/wikibase.datamodel/datamodel.entities/wikibase.Entity.js 
b/lib/resources/wikibase.datamodel/datamodel.entities/wikibase.Entity.js
index 58fb00f..5b264af 100644
--- a/lib/resources/wikibase.datamodel/datamodel.entities/wikibase.Entity.js
+++ b/lib/resources/wikibase.datamodel/datamodel.entities/wikibase.Entity.js
@@ -159,7 +159,7 @@
                return fields1length === fields2length;
        }
 
-       SELF.prototype = {
+       $.extend( SELF.prototype, {
                /**
                 * Internal representation of the object.
                 * @type Object
@@ -367,7 +367,7 @@
                        map.type = this.getType();
                        return map;
                }
-       };
+       } );
 
        /**
         * Creates a new Entity Object from a given Object with certain keys 
and values, what an actual
diff --git a/lib/resources/wikibase.datamodel/wikibase.Claim.js 
b/lib/resources/wikibase.datamodel/wikibase.Claim.js
index 6c542ac..d599a5b 100644
--- a/lib/resources/wikibase.datamodel/wikibase.Claim.js
+++ b/lib/resources/wikibase.datamodel/wikibase.Claim.js
@@ -2,7 +2,7 @@
  * @file
  * @ingroup WikibaseLib
  * @licence GNU GPL v2+
- * @author Daniel Werner
+ * @author Daniel Werner < daniel.wer...@wikimedia.de >
  */
 ( function( wb, $ ) {
 'use strict';
@@ -18,13 +18,20 @@
  * @param {String|null} [guid] The Global Unique Identifier of this Claim. Can 
be omitted or null
  *        if this is a new Claim, not yet stored in the database and 
associated with some entity.
  */
-wb.Claim = function WbClaim( mainSnak, qualifiers, guid ) {
+var SELF = wb.Claim = function WbClaim( mainSnak, qualifiers, guid ) {
        this.setMainSnak( mainSnak );
        this.setQualifiers( qualifiers || new wb.SnakList() );
        this._guid = guid || null;
 };
 
-wb.Claim.prototype = {
+/**
+ * String to identify if the object is a statement or a claim.
+ * @since 0.4
+ * @type {string}
+ */
+SELF.TYPE = 'claim';
+
+$.extend( SELF.prototype, {
        /**
         * @type wb.Snak
         */
@@ -120,7 +127,7 @@
         */
        toJSON: function() {
                var json = {
-                       type: wb.Claim.TYPE,
+                       type: this.constructor.TYPE,
                        mainsnak: this._mainSnak.toJSON()
                };
 
@@ -134,15 +141,15 @@
 
                return json;
        }
-};
+} );
 
 /**
  * Creates a new Claim object from a given JSON structure.
  *
- * @param {String} json
+ * @param {Object} json
  * @return {wb.Claim}
  */
-wb.Claim.newFromJSON = function( json ) {
+SELF.newFromJSON = function( json ) {
        var mainSnak = wb.Snak.newFromJSON( json.mainsnak ),
                qualifiers = new wb.SnakList(),
                references = [],
@@ -168,12 +175,5 @@
        }
        return new wb.Claim( mainSnak, qualifiers, guid );
 };
-
-/**
- * String to identify if the object is a statement or a claim.
- * @since 0.4
- * @type {string}
- */
-wb.Claim.TYPE = 'claim';
 
 }( wikibase, jQuery ) );
diff --git a/lib/resources/wikibase.datamodel/wikibase.PropertyNoValueSnak.js 
b/lib/resources/wikibase.datamodel/wikibase.PropertyNoValueSnak.js
index fd4d03d..013909d 100644
--- a/lib/resources/wikibase.datamodel/wikibase.PropertyNoValueSnak.js
+++ b/lib/resources/wikibase.datamodel/wikibase.PropertyNoValueSnak.js
@@ -2,9 +2,9 @@
  * @file
  * @ingroup WikibaseLib
  * @licence GNU GPL v2+
- * @author Daniel Werner
+ * @author Daniel Werner < daniel.wer...@wikimedia.de >
  */
-( function( wb, $, undefined ) {
+( function( wb, $ ) {
 'use strict';
 
 var PARENT = wb.Snak;
@@ -18,12 +18,12 @@
  *
  * @param {Number} propertyId
  */
-wb.PropertyNoValueSnak = wb.utilities.inherit( 'WbPropertyNoValueSnak', 
PARENT, {} );
+var SELF = wb.PropertyNoValueSnak = wb.utilities.inherit( 
'WbPropertyNoValueSnak', PARENT, {} );
 
 /**
  * @see wb.Snak.TYPE
  * @type String
  */
-wb.PropertyNoValueSnak.TYPE = 'novalue';
+SELF.TYPE = 'novalue';
 
 }( wikibase, jQuery ) );
diff --git a/lib/resources/wikibase.datamodel/wikibase.PropertySomeValueSnak.js 
b/lib/resources/wikibase.datamodel/wikibase.PropertySomeValueSnak.js
index ff79cab..8dd531a 100644
--- a/lib/resources/wikibase.datamodel/wikibase.PropertySomeValueSnak.js
+++ b/lib/resources/wikibase.datamodel/wikibase.PropertySomeValueSnak.js
@@ -4,7 +4,7 @@
  * @licence GNU GPL v2+
  * @author Daniel Werner
  */
-( function( wb, $, undefined ) {
+( function( wb, $ ) {
 'use strict';
 
 var PARENT = wb.Snak;
@@ -19,12 +19,12 @@
  * @param {Number} propertyId
  * @param {dataValues.Value} value
  */
-wb.PropertySomeValueSnak = wb.utilities.inherit( 'WbPropertySomeValueSnak', 
PARENT, {} );
+var SELF = wb.PropertySomeValueSnak = wb.utilities.inherit( 
'WbPropertySomeValueSnak', PARENT, {} );
 
 /**
  * @see wb.Snak.TYPE
  * @type String
  */
-wb.PropertySomeValueSnak.TYPE = 'somevalue';
+SELF.TYPE = 'somevalue';
 
 }( wikibase, jQuery ) );
\ No newline at end of file
diff --git a/lib/resources/wikibase.datamodel/wikibase.PropertyValueSnak.js 
b/lib/resources/wikibase.datamodel/wikibase.PropertyValueSnak.js
index 8a3cc34..3a66a0d 100644
--- a/lib/resources/wikibase.datamodel/wikibase.PropertyValueSnak.js
+++ b/lib/resources/wikibase.datamodel/wikibase.PropertyValueSnak.js
@@ -4,7 +4,7 @@
  * @licence GNU GPL v2+
  * @author Daniel Werner
  */
-( function( wb, dv, $, undefined ) {
+( function( wb, dv, $ ) {
 'use strict';
 
 var PARENT = wb.Snak,
@@ -26,7 +26,7 @@
  * @param {Number} propertyId
  * @param {dv.DataValue} value
  */
-wb.PropertyValueSnak = wb.utilities.inherit( 'WbPropertyValueSnak', PARENT, 
constructor, {
+var SELF = wb.PropertyValueSnak = wb.utilities.inherit( 'WbPropertyValueSnak', 
PARENT, constructor, {
        /**
         * @type dv.DataValue
         */
@@ -83,6 +83,6 @@
 /**
  * @see wb.Snak.TYPE
  */
-wb.PropertyValueSnak.TYPE = 'value';
+SELF.TYPE = 'value';
 
 }( wikibase, dataValues, jQuery ) );
diff --git a/lib/resources/wikibase.datamodel/wikibase.Reference.js 
b/lib/resources/wikibase.datamodel/wikibase.Reference.js
index 8d3f34d..6c08a7a 100644
--- a/lib/resources/wikibase.datamodel/wikibase.Reference.js
+++ b/lib/resources/wikibase.datamodel/wikibase.Reference.js
@@ -3,8 +3,9 @@
  * @ingroup WikibaseLib
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < jeroended...@gmail.com >
+ * @author Daniel Werner < daniel.wer...@wikimedia.de >
  */
-( function( wb, $, undefined ) {
+( function( wb, $ ) {
        'use strict';
 
        /**
@@ -22,12 +23,12 @@
         * TODO: get rid of 'hash' parameter and introduce a method to generate 
the hash, but make sure
         *       it will be the same as it would be for a Reference in PHP.
         */
-       wb.Reference = function WbReference( snaks, hash ) {
+       var SELF = wb.Reference = function WbReference( snaks, hash ) {
                this.setSnaks( snaks );
                this._hash = hash;
        };
 
-       wb.Reference.prototype = {
+       $.extend( SELF.prototype, {
                /**
                 * @type string|null
                 */
@@ -95,11 +96,10 @@
 
                        return json;
                }
+       } );
 
-       };
-
-       wb.Reference.newFromJSON = function( json ) {
-               return new wb.Reference(
+       SELF.newFromJSON = function( json ) {
+               return new SELF(
                        wb.SnakList.newFromJSON( json.snaks ),
                        json.hash
                );
diff --git a/lib/resources/wikibase.datamodel/wikibase.Snak.js 
b/lib/resources/wikibase.datamodel/wikibase.Snak.js
index 6016c97..960c76c 100644
--- a/lib/resources/wikibase.datamodel/wikibase.Snak.js
+++ b/lib/resources/wikibase.datamodel/wikibase.Snak.js
@@ -2,9 +2,9 @@
  * @file
  * @ingroup WikibaseLib
  * @licence GNU GPL v2+
- * @author Daniel Werner
+ * @author Daniel Werner < daniel.wer...@wikimedia.de >
  */
-( function( wb, dv, $, undefined ) {
+( function( wb, dv, $ ) {
 'use strict';
 
 /**
@@ -16,7 +16,7 @@
  *
  * @param {String} propertyId
  */
-wb.Snak = function WbSnak( propertyId ) {
+var SELF = wb.Snak = function WbSnak( propertyId ) {
        // check whether the Snak has a type, doesn't make sense to create an 
instance of wb.Snak!
        if( !this.constructor.TYPE ) {
                throw new Error( 'Can not create abstract Snak of no specific 
type' );
@@ -32,9 +32,9 @@
  * @since 0.3
  * @type String
  */
-wb.Snak.TYPE = null;
+SELF.TYPE = null;
 
-wb.Snak.prototype = {
+$.extend( SELF.prototype, {
        /**
         * @type Number
         */
@@ -105,7 +105,7 @@
                        property: this.getPropertyId()
                };
        }
-};
+} );
 
 // TODO: make newFromJSON and newFromMap abstract factories with registration 
for new Snak types!
 /**
@@ -114,7 +114,7 @@
  * @param {String} json
  * @return wb.Snak|null
  */
-wb.Snak.newFromJSON = function( json ) {
+SELF.newFromJSON = function( json ) {
        // don't alter given Object in case of 'value' Snak by copying 
structure into new Object
        var map = $.extend( {}, json );
 
@@ -124,7 +124,7 @@
                        json.datavalue.value
                );
        }
-       return wb.Snak.newFromMap( map );
+       return SELF.newFromMap( map );
 };
 
 /**
@@ -136,7 +136,7 @@
  * @param {Object} map Requires at least 'snaktype' and 'property' fields.
  * @return wb.Snak|null
  */
-wb.Snak.newFromMap = function( map ) {
+SELF.newFromMap = function( map ) {
        switch( map.snaktype ) {
                case 'value':
                        return new wb.PropertyValueSnak( map.property, 
map.datavalue );
diff --git a/lib/resources/wikibase.datamodel/wikibase.SnakList.js 
b/lib/resources/wikibase.datamodel/wikibase.SnakList.js
index cb66050..91e9957 100644
--- a/lib/resources/wikibase.datamodel/wikibase.SnakList.js
+++ b/lib/resources/wikibase.datamodel/wikibase.SnakList.js
@@ -2,7 +2,7 @@
  * @file
  * @ingroup WikibaseLib
  * @licence GNU GPL v2+
- * @author Daniel Werner
+ * @author Daniel Werner < daniel.wer...@wikimedia.de >
  */
 ( function( wb, $ ) {
 'use strict';
@@ -18,7 +18,7 @@
  *
  * @param {wb.Snak[]|wb.Snak|wb.SnakList} [snaks] One or more Snaks in the 
list initially.
  */
-wb.SnakList = function WbSnakList( snaks ) {
+var SELF = wb.SnakList = function WbSnakList( snaks ) {
        this._snaks = [];
        this.length = 0;
 
@@ -38,7 +38,8 @@
                throw new Error( 'Unknown first argument in SnakList 
constructor' );
        }
 };
-wb.SnakList.prototype = {
+
+$.extend( SELF.prototype, {
        /**
         * Number of snaks in the list currently.
         * @type number
@@ -182,7 +183,7 @@
        toArray: function() {
                return this._snaks.slice(); // don't reveal internal array!
        }
-};
+} );
 
 /**
  * Creates a new Snak Object from a given JSON structure.
@@ -190,8 +191,8 @@
  * @param {String} json
  * @return wb.Snak|null
  */
-wb.SnakList.newFromJSON = function( json ) {
-       var snaksList = new wb.SnakList();
+SELF.newFromJSON = function( json ) {
+       var snaksList = new SELF();
 
        $.each( json, function( propertyId, snaksPerProperty ) {
                $.each( snaksPerProperty, function( i, snakJson ) {
diff --git a/lib/resources/wikibase.datamodel/wikibase.Statement.js 
b/lib/resources/wikibase.datamodel/wikibase.Statement.js
index 8ce88a5..d1b66e6 100644
--- a/lib/resources/wikibase.datamodel/wikibase.Statement.js
+++ b/lib/resources/wikibase.datamodel/wikibase.Statement.js
@@ -28,7 +28,7 @@
  * @param {String|null} [guid] The Global Unique Identifier of this Statement. 
Can be omitted or null
  *        if this is a new Statement, not yet stored in the database and 
associated with some entity.
  */
-wb.Statement = wb.utilities.inherit( 'WbStatement', PARENT, constructor, {
+var SELF = wb.Statement = wb.utilities.inherit( 'WbStatement', PARENT, 
constructor, {
        /**
         * @type {wb.Reference[]}
         * @todo think about implementing a ReferenceList/ClaimList rather than 
having an Array here
@@ -79,8 +79,8 @@
         */
        setRank: function( rank ) {
                // check if given rank is a known rank, then set it. Otherwise, 
throw error!
-               for( var i in wb.Statement.RANK ) {
-                       if( wb.Statement.RANK[i] === rank ) {
+               for( var i in SELF.RANK ) {
+                       if( SELF.RANK[i] === rank ) {
                                this._rank = rank;
                                return;
                        }
@@ -137,8 +137,6 @@
                var self = this,
                        json = PARENT.prototype.toJSON.call( this );
 
-               json.type = wb.Statement.TYPE;
-
                if ( this._references && this._references.length > 0 ) {
                        json.references = [];
                        $.each( this._references, function( i, reference ) {
@@ -147,7 +145,7 @@
                }
 
                if ( this._rank ) {
-                       $.each( wb.Statement.RANK, function ( rank, i ) {
+                       $.each( SELF.RANK, function ( rank, i ) {
                                if ( self._rank === i ) {
                                        json.rank = rank.toLowerCase();
                                        return false;
@@ -164,7 +162,7 @@
  * Rank enum. Higher values are more preferred.
  * @type Object
  */
-wb.Statement.RANK = {
+SELF.RANK = {
        PREFERRED: 2,
        NORMAL: 1,
        DEPRECATED: 0
@@ -173,6 +171,6 @@
 /**
  * @see wb.Claim.TYPE
  */
-wb.Statement.TYPE = 'statement';
+SELF.TYPE = 'statement';
 
 }( wikibase, jQuery ) );
diff --git a/lib/resources/wikibase.serialization/serialization.Serializer.js 
b/lib/resources/wikibase.serialization/serialization.Serializer.js
index dd05501..ad35693 100644
--- a/lib/resources/wikibase.serialization/serialization.Serializer.js
+++ b/lib/resources/wikibase.serialization/serialization.Serializer.js
@@ -26,7 +26,7 @@
                }
        };
 
-       SELF.prototype = {
+       $.extend( SELF.prototype, {
                /**
                 * @type Object
                 */
@@ -63,6 +63,6 @@
                getOptions: function() {
                        return $.extend( {}, this._options );
                }
-       };
+       } );
 
 }( wikibase, jQuery ) );
diff --git a/lib/resources/wikibase.serialization/serialization.Unserializer.js 
b/lib/resources/wikibase.serialization/serialization.Unserializer.js
index 078023c..2a35b7e 100644
--- a/lib/resources/wikibase.serialization/serialization.Unserializer.js
+++ b/lib/resources/wikibase.serialization/serialization.Unserializer.js
@@ -26,7 +26,7 @@
                }
        };
 
-       SELF.prototype = {
+       $.extend( SELF.prototype, {
                /**
                 * @type Object
                 */
@@ -63,6 +63,6 @@
                getOptions: function() {
                        return $.extend( {}, this._options );
                }
-       };
+       } );
 
 }( wikibase, jQuery ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ied01e553d16dd0b161fa97ea25d33d9f4efd0447
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <daniel.wer...@wikimedia.de>
Gerrit-Reviewer: Daniel Werner <daniel.wer...@wikimedia.de>
Gerrit-Reviewer: Henning Snater <henning.sna...@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