Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js |
— | — | @@ -870,18 +870,14 @@ |
871 | 871 | } |
872 | 872 | |
873 | 873 | // 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; |
884 | 878 | } |
885 | | - ); |
| 879 | + _this.editToken = editToken; |
| 880 | + _this.doChunkUploadWithFormData(); |
| 881 | + } ); |
886 | 882 | }, |
887 | 883 | |
888 | 884 | /** |
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js |
— | — | @@ -2173,7 +2173,7 @@ |
2174 | 2174 | } |
2175 | 2175 | // @@todo try to load over ajax if( _this.local_wiki_api_url ) is set |
2176 | 2176 | // ( 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 ) { |
2178 | 2178 | callback( token ); |
2179 | 2179 | } ); |
2180 | 2180 | }, |
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/simpleUploadForm.js |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | } |
48 | 48 | |
49 | 49 | // 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 ) { |
51 | 51 | if ( !eToken || eToken == '+\\' ) { |
52 | 52 | $( this.selector ).html( gM( 'mwe-error_not_loggedin' ) ); |
53 | 53 | return false; |
Index: branches/js2-work/phase3/js2/mwEmbed/libSequencer/mvSequencer.js |
— | — | @@ -506,7 +506,7 @@ |
507 | 507 | this.sequenceEditToken = $j( 'input[wpEditToken]' ).val(); |
508 | 508 | |
509 | 509 | 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(), |
511 | 511 | function( token ) { |
512 | 512 | if ( token ) { |
513 | 513 | _this.sequenceEditToken = token; |
Index: branches/js2-work/phase3/js2/mwEmbed/tests/testApiProxy.html |
— | — | @@ -61,7 +61,7 @@ |
62 | 62 | getUserName(function(userName){ |
63 | 63 | var eTitle = 'User_talk:' + userName; |
64 | 64 | //get a edit token |
65 | | - get_mw_token(eTitle, 'proxy', function( token ){ |
| 65 | + mw.getToken( eTitle, 'proxy', function( token ){ |
66 | 66 | mw.log("got token: " + token) ; |
67 | 67 | var request = { |
68 | 68 | 'action':'edit', |
Index: branches/js2-work/phase3/js2/mwEmbed/mwEmbed.js |
— | — | @@ -1134,6 +1134,44 @@ |
1135 | 1135 | |
1136 | 1136 | |
1137 | 1137 | /** |
| 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 | + /** |
1138 | 1176 | * Utility Functions |
1139 | 1177 | */ |
1140 | 1178 | |
— | — | @@ -2465,41 +2503,6 @@ |
2466 | 2504 | * Utility functions: |
2467 | 2505 | */ |
2468 | 2506 | |
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 | | - |
2504 | 2507 | // Do a metavid callback request: |
2505 | 2508 | // NOTE: this contains metavid specific local vs remote api remapping will be removed shortly |
2506 | 2509 | // this should be depreciated and we should use "$j.get" or an api call |