summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CommentStreams/resources/CommentStreamsQuerier.js')
-rw-r--r--CommentStreams/resources/CommentStreamsQuerier.js158
1 files changed, 90 insertions, 68 deletions
diff --git a/CommentStreams/resources/CommentStreamsQuerier.js b/CommentStreams/resources/CommentStreamsQuerier.js
index 84d92403..bcb83755 100644
--- a/CommentStreams/resources/CommentStreamsQuerier.js
+++ b/CommentStreams/resources/CommentStreamsQuerier.js
@@ -20,45 +20,51 @@
* DEALINGS IN THE SOFTWARE.
*/
-var commentstreams_querier = ( function( mw ) {
+var commentstreams_querier = ( function () {
+ 'use strict';
+
return {
- queryComment: function( pageid, reply ) {
+ queryComment: function ( pageid, reply ) {
var self = this;
var api = new mw.Api();
api.get( {
- action: 'csQueryComment',
- pageid: pageid
- } )
- .done( function( data ) {
- reply( data.csQueryComment );
+ action: 'csquerycomment',
+ pageid: pageid
+ } )
+ .done( function ( data ) {
+ if ( data.csquerycomment === undefined ) {
+ self.reportError( 'invalid', reply );
+ }
+ reply( data.csquerycomment );
} )
- .fail( function( data ) {
- self.reportError( data, reply );
+ .fail( function ( code, error ) {
+ self.reportError( error, reply );
} );
},
- deleteComment: function( pageid, reply ) {
+ deleteComment: function ( pageid, reply ) {
var self = this;
var api = new mw.Api();
api.post( {
- action: 'csDeleteComment',
- pageid: pageid,
- token: mw.user.tokens.get( 'csrfToken' )
- } )
- .done( function( data ) {
- reply( data );
+ action: 'csdeletecomment',
+ pageid: pageid,
+ token: mw.user.tokens.get( 'csrfToken' )
+ } )
+ .done( function () {
+ reply();
} )
- .fail( function( data ) {
- self.reportError( data, reply );
+ .fail( function ( code, error ) {
+ self.reportError( error, reply );
} );
},
- postComment: function( commenttitle, wikitext, associatedid, parentid,
+ postComment: function ( commenttitle, wikitext, associatedid, parentid, commentblockid,
reply ) {
var self = this;
var api = new mw.Api();
var data = {
- action: 'csPostComment',
+ action: 'cspostcomment',
wikitext: wikitext,
associatedid: associatedid,
+ commentblockid: commentblockid,
token: mw.user.tokens.get( 'csrfToken' )
};
if ( commenttitle !== null ) {
@@ -68,83 +74,99 @@ var commentstreams_querier = ( function( mw ) {
data.parentid = parentid;
}
api.post(
- data
- )
- .done( function( data ) {
- reply( data.csPostComment );
+ data
+ )
+ .done( function ( postData ) {
+ if ( postData.cspostcomment === undefined ) {
+ self.reportError( 'invalid', reply );
+ }
+ self.queryComment( postData.cspostcomment, reply );
} )
- .fail( function( data ) {
- self.reportError( data, reply );
+ .fail( function ( code, error ) {
+ self.reportError( error, reply );
} );
},
- editComment: function( commenttitle, wikitext, pageid, reply ) {
+ editComment: function ( commenttitle, wikitext, pageid, reply ) {
var self = this;
var api = new mw.Api();
- api.post( {
- action: 'csEditComment',
- pageid: pageid,
- commenttitle: commenttitle,
- wikitext: wikitext,
- token: mw.user.tokens.get( 'csrfToken' )
- } )
- .done( function( data ) {
- reply( data.csEditComment );
+ var data = {
+ action: 'cseditcomment',
+ pageid: pageid,
+ wikitext: wikitext,
+ token: mw.user.tokens.get( 'csrfToken' )
+ };
+ if ( commenttitle ) {
+ data.commenttitle = commenttitle;
+ }
+ api.post(
+ data
+ )
+ .done( function () {
+ self.queryComment( pageid, reply );
} )
- .fail( function( data ) {
- self.reportError( data, reply );
+ .fail( function ( code, error ) {
+ self.reportError( error, reply );
} );
},
- vote: function( pageid, vote, reply ) {
+ vote: function ( pageid, vote, reply ) {
var self = this;
var api = new mw.Api();
api.post( {
- action: 'csVote',
- pageid: pageid,
- vote: vote,
- token: mw.user.tokens.get( 'csrfToken' )
- } )
- .done( function( data ) {
- reply( data.csVote );
+ action: 'csvote',
+ pageid: pageid,
+ vote: vote,
+ token: mw.user.tokens.get( 'csrfToken' )
+ } )
+ .done( function () {
+ reply();
} )
- .fail( function( data ) {
- self.reportError( data, reply );
+ .fail( function ( code, error ) {
+ self.reportError( error, reply );
} );
},
- watch: function( pageid, action, reply ) {
+ watch: function ( pageid, action, reply ) {
var self = this;
var api = new mw.Api();
api.post( {
- action: action ? 'csWatch' : 'csUnwatch',
- pageid: pageid,
- token: mw.user.tokens.get( 'csrfToken' )
- } )
- .done( function( data ) {
- if ( action ) {
- reply( data.csWatch );
- } else {
- reply( data.csUnwatch );
- }
+ action: action ? 'cswatch' : 'csunwatch',
+ pageid: pageid,
+ token: mw.user.tokens.get( 'csrfToken' )
+ } )
+ .done( function () {
+ reply();
} )
- .fail( function( data ) {
- self.reportError( data, reply );
+ .fail( function ( code, error ) {
+ self.reportError( error, reply );
} );
},
- reportError: function( data, reply ) {
- if ( data === 'nosuchpageid' ) {
+ reportError: function ( error, reply ) {
+ if (
+ error === 'invalid' ||
+ error.error === undefined ||
+ error.error.code === undefined ||
+ error.error[ '*' ] === undefined
+ ) {
+ reply( {
+ error: 'commentstreams-api-error-invalid'
+ } );
+ } else if ( error.error.code === 'nosuchpageid' ) {
reply( {
- 'error': 'commentstreams-api-error-commentnotfound'
+ error: 'commentstreams-api-error-commentnotfound'
} );
- } else if ( data === 'badtoken' ) {
+ } else if ( error.error.code === 'badtoken' ) {
reply( {
- 'error': 'commentstreams-api-error-notloggedin'
+ error: 'commentstreams-api-error-notloggedin'
} );
} else {
+ // These types of errors should never happen, but in the case of install errors,
+ // syntax errors during development, or conflicting extensions, they could happen.
+ // Since there is no other good way of debugging them, they will be displayed.
reply( {
- 'error': data
+ error: error.error[ '*' ]
} );
}
}
};
-}( mediaWiki ) );
+}() );
window.CommentStreamsQuerier = commentstreams_querier;