jenkins-bot has submitted this change and it was merged.
Change subject: Hygiene: Introduce WikiGrokApi
......................................................................
Hygiene: Introduce WikiGrokApi
Change-Id: I2b9773c851b7aa8a8aa4194c3b93e8e7cb4d426b
---
M includes/Resources.php
A javascripts/modules/wikigrok/WikiGrokApi.js
M javascripts/modules/wikigrok/WikiGrokDialog.js
3 files changed, 62 insertions(+), 43 deletions(-)
Approvals:
Kaldari: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Resources.php b/includes/Resources.php
index b9437ec..c00317a 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -903,6 +903,7 @@
),
'scripts' => array(
'javascripts/modules/wikigrok/WikiDataApi.js',
+ 'javascripts/modules/wikigrok/WikiGrokApi.js',
'javascripts/modules/wikigrok/WikiGrokDialog.js',
'javascripts/modules/wikigrok/WikiGrokMoreInfo.js',
'javascripts/modules/wikigrok/wikigrokeval.js',
diff --git a/javascripts/modules/wikigrok/WikiGrokApi.js
b/javascripts/modules/wikigrok/WikiGrokApi.js
new file mode 100644
index 0000000..e9dfa61
--- /dev/null
+++ b/javascripts/modules/wikigrok/WikiGrokApi.js
@@ -0,0 +1,28 @@
+( function( M ) {
+ var Api = M.require( 'api' ).Api, WikiGrokApi;
+ /**
+ * @class EditorApi
+ * @extends Api
+ */
+ WikiGrokApi = Api.extend( {
+ apiUrl: 'https://tools.wmflabs.org/wikigrok/api.php',
+
+ initialize: function() {
+ Api.prototype.initialize.apply( this, arguments );
+ },
+ getPossibleOccupations: function( itemId ) {
+ return this.ajax( {
+ action: 'get_potential_occupations',
+ // Strip the Q out of the Wikibase item
ID
+ item: itemId.replace( 'Q' , '' )
+ },
+ {
+ url: this.apiUrl,
+ dataType: 'jsonp'
+ } );
+ }
+ } );
+
+ M.define( 'modules/wikigrok/WikiGrokApi', WikiGrokApi );
+
+}( mw.mobileFrontend ) );
diff --git a/javascripts/modules/wikigrok/WikiGrokDialog.js
b/javascripts/modules/wikigrok/WikiGrokDialog.js
index cadf2e4..7008540 100644
--- a/javascripts/modules/wikigrok/WikiGrokDialog.js
+++ b/javascripts/modules/wikigrok/WikiGrokDialog.js
@@ -2,6 +2,7 @@
M.assertMode( [ 'beta', 'alpha' ] );
var Panel = M.require( 'Panel' ),
+ WikiGrokApi = M.require( 'modules/wikigrok/WikiGrokApi' ),
WikiDataApi = M.require( 'modules/wikigrok/WikiDataApi' ),
schema = M.require( 'loggingSchemas/mobileWebWikiGrok' ),
WikiGrokDialog;
@@ -35,6 +36,7 @@
template: M.template.get(
'modules/wikigrok/WikiGrokDialog.hogan' ),
initialize: function() {
+ this.apiWikiGrok = new WikiGrokApi();
this.apiWikiData = new WikiDataApi();
Panel.prototype.initialize.apply( this, arguments );
},
@@ -51,52 +53,40 @@
var self = this;
// Get potential occupations for the person.
- // FIXME: Create a client-side API class for
interacting with the WikiGrok API
- $.ajax( {
- type: 'get',
- // https://github.com/kaldari/WikiGrokAPI
- url:
'https://tools.wmflabs.org/wikigrok/api.php',
- data: {
- 'action': 'get_potential_occupations',
- // Strip the Q out of the Wikibase item
ID
- 'item': options.itemId.replace( 'Q' ,
'' )
- },
- dataType: 'jsonp',
- success: function( data ) {
- var occupationArray;
+ this.apiWikiGrok.getPossibleOccupations( options.itemId
).done( function( data ) {
+ var occupationArray;
- // If there are potential occupations
for this person, select one at
- // random and ask if it is a correct
occupation for the person.
- if ( data.occupations !== undefined ) {
- occupationArray =
data.occupations.split( ',' );
- // Choose a random occupation
from the list of possible occupations.
- options.occupationId = 'Q' +
occupationArray[ Math.floor( Math.random() * occupationArray.length ) ];
- // Remove any disambiguation
parentheticals from the title.
- options.name = mw.config.get(
'wgTitle' ).replace( / \(.+\)$/, '' );
+ // If there are potential occupations for this
person, select one at
+ // random and ask if it is a correct occupation
for the person.
+ if ( data.occupations !== undefined ) {
+ occupationArray =
data.occupations.split( ',' );
+ // Choose a random occupation from the
list of possible occupations.
+ options.occupationId = 'Q' +
occupationArray[ Math.floor( Math.random() * occupationArray.length ) ];
+ // Remove any disambiguation
parentheticals from the title.
+ options.name = mw.config.get( 'wgTitle'
).replace( / \(.+\)$/, '' );
- // Get the name of the
occupation from Wikidata.
-
self.apiWikiData.getOccupations( options.occupationId ).done( function( data ) {
- var vowels = [ 'a',
'e', 'i', 'o', 'u' ];
- if (
data.entities[options.occupationId].labels.en.value !== undefined ) {
- // Re-render
with new content for 'Question' step
-
options.beginQuestions = true;
-
options.occupation = data.entities[options.occupationId].labels.en.value;
- // Hack for
English prototype
- if ( $.inArray(
options.occupation.charAt(0), vowels ) === -1 ) {
-
options.contentMsg = 'Was ' + options.name + ' a ' + options.occupation + '?';
- } else {
-
options.contentMsg = 'Was ' + options.name + ' an ' + options.occupation + '?';
- }
- options.buttons
= [
- {
classes: 'yes inline mw-ui-button mw-ui-progressive', label: 'Yes' },
- {
classes: 'not-sure inline mw-ui-button', label: 'Not Sure' },
- {
classes: 'no inline mw-ui-button mw-ui-progressive', label: 'No' }
- ];
-
options.noticeMsg = 'All submissions are <a class="wg-notice-link"
href="#/wikigrok/about">released freely</a>';
- self.render(
options );
+ // Get the name of the occupation from
Wikidata.
+ self.apiWikiData.getOccupations(
options.occupationId ).done( function( data ) {
+ var vowels = [ 'a', 'e', 'i',
'o', 'u' ];
+ if (
data.entities[options.occupationId].labels.en.value !== undefined ) {
+ // Re-render with new
content for 'Question' step
+ options.beginQuestions
= true;
+ options.occupation =
data.entities[options.occupationId].labels.en.value;
+ // Hack for English
prototype
+ if ( $.inArray(
options.occupation.charAt(0), vowels ) === -1 ) {
+
options.contentMsg = 'Was ' + options.name + ' a ' + options.occupation + '?';
+ } else {
+
options.contentMsg = 'Was ' + options.name + ' an ' + options.occupation + '?';
}
- } );
- }
+ options.buttons = [
+ { classes: 'yes
inline mw-ui-button mw-ui-progressive', label: 'Yes' },
+ { classes:
'not-sure inline mw-ui-button', label: 'Not Sure' },
+ { classes: 'no
inline mw-ui-button mw-ui-progressive', label: 'No' }
+ ];
+ options.noticeMsg =
'All submissions are <a class="wg-notice-link" href="#/wikigrok/about">released
freely</a>';
+ self.render( options );
+ }
+ } );
}
} );
},
--
To view, visit https://gerrit.wikimedia.org/r/162132
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2b9773c851b7aa8a8aa4194c3b93e8e7cb4d426b
Gerrit-PatchSet: 4
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