r59941 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59940‎ | r59941 | r59942 >
Date:00:43, 11 December 2009
Author:dale
Status:deferred
Tags:
Comment:
get_edit_token -> mw.getToken()
Modified paths:
  • /branches/js2-work/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libAddMedia/simpleUploadForm.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libSequencer/mvSequencer.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/tests/testApiProxy.html (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js
@@ -870,18 +870,14 @@
871871 }
872872
873873 // No edit token. Fetch it asynchronously and then do the upload.
874 - get_mw_token(
875 - 'File:'+ _this.formData['filename'],
876 - _this.api_url,
877 - function( editToken ) {
878 - if( !editToken || editToken == '+\\' ) {
879 - _this.updateProgressWin( gM( 'fogg-badtoken' ), gM( 'fogg-badtoken' ) );
880 - return false;
881 - }
882 - _this.editToken = editToken;
883 - _this.doChunkUploadWithFormData();
 874+ mw.getToken( 'File:'+ _this.formData['filename'], _this.api_url, function( editToken ) {
 875+ if( !editToken || editToken == '+\\' ) {
 876+ _this.updateProgressWin( gM( 'fogg-badtoken' ), gM( 'fogg-badtoken' ) );
 877+ return false;
884878 }
885 - );
 879+ _this.editToken = editToken;
 880+ _this.doChunkUploadWithFormData();
 881+ } );
886882 },
887883
888884 /**
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js
@@ -2173,7 +2173,7 @@
21742174 }
21752175 // @@todo try to load over ajax if( _this.local_wiki_api_url ) is set
21762176 // ( for cases where inserting from a normal page view (that did not have wpEditToken)
2177 - get_mw_token( null, _this.upload_api_target, function( token ) {
 2177+ mw.getToken( _this.upload_api_target, function( token ) {
21782178 callback( token );
21792179 } );
21802180 },
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/simpleUploadForm.js
@@ -46,7 +46,7 @@
4747 }
4848
4949 // Get an edit Token for "uploading"
50 - get_mw_token( 'File:MyRandomFileTokenCheck', options.api_target, function( eToken ) {
 50+ mw.getToken( 'File:MyRandomFileTokenCheck', options.api_target, function( eToken ) {
5151 if ( !eToken || eToken == '+\\' ) {
5252 $( this.selector ).html( gM( 'mwe-error_not_loggedin' ) );
5353 return false;
Index: branches/js2-work/phase3/js2/mwEmbed/libSequencer/mvSequencer.js
@@ -506,7 +506,7 @@
507507 this.sequenceEditToken = $j( 'input[wpEditToken]' ).val();
508508
509509 if ( typeof this.sequenceEditToken == 'undefined' && this.getLocalApiUrl() != null ) {
510 - get_mw_token( _this.plObj.mTitle, _this.getLocalApiUrl(),
 510+ mw.getToken( _this.plObj.mTitle, _this.getLocalApiUrl(),
511511 function( token ) {
512512 if ( token ) {
513513 _this.sequenceEditToken = token;
Index: branches/js2-work/phase3/js2/mwEmbed/tests/testApiProxy.html
@@ -61,7 +61,7 @@
6262 getUserName(function(userName){
6363 var eTitle = 'User_talk:' + userName;
6464 //get a edit token
65 - get_mw_token(eTitle, 'proxy', function( token ){
 65+ mw.getToken( eTitle, 'proxy', function( token ){
6666 mw.log("got token: " + token) ;
6767 var request = {
6868 'action':'edit',
Index: branches/js2-work/phase3/js2/mwEmbed/mwEmbed.js
@@ -1134,6 +1134,44 @@
11351135
11361136
11371137 /**
 1138+ * Simple api helper to grab an edit token
 1139+ *
 1140+ * @param title The wiki page title you want to edit
 1141+ * @param {String} [api_url] The target API URL
 1142+ * @param {callback} callback Function to pass the token to
 1143+ */
 1144+ mw.getToken( title, api_url, callback ) {
 1145+ if( typeof api_url == 'function' )
 1146+ callback = api_url;
 1147+ if( typeof title == 'function')
 1148+ callback = title;
 1149+
 1150+ mw.log( 'mw:getToken' );
 1151+
 1152+ // If no title is provided get a token for the user page:
 1153+ if ( typeof title != 'string' && wgUserName ) {
 1154+ title = 'User:' + wgUserName;
 1155+ }
 1156+
 1157+ var request = {
 1158+ 'prop': 'info',
 1159+ 'intoken': 'edit',
 1160+ 'titles': title
 1161+ };
 1162+ mw.getJSON( api_url, request, function( data ) {
 1163+ for ( var i in data.query.pages ) {
 1164+ if ( data.query.pages[i]['edittoken'] ) {
 1165+ if ( typeof callback == 'function' )
 1166+ callback ( data.query.pages[i]['edittoken'] );
 1167+ }
 1168+ }
 1169+ // No token found:
 1170+ return false;
 1171+ } );
 1172+ }
 1173+
 1174+
 1175+ /**
11381176 * Utility Functions
11391177 */
11401178
@@ -2465,41 +2503,6 @@
24662504 * Utility functions:
24672505 */
24682506
2469 -
2470 -/*
2471 - * Simple helper to grab an edit token
2472 - *
2473 - * @param title The wiki page title you want to edit
2474 - * @param api_url 'optional' The target API URL
2475 - * @param callback The callback function to pass the token to
2476 - */
2477 -function get_mw_token( title, api_url, callback ) {
2478 - mw.log( ':get_mw_token:' );
2479 - if ( !title && wgUserName ) {
2480 - title = 'User:' + wgUserName;
2481 - }
2482 - var reqObj = {
2483 - 'action': 'query',
2484 - 'prop': 'info',
2485 - 'intoken': 'edit',
2486 - 'titles': title
2487 - };
2488 - do_api_req( {
2489 - 'data': reqObj,
2490 - 'url' : api_url
2491 - }, function( data ) {
2492 - for ( var i in data.query.pages ) {
2493 - if ( data.query.pages[i]['edittoken'] ) {
2494 - if ( typeof callback == 'function' )
2495 - callback ( data.query.pages[i]['edittoken'] );
2496 - }
2497 - }
2498 - // No token found:
2499 - return false;
2500 - }
2501 - );
2502 -}
2503 -
25042507 // Do a metavid callback request:
25052508 // NOTE: this contains metavid specific local vs remote api remapping will be removed shortly
25062509 // this should be depreciated and we should use "$j.get" or an api call

Status & tagging log