Skip to content

Commit

Permalink
Merge "Use browser native URL instead of mw.Uri"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Sep 16, 2024
2 parents a52806b + a500877 commit 03c705d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
3 changes: 1 addition & 2 deletions repo/resources/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
],
'dependencies' => [
'wikibase',
'mediawiki.Uri',
'web2017-polyfills',
],
],

Expand Down Expand Up @@ -235,7 +235,6 @@
'mediawiki.api',
'mediawiki.cookie',
'mediawiki.page.watch.ajax',
'mediawiki.Uri',
'mediawiki.user',
'mw.config.values.wbRepo',
'mw.config.values.wbDataTypes',
Expand Down
29 changes: 13 additions & 16 deletions repo/resources/wikibase.entityPage.entityLoaded.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
* } );
*
* @example <caption>Convert to jQuery promise</caption>
* var entityPromise = $.Deferred( function ( deferred ) {
* const entityPromise = $.Deferred( function ( deferred ) {
* mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) {
* deferred.resolve( entity );
* } );
* } ).promise();
*
* @example <caption>Convert to native promise</caption>
* var entityPromise = new Promise( function ( resolve ) {
* const entityPromise = new Promise( function ( resolve ) {
* mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) {
* resolve( entity );
* } );
* } );
*/
( function ( mwConfig, mwUri ) {
( function ( mwConfig ) {
'use strict';

/**
Expand All @@ -42,11 +42,11 @@
*/
function deepFreeze( obj ) {
// Retrieve the property names defined on obj
var propNames = Object.getOwnPropertyNames( obj );
const propNames = Object.getOwnPropertyNames( obj );

// Freeze properties before freezing self
propNames.forEach( function ( name ) {
var prop = obj[ name ];
const prop = obj[ name ];

// Freeze prop if it is an object
if ( typeof prop === 'object' && prop !== null ) {
Expand All @@ -58,9 +58,7 @@
return Object.freeze( obj );
}

var entityId = mwConfig.get( 'wbEntityId' ),
url,
specialEntityDataPath;
const entityId = mwConfig.get( 'wbEntityId' );

if ( entityId === null ) {
mw.log.error(
Expand All @@ -71,24 +69,23 @@
}

// Load from Special:EntityData because it gets cached in several layers
specialEntityDataPath = mwConfig.get( 'wgArticlePath' ).replace(
const specialEntityDataPath = mwConfig.get( 'wgArticlePath' ).replace(
/\$1/g, 'Special:EntityData/' + entityId + '.json'
);
url = new mwUri( specialEntityDataPath );
url.extend( { revision: mwConfig.get( 'wgRevisionId' ) } );

$.getJSON( url.toString(), function ( data ) {
var wbEntity;
const url = new URL( specialEntityDataPath, location.href );
url.searchParams.set( 'revision', mwConfig.get( 'wgRevisionId' ) );

$.getJSON( url.toString(), ( data ) => {
if ( !data || !data.entities || !data.entities[ entityId ] ) {
return;
}
wbEntity = data.entities[ entityId ];

const wbEntity = data.entities[ entityId ];

if ( wbEntity ) {
// Note this assumes "wbEntity" contains valid JSON, and will throw an error otherwise.
mw.hook( 'wikibase.entityPage.entityLoaded' ).fire( deepFreeze( wbEntity ) );
}
} );

}( mw.config, mw.Uri ) );
}( mw.config ) );

0 comments on commit 03c705d

Please sign in to comment.