MarkTraceur has uploaded a new change for review.

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


Change subject: Add mediawiki.api.query and getAndContinue
......................................................................

Add mediawiki.api.query and getAndContinue

mw.Api#getAndContinue is a new function that handles the complexity of
getting a continuable API query.

This is in furtherance of a new extension which is at
https://gitorious.org/categoryslideshow/categoryslideshow for now - see
it for a first example.

Change-Id: Ic8e66ec2799a51dc304b0cb162ec7e5c487c1f96
---
M resources/Resources.php
A resources/mediawiki.api/mediawiki.api.query.js
2 files changed, 64 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/44/72844/1

diff --git a/resources/Resources.php b/resources/Resources.php
index 02cde52..a189fb1 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -583,6 +583,13 @@
                        'mediawiki.Title',
                ),
        ),
+       'mediawiki.api.query' => array(
+               'scripts' => 'resources/mediawiki.api/mediawiki.api.query.js',
+               'dependencies' => array(
+                       'jquery',
+                       'mediawiki.api',
+               ),
+       ),
        'mediawiki.api.edit' => array(
                'scripts' => 'resources/mediawiki.api/mediawiki.api.edit.js',
                'dependencies' => array(
diff --git a/resources/mediawiki.api/mediawiki.api.query.js 
b/resources/mediawiki.api/mediawiki.api.query.js
new file mode 100644
index 0000000..92e667f
--- /dev/null
+++ b/resources/mediawiki.api/mediawiki.api.query.js
@@ -0,0 +1,57 @@
+/**
+ * @class mw.Api.plugin.query
+ */
+( function ( mw, $ ) {
+
+       var continueToken = {};
+
+       $.extend( mw.Api.prototype, {
+               /**
+                * Will automatically continue any queries that allow it.
+                * Call multiple times for full effect.
+                *
+                * @param {string} continuation Key for remembering the 
continue key. Make sure this is consistent.
+                * @param {Object} params API parameters
+                * @param {Object|Function} ajaxOptions Passed to jQuery#ajax
+                * @return {jQuery.Promise}
+                */
+               getAndContinue: function ( continuation, params, ajaxOptions ) {
+                       var promise,
+                               ct = continueToken[continuation];
+
+                       if ( ct !== undefined ) {
+                               $.each( ct, function ( i, param ) {
+                                       params[param.name] = param.value;
+                               } );
+                       }
+
+                       promise = this.get( params, ajaxOptions );
+
+                       promise.done( function ( data ) {
+                               var qc = data['query-continue'];
+
+                               if ( qc !== undefined ) {
+                                       continueToken[continuation] = [];
+                                       $.each( qc, function ( name, obj ) {
+                                               $.each( obj, function ( name, 
value ) {
+                                                       var pairobj = {
+                                                               name: name,
+                                                               value: value
+                                                       };
+
+                                                       
continueToken[continuation].push( pairobj );
+                                               } );
+                                       } );
+                               }
+                       } );
+
+                       return promise;
+               }
+       } );
+
+       /**
+        * @class mw.Api
+        * @mixins mw.Api.plugin.query
+        */
+
+}( mediaWiki, jQuery ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/72844
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic8e66ec2799a51dc304b0cb162ec7e5c487c1f96
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to