[MediaWiki-commits] [Gerrit] Rewrite to use mediawiki.api - change (mediawiki...WikiLove)

2014-09-05 Thread TheDJ (Code Review)
TheDJ has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/158664

Change subject: Rewrite to use mediawiki.api
..

Rewrite to use mediawiki.api

mediawiki.ap has edittoken retry, seems useful here.

Change-Id: I4d611bb82d85891ebf1cc67e20552596eeda327d
---
M WikiLove.php
M resources/ext.wikiLove.core.js
2 files changed, 57 insertions(+), 93 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiLove 
refs/changes/64/158664/1

diff --git a/WikiLove.php b/WikiLove.php
index 0d239e6..4f5fd95 100644
--- a/WikiLove.php
+++ b/WikiLove.php
@@ -279,6 +279,7 @@
'wikilove-success-number',
),
'dependencies' = array(
+   'mediawiki.api.edit',
'ext.wikiLove.defaultOptions',
'jquery.ui.dialog',
'mediawiki.ui.button',
diff --git a/resources/ext.wikiLove.core.js b/resources/ext.wikiLove.core.js
index 77c2a16..9b45737 100644
--- a/resources/ext.wikiLove.core.js
+++ b/resources/ext.wikiLove.core.js
@@ -11,7 +11,8 @@
redirect = true, // whether or not to redirect the user to the WikiLove 
message after it has been posted
targets = [], // the recipients of the WikiLove
maxRecipients = 10, // maximum number of simultaneous recipients
-   gallery = {};
+   gallery = {},
+   api = new mw.Api();
 
 $.wikiLove = {
/**
@@ -314,20 +315,15 @@
$( '#mw-wikilove-image-preview-spinner' ).fadeIn( 200 );
var title = $.wikiLove.normalizeFilename( 
currentTypeOrSubtype.image );
var loadingType = currentTypeOrSubtype;
-   $.ajax({
-   url: mw.config.get( 'wgServer' ) + mw.config.get( 
'wgScriptPath' ) + '/api.php?',
-   data: {
-   'action'  : 'query',
-   'format'  : 'json',
-   'prop': 'imageinfo',
-   'iiprop'  : 'mime|url',
-   'titles'  : title,
-   'iiurlwidth'  : 75,
-   'iiurlheight' : 68
-   },
-   dataType: 'json',
-   type: 'POST',
-   success: function( data ) {
+   api.post( {
+   'action'  : 'query',
+   'prop': 'imageinfo',
+   'iiprop'  : 'mime|url',
+   'titles'  : title,
+   'iiurlwidth'  : 75,
+   'iiurlheight' : 68
+   } )
+   .done( function( data ) {
if ( !data || !data.query || !data.query.pages 
) {
$( '#mw-wikilove-image-preview-spinner' 
).fadeOut( 200 );
return;
@@ -348,11 +344,10 @@
$( 
'#mw-wikilove-image-preview-content' ).append( $img );
}
});
-   },
-   error: function() {
+   } )
+   .fail( function() {
$( '#mw-wikilove-image-preview-spinner' 
).fadeOut( 200 );
-   }
-   });
+   } );
},
 
/**
@@ -464,16 +459,12 @@
var imageTitle = 
$.wikiLove.normalizeFilename( $( '#mw-wikilove-image' ).val() );
$( '#mw-wikilove-preview-spinner' 
).fadeIn( 200 );
 
-   $.ajax( {
-   url: mw.config.get( 'wgServer' 
) + mw.config.get( 'wgScriptPath' ) + '/api.php?',
-   data: {
-   'action': 'query',
-   'format': 'json',
-   'titles': imageTitle,
-   'prop': 'imageinfo'
-   },
-   dataType: 'json',
-   success: function( data ) {
+   api.get( {
+   'action': 'query',
+   'titles': imageTitle,
+   'prop': 'imageinfo'
+   } )
+   .done( function( data ) {
   

[MediaWiki-commits] [Gerrit] Rewrite to use mediawiki.api - change (mediawiki...WikiLove)

2014-09-05 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Rewrite to use mediawiki.api
..


Rewrite to use mediawiki.api

mediawiki.api has edittoken retry, seems useful here.

Change-Id: I4d611bb82d85891ebf1cc67e20552596eeda327d
---
M WikiLove.php
M resources/ext.wikiLove.core.js
2 files changed, 57 insertions(+), 93 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/WikiLove.php b/WikiLove.php
index 0d239e6..4f5fd95 100644
--- a/WikiLove.php
+++ b/WikiLove.php
@@ -279,6 +279,7 @@
'wikilove-success-number',
),
'dependencies' = array(
+   'mediawiki.api.edit',
'ext.wikiLove.defaultOptions',
'jquery.ui.dialog',
'mediawiki.ui.button',
diff --git a/resources/ext.wikiLove.core.js b/resources/ext.wikiLove.core.js
index 77c2a16..9b45737 100644
--- a/resources/ext.wikiLove.core.js
+++ b/resources/ext.wikiLove.core.js
@@ -11,7 +11,8 @@
redirect = true, // whether or not to redirect the user to the WikiLove 
message after it has been posted
targets = [], // the recipients of the WikiLove
maxRecipients = 10, // maximum number of simultaneous recipients
-   gallery = {};
+   gallery = {},
+   api = new mw.Api();
 
 $.wikiLove = {
/**
@@ -314,20 +315,15 @@
$( '#mw-wikilove-image-preview-spinner' ).fadeIn( 200 );
var title = $.wikiLove.normalizeFilename( 
currentTypeOrSubtype.image );
var loadingType = currentTypeOrSubtype;
-   $.ajax({
-   url: mw.config.get( 'wgServer' ) + mw.config.get( 
'wgScriptPath' ) + '/api.php?',
-   data: {
-   'action'  : 'query',
-   'format'  : 'json',
-   'prop': 'imageinfo',
-   'iiprop'  : 'mime|url',
-   'titles'  : title,
-   'iiurlwidth'  : 75,
-   'iiurlheight' : 68
-   },
-   dataType: 'json',
-   type: 'POST',
-   success: function( data ) {
+   api.post( {
+   'action'  : 'query',
+   'prop': 'imageinfo',
+   'iiprop'  : 'mime|url',
+   'titles'  : title,
+   'iiurlwidth'  : 75,
+   'iiurlheight' : 68
+   } )
+   .done( function( data ) {
if ( !data || !data.query || !data.query.pages 
) {
$( '#mw-wikilove-image-preview-spinner' 
).fadeOut( 200 );
return;
@@ -348,11 +344,10 @@
$( 
'#mw-wikilove-image-preview-content' ).append( $img );
}
});
-   },
-   error: function() {
+   } )
+   .fail( function() {
$( '#mw-wikilove-image-preview-spinner' 
).fadeOut( 200 );
-   }
-   });
+   } );
},
 
/**
@@ -464,16 +459,12 @@
var imageTitle = 
$.wikiLove.normalizeFilename( $( '#mw-wikilove-image' ).val() );
$( '#mw-wikilove-preview-spinner' 
).fadeIn( 200 );
 
-   $.ajax( {
-   url: mw.config.get( 'wgServer' 
) + mw.config.get( 'wgScriptPath' ) + '/api.php?',
-   data: {
-   'action': 'query',
-   'format': 'json',
-   'titles': imageTitle,
-   'prop': 'imageinfo'
-   },
-   dataType: 'json',
-   success: function( data ) {
+   api.get( {
+   'action': 'query',
+   'titles': imageTitle,
+   'prop': 'imageinfo'
+   } )
+   .done( function( data ) {
// See if