Hello,
This is an important message for people who develop gadgets or user scripts for Wikidata’s frontend.
We plan to deprecate the wbEntity javascript config variable in the
next months. The variable is currently used on every page load, even if
when it is not useful (for example on mobile). With that change, we will
increase the load speed of the entity pages. After that the expression mw.config.get( 'wbEntity' );
will not work any more. All code that uses this config variable should be migrated towards using the Mediawiki hook wikibase.entityPage.entityLoaded
.
When a user opens an entity page (item or property), as soon as the
JSON representation of the entity stored on the current entity page is
loaded, the Mediawiki hook wikibase.entityPage.entityLoaded
is triggered. Listener callbacks should expect the entity as a native
JavaScript object (the parsed JSON serialization) passed as the first
(and only) argument.
Note: The entity object is completely frozen (read-only) to avoid the case when one of the clients accidentally changes it and breaks other clients.
Here are a few examples on how you can use it:
// Basic usage
mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) {
'use strict';
// Your code goes here
console.log( entity );
} );
// Convert to jQuery promise
var entityPromise = $.Deferred( function ( deferred ) {
mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) {
deferred.resolve( entity );
} );
} ).promise();
// Convert to native promise
var entityPromise = new Promise( function ( resolve ) {
mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) {
resolve( entity );
} );
} );
See also: the related ticket, the code of wikibase.entityPage.entityLoaded.
If you have any question or need support with migrating specific gadgets, feel free to write to me.