jenkins-bot has submitted this change and it was merged.
Change subject: Hygiene: Abstract more of the nastiness of the wikidata api
......................................................................
Hygiene: Abstract more of the nastiness of the wikidata api
Return a simple object with information about the wikidata item.
Change-Id: Ib680afae6e3b864057230619eb9c9e4f30e0b5ea
---
M javascripts/modules/wikigrok/WikiDataApi.js
M javascripts/modules/wikigrok/wikigrokeval.js
2 files changed, 28 insertions(+), 31 deletions(-)
Approvals:
Kaldari: Looks good to me, approved
jenkins-bot: Verified
diff --git a/javascripts/modules/wikigrok/WikiDataApi.js
b/javascripts/modules/wikigrok/WikiDataApi.js
index 04e0251..321f5d9 100644
--- a/javascripts/modules/wikigrok/WikiDataApi.js
+++ b/javascripts/modules/wikigrok/WikiDataApi.js
@@ -1,4 +1,4 @@
-( function( M ) {
+( function( M, $ ) {
var Api = M.require( 'api' ).Api, WikiDataApi;
/**
* @class EditorApi
@@ -13,11 +13,28 @@
Api.prototype.initialize.apply( this, arguments );
},
getClaims: function() {
+ var id = this.itemId;
return this.ajax( {
action: 'wbgetentities',
ids: this.itemId,
props: 'claims',
format: 'json'
+ } ).then( function( data ) {
+ var instanceClaims,
+ claims = {};
+ // See if the page has any 'instance of' claims.
+ if ( data.entities !== undefined &&
data.entities[id].claims.P31 !== undefined ) {
+ instanceClaims =
data.entities[id].claims.P31;
+
+ // Examine claims closely
+ $.each( instanceClaims, function( i,
claim ) {
+ claims.isHuman =
claim.mainsnak.datavalue.value['numeric-id'] === 5 ? true : false;
+ claims.hasOccupation =
data.entities[id].claims.P106 ? true : false;
+ } );
+ return claims;
+ } else {
+ return false;
+ }
} );
},
getOccupations: function( occupationId ) {
@@ -31,4 +48,4 @@
M.define( 'modules/wikigrok/WikiDataApi', WikiDataApi );
-}( mw.mobileFrontend ) );
+}( mw.mobileFrontend, jQuery ) );
diff --git a/javascripts/modules/wikigrok/wikigrokeval.js
b/javascripts/modules/wikigrok/wikigrokeval.js
index c4c1341..23198ce 100644
--- a/javascripts/modules/wikigrok/wikigrokeval.js
+++ b/javascripts/modules/wikigrok/wikigrokeval.js
@@ -9,36 +9,16 @@
if ( !M.settings.getUserSetting( 'mfHideWikiGrok' ) ) {
api = new WikiDataApi( { itemId: wikidataID });
api.getClaims().done(
- function( data ) {
- var instanceClaims,
- dialog,
- loadWikiGrokDialog = false;
+ function( claims ) {
+ var dialog;
- // See if the page has any 'instance of' claims.
- if ( data.entities !== undefined &&
data.entities[wikidataID].claims.P31 !== undefined ) {
- instanceClaims =
data.entities[wikidataID].claims.P31;
- $.each( instanceClaims, function( id,
claim ) {
- // See if any of the claims
state that the topic is a human.
- if (
claim.mainsnak.datavalue.value['numeric-id'] === 5 ) {
- // Make sure there are
no existing occupation claims.
- if (
data.entities[wikidataID].claims.P106 === undefined ) {
-
loadWikiGrokDialog = true;
- }
- // Break each loop.
- return false;
- }
- } );
- if ( loadWikiGrokDialog ) {
- dialog = new WikiGrokDialog( {
itemId: wikidataID } );
- // Insert the dialog into the
page
- $( function() {
- // If there is a table
of contents, insert before it.
- if ( $( '.toc-mobile'
).length ) {
-
dialog.insertBefore( '.toc-mobile' );
- } else {
-
dialog.appendTo( M.getLeadSection() );
- }
- } );
+ if ( claims && !claims.hasOccupation ) {
+ dialog = new WikiGrokDialog( { itemId:
wikidataID } );
+ // If there is a table of contents,
insert before it.
+ if ( $( '.toc-mobile' ).length ) {
+ dialog.insertBefore(
'.toc-mobile' );
+ } else {
+ dialog.appendTo(
M.getLeadSection() );
}
}
}
--
To view, visit https://gerrit.wikimedia.org/r/162797
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib680afae6e3b864057230619eb9c9e4f30e0b5ea
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Awjrichards <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits