Cross post.
---------- Forwarded message ---------- From: Léa Lacroix lea.lacroix@wikimedia.de Date: Tue, Jul 18, 2017 at 4:31 AM Subject: [Wikidata] wbEntity config variable to be deprecated To: "Discussion list for the Wikidata project." < wikidata@lists.wikimedia.org>
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 usagemw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) { 'use strict'; // Your code goes here console.log( entity );} ); // Convert to jQuery promisevar entityPromise = $.Deferred( function ( deferred ) { mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) { deferred.resolve( entity ); } );} ).promise(); // Convert to native promisevar entityPromise = new Promise( function ( resolve ) { mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) { resolve( entity ); } );} );
See also: the related ticket https://phabricator.wikimedia.org/T85499, the code of wikibase.entityPage.entityLoaded https://phabricator.wikimedia.org/diffusion/EWBA/browse/master/repo/resources/wikibase.entityPage.entityLoaded.js . If you have any question or need support with migrating specific gadgets, feel free to write to me. Thanks,