Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.UploadHandler.js |
— | — | @@ -55,7 +55,10 @@ |
56 | 56 | 'rewriteDescriptionText' : true, |
57 | 57 | |
58 | 58 | // Callback which is called when the source name changes |
59 | | - 'selectFileCb': false |
| 59 | + 'selectFileCb': null, |
| 60 | + |
| 61 | + // Callback called when an upload completes or is canceld and we want to re-activeate the form |
| 62 | + 'returnToFormCb' : null |
60 | 63 | |
61 | 64 | }; |
62 | 65 | |
— | — | @@ -139,7 +142,7 @@ |
140 | 143 | } |
141 | 144 | |
142 | 145 | // Setup ui uploadHandler pointer |
143 | | - this.ui.uploadHandler = this; |
| 146 | + this.ui.uploadHandler = this; |
144 | 147 | |
145 | 148 | mw.log( "init mvUploadHandler:: " + this.apiUrl + ' interface: ' + this.ui ); |
146 | 149 | }, |
— | — | @@ -473,7 +476,7 @@ |
474 | 477 | |
475 | 478 | var httpUpConf = { |
476 | 479 | 'url' : $j( '#wpUploadFileURL' ).val(), |
477 | | - 'filename' : $j( '#wpDestFile' ).val(), |
| 480 | + 'filename' : _this.getFilename(), |
478 | 481 | 'comment' : this.getUploadDescription(), |
479 | 482 | 'watch' : ( $j( '#wpWatchthis' ).is( ':checked' ) ) ? 'true' : 'false', |
480 | 483 | 'ignorewarnings': ($j('#wpIgnoreWarning' ).is( ':checked' ) ) ? 'true' : 'false' |
— | — | @@ -787,11 +790,15 @@ |
788 | 791 | var request = { |
789 | 792 | 'action': 'upload', |
790 | 793 | 'sessionkey': _this.warnings_sessionkey, |
791 | | - 'ignorewarnings': 1, |
792 | | - 'filename': $j( '#wpDestFile' ).val(), |
| 794 | + 'ignorewarnings': 1, |
793 | 795 | 'token' : _this.getToken(), |
| 796 | + 'filename' : _this.getFileName() |
| 797 | + }; |
| 798 | + // presently we don't let the user update desc at ignoreWarningsSubmit |
| 799 | + /* |
794 | 800 | 'comment' : _this.getUploadDescription() |
795 | | - }; |
| 801 | + */ |
| 802 | + |
796 | 803 | //run the upload from stash request |
797 | 804 | mw.getJSON(_this.apiUrl, request, function( data ) { |
798 | 805 | _this.processApiResult( data ); |
— | — | @@ -823,6 +830,10 @@ |
824 | 831 | return false; |
825 | 832 | } |
826 | 833 | }, |
| 834 | + // get the filename from the current form |
| 835 | + getFileName: function() { |
| 836 | + return $j( this.form ).find( "[name='filename']" ).val(); |
| 837 | + }, |
827 | 838 | |
828 | 839 | // Get the editToken from the page. |
829 | 840 | getToken : function(){ |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.UploadInterface.js |
— | — | @@ -16,6 +16,7 @@ |
17 | 17 | mw.addMessages( { |
18 | 18 | "mwe-upload-in-progress" : "Upload in progress (do not close this window)", |
19 | 19 | "mwe-uploaded-status" : "Uploaded", |
| 20 | + "mwe-transcoded-status" : "Transcoded", |
20 | 21 | "mwe-uploaded-time-remaining" : "Time remaining: $1", |
21 | 22 | "mwe-upload-done" : "Your upload <i>should be<\/i> accessible." |
22 | 23 | } ); |
— | — | @@ -117,11 +118,17 @@ |
118 | 119 | .text( '0% -' ), |
119 | 120 | |
120 | 121 | $j( '<span />' ) |
121 | | - .attr( 'id', 'up-status-state' ) |
122 | | - .text( gM( 'mwe-uploaded-status' ) ) |
| 122 | + .attr( 'id', 'up-status-state' ) |
123 | 123 | ) |
124 | 124 | ); |
125 | 125 | |
| 126 | + var $statusState = $progressContainer.find( '#up-status-state' ); |
| 127 | + if( options.statusType == 'transcode' ){ |
| 128 | + $statusState.text( gM( 'mwe-transcoded-status' ) ); |
| 129 | + } else { |
| 130 | + $statusState.text( gM( 'mwe-uploaded-status' ) ); |
| 131 | + } |
| 132 | + |
126 | 133 | // Add the estimated time remaining |
127 | 134 | $progressContainer.append( |
128 | 135 | $j('<span />') |
— | — | @@ -252,10 +259,8 @@ |
253 | 260 | |
254 | 261 | // Generate the error button |
255 | 262 | var buttons = {}; |
256 | | - buttons[ gM( 'mwe-return-to-form' ) ] = function() { |
257 | | - $j( this ).dialog( 'close' ); |
258 | | - // Disable direct submit so that we can handle updated form data |
259 | | - _this.sendUploadAction( 'disableDirectSubmit' ); |
| 263 | + buttons[ gM( 'mwe-return-to-form' ) ] = function() { |
| 264 | + _this.returnToForm( this ); |
260 | 265 | }; |
261 | 266 | |
262 | 267 | |
— | — | @@ -396,8 +401,7 @@ |
397 | 402 | }; |
398 | 403 | // Create the "return to form" button |
399 | 404 | buttons[ gM( 'mwe-return-to-form' ) ] = function() { |
400 | | - $j( this ).dialog( 'close' ); |
401 | | - _this.sendUploadAction( 'disableDirectSubmit' ); |
| 405 | + _this.returnToForm( this ); |
402 | 406 | } |
403 | 407 | // Show warning |
404 | 408 | _this.setPrompt( |
— | — | @@ -416,6 +420,18 @@ |
417 | 421 | // No error! |
418 | 422 | return true; |
419 | 423 | }, |
| 424 | + /** |
| 425 | + * return to the upload form handler |
| 426 | + */ |
| 427 | + returnToForm: function( dialogElement ){ |
| 428 | + $j( dialogElement ).dialog( 'close' ); |
| 429 | + |
| 430 | + // Dissable direct submit on the transport ( so send via sendUploadAction ) |
| 431 | + this.sendUploadAction( 'disableDirectSubmit' ); |
| 432 | + |
| 433 | + // returnToFormCb |
| 434 | + this.sendUploadAction( 'returnToFormCb' ); |
| 435 | + }, |
420 | 436 | |
421 | 437 | /** |
422 | 438 | * Send an upload action to the upload handler. |
— | — | @@ -438,6 +454,7 @@ |
439 | 455 | // "Return" button |
440 | 456 | buttons[ gM( 'mwe-return-to-form' ) ] = function() { |
441 | 457 | $j( this ).dialog( 'destroy' ).remove(); |
| 458 | + _this.sendUploadAction( 'returnToForm' ); |
442 | 459 | _this.sendUploadAction( 'disableDirectSubmit' ); |
443 | 460 | } |
444 | 461 | // "Go to resource" button |
— | — | @@ -473,7 +490,7 @@ |
474 | 491 | mw.log( 'f: getCancelButton()' ); |
475 | 492 | var cancelBtn = []; |
476 | 493 | cancelBtn[ gM( 'mwe-cancel' ) ] = function() { |
477 | | - $j( dlElm ).dialog( 'close' ); |
| 494 | + $j( this ).dialog( 'close' ); |
478 | 495 | }; |
479 | 496 | return cancelBtn; |
480 | 497 | } |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js |
— | — | @@ -388,8 +388,7 @@ |
389 | 389 | |
390 | 390 | // Otherwise show the "install Firefogg" message |
391 | 391 | var firefoggUrl = _this.getFirefoggInstallUrl(); |
392 | | - if( firefoggUrl ) { |
393 | | - |
| 392 | + if( firefoggUrl ) { |
394 | 393 | // Add the target please install in not present: |
395 | 394 | if ( !this.target_please_install ) { |
396 | 395 | $j( this.selector ).after( |
— | — | @@ -788,10 +787,13 @@ |
789 | 788 | return false; |
790 | 789 | } |
791 | 790 | // Setup the interface progress indicator: |
792 | | - _this.ui.setup( { 'title' : gM( 'fogg-transcoding' ) } ); |
| 791 | + _this.ui.setup( { |
| 792 | + 'title' : gM( 'fogg-transcoding' ), |
| 793 | + 'statusType' : 'transcode' |
| 794 | + } ); |
793 | 795 | |
794 | 796 | // Add the preview controls if transcoding: |
795 | | - if ( !_this.getEncoderSettings()['passthrough'] ) { |
| 797 | + if ( !_this.getEncoderSettings()[ 'passthrough' ] ) { |
796 | 798 | _this.createPreviewControls(); |
797 | 799 | } |
798 | 800 | |
— | — | @@ -948,13 +950,17 @@ |
949 | 951 | } |
950 | 952 | // We are doing a firefogg upload: |
951 | 953 | mw.log( "firefogg: doUpload:: " ); |
952 | | - |
953 | | - // Setup the firefogg dialog (if not passthrough ) |
954 | | - _this.ui.setup( { 'title' : gM( 'mwe-upload-transcode-in-progress' ) } ); |
955 | | - |
| 954 | + |
956 | 955 | // Add the preview controls if transcoding: |
957 | 956 | if ( !_this.getEncoderSettings()['passthrough'] ) { |
958 | 957 | _this.createPreviewControls(); |
| 958 | + |
| 959 | + // Setup the firefogg transcode dialog (if not passthrough ) |
| 960 | + _this.ui.setup( { |
| 961 | + 'title' : gM( 'mwe-upload-transcode-in-progress' ), |
| 962 | + 'statusType' : 'transcode' |
| 963 | + } ); |
| 964 | + |
959 | 965 | } |
960 | 966 | |
961 | 967 | |
— | — | @@ -1013,6 +1019,12 @@ |
1014 | 1020 | function /* onDone */ () { |
1015 | 1021 | var uploadRequest = _this.getUploadApiRequest(); |
1016 | 1022 | |
| 1023 | + // Update the UI for uploading |
| 1024 | + _this.ui.setup( { |
| 1025 | + 'title' : gM( 'mwe-upload-in-progress' ), |
| 1026 | + 'statusType' : 'upload' |
| 1027 | + } ); |
| 1028 | + |
1017 | 1029 | mw.log( 'Do POST upload to:' +_this.apiUrl + ' with data:\n' + JSON.stringify( uploadRequest ) ); |
1018 | 1030 | |
1019 | 1031 | _this.fogg.post( _this.apiUrl, 'file', JSON.stringify( uploadRequest ) ); |
— | — | @@ -1125,10 +1137,7 @@ |
1126 | 1138 | } |
1127 | 1139 | |
1128 | 1140 | mw.log( 'doEncode: with: ' + JSON.stringify( encoderSettings ) ); |
1129 | | - _this.fogg.encode( JSON.stringify( encoderSettings ) ); |
1130 | | - |
1131 | | - // Show transcode status: |
1132 | | - $j( '#up-status-state' ).html( gM( 'mwe-upload-transcoded-status' ) ); |
| 1141 | + _this.fogg.encode( JSON.stringify( encoderSettings ) ); |
1133 | 1142 | |
1134 | 1143 | |
1135 | 1144 | // Setup a local function for timed callback: |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.UploadForm.js |
— | — | @@ -192,6 +192,16 @@ |
193 | 193 | 'warn_target' : "#wpDestFile-warning" |
194 | 194 | } ); |
195 | 195 | }, |
| 196 | + |
| 197 | + 'returnToFormCb' : function(){ |
| 198 | + // Enable upload button and remove loader |
| 199 | + $j( '#wpUploadBtn' ) |
| 200 | + .attr( 'disabled', null ) |
| 201 | + .parent() |
| 202 | + .find( '.loading_spinner' ) |
| 203 | + .remove(); |
| 204 | + }, |
| 205 | + |
196 | 206 | 'beforeSubmitCb' : function( ) { |
197 | 207 | buildAssetDescription( options ); |
198 | 208 | } |
— | — | @@ -266,7 +276,15 @@ |
267 | 277 | 'warn_target': '#file-warning' |
268 | 278 | } ); |
269 | 279 | }, |
270 | | - |
| 280 | + 'returnToFormCb' : function(){ |
| 281 | + alert("UPLOAD form returnToFormCb "); |
| 282 | + // Enable upload button and remove loader |
| 283 | + $j( '#wpUploadBtn' ) |
| 284 | + .attr( 'disabled', null ) |
| 285 | + .parent() |
| 286 | + .find( '.loading_spinner' ) |
| 287 | + .remove(); |
| 288 | + }, |
271 | 289 | // Timeout callback |
272 | 290 | 'timeoutCb' : function(){ |
273 | 291 | mw.log("timed out in setting up setupApiFileBrowseProxy"); |
— | — | @@ -291,21 +309,28 @@ |
292 | 310 | .attr( 'disabled', 'disabled' ) |
293 | 311 | .before( |
294 | 312 | $j('<span />').loadingSpinner() |
295 | | - ); |
| 313 | + ); |
296 | 314 | |
| 315 | + // Setup the form data: |
| 316 | + var formData = { |
| 317 | + 'filename' : $j( '#wpDestFile' ).val(), |
| 318 | + 'comment' : $j( '#wpUploadDescription' ).val(), |
| 319 | + } |
297 | 320 | |
| 321 | + if( $j( '#wpWatchthis' ).is( ':checked' ) ) { |
| 322 | + formData[ 'watch' ] = 'true'; |
| 323 | + } |
| 324 | + if( $j('#wpIgnoreWarning' ).is( ':checked' ) ) { |
| 325 | + formData[ 'ignorewarnings' ] = 'true'; |
| 326 | + } |
| 327 | + |
298 | 328 | // Build the output and send upload request to fileProxy |
299 | 329 | mw.ApiProxy.sendServerMsg( { |
300 | 330 | 'apiUrl' : options.apiUrl, |
301 | 331 | 'frameName' : fileIframeName, |
302 | 332 | 'frameMsg' : { |
303 | 333 | 'action' : 'fileSubmit', |
304 | | - 'formData' : { |
305 | | - 'filename' : $j('#wpDestFile').val(), |
306 | | - 'comment' : $j('#wpUploadDescription').val(), |
307 | | - 'watch' : ( $j( '#wpWatchthis' ).is( ':checked' ) ) ? 'true' : 'false', |
308 | | - 'ignorewarnings': ($j('#wpIgnoreWarning' ).is( ':checked' ) ) ? 'true' : 'false' |
309 | | - } |
| 334 | + 'formData' : formData |
310 | 335 | } |
311 | 336 | } ); |
312 | 337 | } ); |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AjaxCategories/loader.js |
— | — | @@ -0,0 +1,5 @@ |
| 2 | + |
| 3 | +// Add the class name define for AjaxCategories |
| 4 | +mw.addClassFilePaths( { |
| 5 | + "mw.AjaxCategories" : "modules/AjaxCategories/mw.AjaxCategories.js" |
| 6 | +} ); |
\ No newline at end of file |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AjaxCategories/mw.AjaxCategories.js |
— | — | @@ -0,0 +1,359 @@ |
| 2 | +mw.addMessages( { |
| 3 | + "ajax-add-category" : "[Add Category]", |
| 4 | + "ajax-add-category-submit" : "[Add]", |
| 5 | + "ajax-confirm-prompt" : "[Confirmation Text]", |
| 6 | + "ajax-confirm-title" : "[Confirmation Title]", |
| 7 | + "ajax-confirm-save" : "[Save]", |
| 8 | + "ajax-add-category-summary" : "[Add category $1]", |
| 9 | + "ajax-remove-category-summary" : "[Remove category $2]", |
| 10 | + "ajax-confirm-actionsummary" : "[Summary]", |
| 11 | + "ajax-error-title" : "Error", |
| 12 | + "ajax-error-dismiss" : "OK", |
| 13 | + "ajax-remove-category-error" : "[RemoveErr]" |
| 14 | +} ); |
| 15 | + |
| 16 | +var defaultAjaxCategoriesOptions = { |
| 17 | + |
| 18 | + // The edit mode can be api, or text box. |
| 19 | + // When set to api, category changes are saved to the target article page |
| 20 | + // when set to textbox category changes are outputed to a text box. |
| 21 | + 'editMode' : 'api' |
| 22 | + |
| 23 | +} |
| 24 | + |
| 25 | +/** |
| 26 | +* AjaxCategories jQuery binder |
| 27 | +* lets you bind a ajaxCategories tool to a div |
| 28 | +*/ |
| 29 | +( function( $ ) { |
| 30 | + $.fn.AjaxCategories = function( options ) { |
| 31 | + var hostElement = $j( this.selector ).get(0); |
| 32 | + // Merge options with defaults and create new mw.AjaxCategories instance |
| 33 | + hostElement.AjaxCategories = mw.AjaxCategories( |
| 34 | + $j.extend( {}, |
| 35 | + defaultAjaxCategoriesOptions, |
| 36 | + {'target' : this.selector}, |
| 37 | + options |
| 38 | + ) |
| 39 | + ); |
| 40 | + } |
| 41 | +} )( jQuery ); |
| 42 | + |
| 43 | +/** |
| 44 | + * AjaxCategories constructor |
| 45 | + */ |
| 46 | +mw.AjaxCategories = function( options ){ |
| 47 | + this.setupAJAXCategories( options ); |
| 48 | +} |
| 49 | +mw.AjaxCategories.prototype = { |
| 50 | + |
| 51 | + setupAJAXCategories : function( options ) { |
| 52 | + |
| 53 | + var clElement = $j( '.catlinks' ); |
| 54 | + |
| 55 | + // Unhide hidden category holders. |
| 56 | + clElement.removeClass( 'catlinks-allhidden' ); |
| 57 | + |
| 58 | + var addLink = $j( '<a/>' ); |
| 59 | + addLink.addClass( 'mw-ajax-addcategory' ); |
| 60 | + |
| 61 | + // Create [Add Category] link |
| 62 | + addLink.text( gM( 'ajax-add-category' ) ); |
| 63 | + addLink.attr( 'href', '#' ); |
| 64 | + addLink.click( ajaxCategories.handleAddLink ); |
| 65 | + clElement.append( addLink ); |
| 66 | + |
| 67 | + // Create add category prompt |
| 68 | + var $promptContainer = $j( '<div />') |
| 69 | + .attr( { |
| 70 | + 'id' : "mw-addcategory-prompt" |
| 71 | + } ); |
| 72 | + |
| 73 | + var $promptTextbox = $j( '<input />') |
| 74 | + .attr( { |
| 75 | + 'type' : "text", |
| 76 | + 'size' : "45", |
| 77 | + 'id' : "mw-addcategory-input" |
| 78 | + } ); |
| 79 | + |
| 80 | + var $addButton = $j( '<input />') |
| 81 | + .attr({ |
| 82 | + 'type' : "button", |
| 83 | + 'id' : "mw-addcategory-button" |
| 84 | + }); |
| 85 | + $addButton.val( gM( 'ajax-add-category-submit' ) ); |
| 86 | + |
| 87 | + $promptTextbox.keypress( ajaxCategories.handleCategoryInput ); |
| 88 | + $addButton.click( ajaxCategories.handleCategoryAdd ); |
| 89 | + |
| 90 | + $promptContainer.append( $promptTextbox ); |
| 91 | + $promptContainer.append( $addButton ); |
| 92 | + $promptContainer.hide(); |
| 93 | + |
| 94 | + // Create delete link for each category. |
| 95 | + $j( '.catlinks div span a' ).each( function( e ) { |
| 96 | + // Create a remove link |
| 97 | + var deleteLink = $j( '<a class="mw-remove-category" href="#"/>' ); |
| 98 | + |
| 99 | + deleteLink.click( ajaxCategories.handleDeleteLink ); |
| 100 | + |
| 101 | + $j( this ).after( deleteLink ); |
| 102 | + } ); |
| 103 | + |
| 104 | + clElement.append( $promptContainer ); |
| 105 | + }, |
| 106 | + |
| 107 | + handleAddLink : function( e ) { |
| 108 | + |
| 109 | + e.preventDefault(); |
| 110 | + |
| 111 | + // Make sure the suggestion plugin is loaded. Load everything else while we're at it |
| 112 | + mw.load( |
| 113 | + ['$j.ui', '$j.ui.dialog', '$j.fn.suggestions'], |
| 114 | + function() { |
| 115 | + $j( '#mw-addcategory-prompt' ).toggle(); |
| 116 | + |
| 117 | + $j( '#mw-addcategory-input' ).suggestions( { |
| 118 | + 'fetch':ajaxCategories.fetchSuggestions, |
| 119 | + 'cancel': function() { |
| 120 | + // TODO support abort mechnism for mwEmbed |
| 121 | + mw.log('Abort request'); |
| 122 | + } |
| 123 | + } ); |
| 124 | + $j( '#mw-addcategory-input' ).suggestions(); |
| 125 | + } |
| 126 | + ); |
| 127 | + }, |
| 128 | + |
| 129 | + fetchSuggestions : function( query ) { |
| 130 | + var that = this; |
| 131 | + var request = { |
| 132 | + 'list': 'allpages', |
| 133 | + 'apnamespace': 14, |
| 134 | + 'apprefix': $j( this ).val() |
| 135 | + }; |
| 136 | + mw.getJSON( request, function( data ) { |
| 137 | + // Process data.query.allpages into an array of titles |
| 138 | + var pages = data.query.allpages; |
| 139 | + var titleArr = []; |
| 140 | + |
| 141 | + $j.each( pages, function( i, page ) { |
| 142 | + var title = page.title.split( ':', 2 )[1]; |
| 143 | + titleArr.push( title ); |
| 144 | + } ); |
| 145 | + |
| 146 | + $j( that ).suggestions( 'suggestions', titleArr ); |
| 147 | + } ); |
| 148 | + |
| 149 | + ajaxCategories.request = request; |
| 150 | + }, |
| 151 | + |
| 152 | + reloadCategoryList : function( response ) { |
| 153 | + var holder = $j( '<div/>' ); |
| 154 | + |
| 155 | + holder.load( |
| 156 | + window.location.href + ' .catlinks', |
| 157 | + function() { |
| 158 | + $j( '.catlinks' ).replaceWith( holder.find( '.catlinks' ) ); |
| 159 | + ajaxCategories.setupAJAXCategories(); |
| 160 | + ajaxCategories.removeProgressIndicator( $j( '.catlinks' ) ); |
| 161 | + } |
| 162 | + ); |
| 163 | + }, |
| 164 | + |
| 165 | + confirmEdit : function( page, fn, actionSummary, doneFn ) { |
| 166 | + // Load jQuery UI |
| 167 | + mw.load( |
| 168 | + ['$j.ui', '$j.ui.dialog', '$j.fn.suggestions'], |
| 169 | + function() { |
| 170 | + // Produce a confirmation dialog |
| 171 | + |
| 172 | + var dialog = $j( '<div/>' ); |
| 173 | + |
| 174 | + dialog.addClass( 'mw-ajax-confirm-dialog' ); |
| 175 | + dialog.attr( 'title', gM( 'ajax-confirm-title' ) ); |
| 176 | + |
| 177 | + // Intro text. |
| 178 | + var confirmIntro = $j( '<p/>' ); |
| 179 | + confirmIntro.text( gM( 'ajax-confirm-prompt' ) ); |
| 180 | + dialog.append( confirmIntro ); |
| 181 | + |
| 182 | + // Summary of the action to be taken |
| 183 | + var summaryHolder = $j( '<p/>' ); |
| 184 | + var summaryLabel = $j( '<strong/>' ); |
| 185 | + summaryLabel.text( gM( 'ajax-confirm-actionsummary' ) + " " ); |
| 186 | + summaryHolder.text( actionSummary ); |
| 187 | + summaryHolder.prepend( summaryLabel ); |
| 188 | + dialog.append( summaryHolder ); |
| 189 | + |
| 190 | + // Reason textbox. |
| 191 | + var reasonBox = $j( '<input type="text" size="45" />' ); |
| 192 | + reasonBox.addClass( 'mw-ajax-confirm-reason' ); |
| 193 | + dialog.append( reasonBox ); |
| 194 | + |
| 195 | + // Submit button |
| 196 | + var submitButton = $j( '<input type="button"/>' ); |
| 197 | + submitButton.val( gM( 'ajax-confirm-save' ) ); |
| 198 | + |
| 199 | + var submitFunction = function() { |
| 200 | + dialog.loadingSpinner(); |
| 201 | + ajaxCategories.doEdit( |
| 202 | + page, |
| 203 | + fn, |
| 204 | + reasonBox.val(), |
| 205 | + function() { |
| 206 | + doneFn(); |
| 207 | + dialog.dialog( 'close' ); |
| 208 | + ajaxCategories.removeProgressIndicator( dialog ); |
| 209 | + } |
| 210 | + ); |
| 211 | + }; |
| 212 | + |
| 213 | + var buttons = { }; |
| 214 | + buttons[gM( 'ajax-confirm-save' )] = submitFunction; |
| 215 | + var dialogOptions = { |
| 216 | + 'AutoOpen' : true, |
| 217 | + 'buttons' : buttons, |
| 218 | + 'width' : 450 |
| 219 | + }; |
| 220 | + |
| 221 | + $j( '#catlinks' ).prepend( dialog ); |
| 222 | + dialog.dialog( dialogOptions ); |
| 223 | + } |
| 224 | + ); |
| 225 | + }, |
| 226 | + |
| 227 | + doEdit : function( page, fn, summary, doneFn ) { |
| 228 | + // Get an edit token and page revision info |
| 229 | + var getTokenVars = { |
| 230 | + 'prop':'info|revisions', |
| 231 | + 'intoken':'edit', |
| 232 | + 'titles':page, |
| 233 | + 'rvprop':'content|timestamp' |
| 234 | + }; |
| 235 | + |
| 236 | + mw.getJSON( getTokenVars, function( reply ) { |
| 237 | + var infos = reply.query.pages; |
| 238 | + $j.each( |
| 239 | + infos, |
| 240 | + function( pageid, data ) { |
| 241 | + var token = data.edittoken; |
| 242 | + var timestamp = data.revisions[0].timestamp; |
| 243 | + var oldText = data.revisions[0]['*']; |
| 244 | + |
| 245 | + var newText = fn( oldText ); |
| 246 | + |
| 247 | + if ( newText === false ) return; |
| 248 | + |
| 249 | + var postEditVars = { |
| 250 | + 'action':'edit', |
| 251 | + 'title':page, |
| 252 | + 'text':newText, |
| 253 | + 'summary':summary, |
| 254 | + 'token':token, |
| 255 | + 'basetimestamp':timestamp, |
| 256 | + 'format':'json' |
| 257 | + }; |
| 258 | + |
| 259 | + $j.post( wgScriptPath + '/api.php', postEditVars, doneFn, 'json' ); |
| 260 | + } |
| 261 | + ); |
| 262 | + } ); |
| 263 | + }, |
| 264 | + |
| 265 | + addProgressIndicator : function( elem ) { |
| 266 | + var indicator = $j( '<div/>' ); |
| 267 | + |
| 268 | + indicator.addClass( 'mw-ajax-loader' ); |
| 269 | + |
| 270 | + elem.append( indicator ); |
| 271 | + }, |
| 272 | + |
| 273 | + removeProgressIndicator : function( elem ) { |
| 274 | + elem.find( '.mw-ajax-loader' ).remove(); |
| 275 | + }, |
| 276 | + |
| 277 | + handleCategoryAdd : function( e ) { |
| 278 | + // Grab category text |
| 279 | + var category = $j( '#mw-addcategory-input' ).val(); |
| 280 | + var appendText = "\n[[" + wgFormattedNamespaces[14] + ":" + category + "]]\n"; |
| 281 | + var summary = gM( 'ajax-add-category-summary', category ); |
| 282 | + |
| 283 | + ajaxCategories.confirmEdit( |
| 284 | + wgPageName, |
| 285 | + function( oldText ) { return oldText + appendText }, |
| 286 | + summary, |
| 287 | + ajaxCategories.reloadCategoryList |
| 288 | + ); |
| 289 | + }, |
| 290 | + |
| 291 | + handleDeleteLink : function( e ) { |
| 292 | + e.preventDefault(); |
| 293 | + |
| 294 | + var category = $j( this ).parent().find( 'a' ).text(); |
| 295 | + |
| 296 | + // Build a regex that matches legal invocations of that category. |
| 297 | + |
| 298 | + // In theory I should escape the aliases, but there's no JS function for it |
| 299 | + // Shouldn't have any real impact, can't be exploited or anything, so we'll |
| 300 | + // leave it for now. |
| 301 | + var categoryNSFragment = ''; |
| 302 | + $j.each( wgNamespaceIds, function( name, id ) { |
| 303 | + if ( id == 14 ) { |
| 304 | + // Allow the first character to be any case |
| 305 | + var firstChar = name.charAt( 0 ); |
| 306 | + firstChar = '[' + firstChar.toUpperCase() + firstChar.toLowerCase() + ']'; |
| 307 | + categoryNSFragment += '|' + firstChar + name.substr( 1 ); |
| 308 | + } |
| 309 | + } ); |
| 310 | + categoryNSFragment = categoryNSFragment.substr( 1 ); // Remove leading | |
| 311 | + |
| 312 | + // Build the regex |
| 313 | + var titleFragment = category; |
| 314 | + |
| 315 | + firstChar = category.charAt( 0 ); |
| 316 | + firstChar = '[' + firstChar.toUpperCase() + firstChar.toLowerCase() + ']'; |
| 317 | + titleFragment = firstChar + category.substr( 1 ); |
| 318 | + var categoryRegex = '\\[\\[' + categoryNSFragment + ':' + titleFragment + '(\\|[^\\]]*)?\\]\\]'; |
| 319 | + categoryRegex = new RegExp( categoryRegex, 'g' ); |
| 320 | + |
| 321 | + var summary = gM( 'ajax-remove-category-summary', category ); |
| 322 | + |
| 323 | + ajaxCategories.confirmEdit( |
| 324 | + wgPageName, |
| 325 | + function( oldText ) { |
| 326 | + var newText = oldText.replace( categoryRegex, '' ); |
| 327 | + |
| 328 | + if ( newText == oldText ) { |
| 329 | + var error = gM( 'ajax-remove-category-error' ); |
| 330 | + ajaxCategories.showError( error ); |
| 331 | + ajaxCategories.removeProgressIndicator( $j( '.mw-ajax-confirm-dialog' ) ); |
| 332 | + $j( '.mw-ajax-confirm-dialog' ).dialog( 'close' ); |
| 333 | + return false; |
| 334 | + } |
| 335 | + |
| 336 | + return newText; |
| 337 | + }, |
| 338 | + summary, ajaxCategories.reloadCategoryList |
| 339 | + ); |
| 340 | + }, |
| 341 | + |
| 342 | + showError : function( str ) { |
| 343 | + var dialog = $j( '<div/>' ); |
| 344 | + dialog.text( str ); |
| 345 | + |
| 346 | + $j( '#bodyContent' ).append( dialog ); |
| 347 | + |
| 348 | + var buttons = { }; |
| 349 | + buttons[gM( 'ajax-error-dismiss' )] = function( e ) { |
| 350 | + dialog.dialog( 'close' ); |
| 351 | + }; |
| 352 | + var dialogOptions = { |
| 353 | + 'buttons' : buttons, |
| 354 | + 'AutoOpen' : true, |
| 355 | + 'title' : gM( 'ajax-error-title' ) |
| 356 | + }; |
| 357 | + |
| 358 | + dialog.dialog( dialogOptions ); |
| 359 | + } |
| 360 | +}; |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AjaxCategories/README |
— | — | @@ -0,0 +1 @@ |
| 2 | +Port of ajaxcategories to mwEmbed module |
\ No newline at end of file |
Index: branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/kplayerEmbed.js |
— | — | @@ -82,6 +82,7 @@ |
83 | 83 | |
84 | 84 | //alert( this.playerElement ); |
85 | 85 | if( this.playerElement && this.playerElement.addJsListener ) { |
| 86 | + |
86 | 87 | // Add KDP listeners |
87 | 88 | _this.bindPlayerFunction( 'doPause', 'onPause' ); |
88 | 89 | _this.bindPlayerFunction( 'doPlay', 'onPlay' ); |
— | — | @@ -134,8 +135,9 @@ |
135 | 136 | * calls parent_play to update the interface |
136 | 137 | */ |
137 | 138 | play: function() { |
138 | | - if( this.playerElement && this.playerElement.sendNotification ) |
| 139 | + if( this.playerElement && this.playerElement.sendNotification ){ |
139 | 140 | this.playerElement.sendNotification( 'doPlay' ); |
| 141 | + } |
140 | 142 | this.parent_play(); |
141 | 143 | }, |
142 | 144 | |
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js |
— | — | @@ -114,7 +114,18 @@ |
115 | 115 | var uploadDialogInterface = new mw.UploadDialogInterface( { |
116 | 116 | 'uploadHandlerAction' : function( action ){ |
117 | 117 | mw.log( 'apiProxy uploadActionHandler:: ' + action ); |
118 | | - // Send action to remote frame |
| 118 | + |
| 119 | + // Handle actions that don't need to go to the iframe: |
| 120 | + switch ( action ){ |
| 121 | + case 'returnToFormCb': |
| 122 | + if( options.returnToFormCb ){ |
| 123 | + options.returnToFormCb(); |
| 124 | + } |
| 125 | + return ; |
| 126 | + break; |
| 127 | + } |
| 128 | + |
| 129 | + // Handle actions that get sent to the remote frame |
119 | 130 | mw.ApiProxy.sendServerMsg( { |
120 | 131 | 'apiUrl' : options.apiUrl, |
121 | 132 | 'frameName' : iFrameName, |
— | — | @@ -127,7 +138,7 @@ |
128 | 139 | } ); |
129 | 140 | |
130 | 141 | // Setup the context with the callback in the current closure |
131 | | - var context = createContext({ |
| 142 | + var context = createContext( { |
132 | 143 | 'apiUrl' : options.apiUrl, |
133 | 144 | // Setup the callback to process iframeData |
134 | 145 | 'callback' : function( iframeData ) { |
— | — | @@ -143,14 +154,14 @@ |
144 | 155 | } |
145 | 156 | mw.log( '~browseFile Callback~ event type: ' + iframeData['event'] ); |
146 | 157 | |
147 | | - // Else check for event |
| 158 | + // Handle events: |
148 | 159 | if( iframeData['event'] ) { |
149 | 160 | switch( iframeData['event'] ) { |
150 | 161 | case 'selectFileCb': |
151 | 162 | if( options.selectFileCb ) { |
152 | 163 | options.selectFileCb( iframeData[ 'fileName' ] ); |
153 | 164 | } |
154 | | - break |
| 165 | + break |
155 | 166 | // Set the doneUploadCb if set in the browseFile options |
156 | 167 | case 'doneUploadCb': |
157 | 168 | mw.log( "should call cb: " + options.doneUploadCb ); |
— | — | @@ -312,11 +323,11 @@ |
313 | 324 | */ |
314 | 325 | $.handleServerMsg = function( frameMsg ){ |
315 | 326 | mw.log( "handleServerMsg:: " + JSON.stringify( frameMsg ) ); |
316 | | - if( ! frameMsg.action ){ |
| 327 | + if( ! frameMsg.action ) { |
317 | 328 | mw.log(" missing frameMsg action " ); |
318 | 329 | return false; |
319 | 330 | } |
320 | | - switch( frameMsg.action ){ |
| 331 | + switch( frameMsg.action ) { |
321 | 332 | case 'fileSubmit': |
322 | 333 | serverSubmitFile( frameMsg.formData ); |
323 | 334 | break; |
— | — | @@ -374,7 +385,7 @@ |
375 | 386 | * @return context object |
376 | 387 | * false if context object can not be found |
377 | 388 | */ |
378 | | - function getContext ( contextKey ){ |
| 389 | + function getContext ( contextKey ) { |
379 | 390 | if( ! proxyContext [ contextKey ] ){ |
380 | 391 | mw.log( "Error: contextKey not found:: " + contextKey ); |
381 | 392 | return false; |
— | — | @@ -416,8 +427,8 @@ |
417 | 428 | * @param {URL} apiUrl The url of the api server |
418 | 429 | */ |
419 | 430 | // Include gadget js ( in case the user has not enabled the gadget on that domain ) |
420 | | - var gadgetWithJS = '?withJS=MediaWiki:MwEmbed.js'; |
421 | | - //var gadgetWithJS = ''; |
| 431 | + //var gadgetWithJS = '?withJS=MediaWiki:MwEmbed.js'; |
| 432 | + var gadgetWithJS = ''; |
422 | 433 | function getServerFrame( context ) { |
423 | 434 | if( ! context || ! context.apiUrl ){ |
424 | 435 | mw.log( "Error no context api url " ); |
— | — | @@ -513,7 +524,7 @@ |
514 | 525 | // FIXME offer the user the ability to "approve" requested domain save to |
515 | 526 | // their user preference setup ) |
516 | 527 | |
517 | | - // FIXME grab the users whitelist for our current domain |
| 528 | + // FIXME grab and check domain against the users whitelist and permissions |
518 | 529 | return false; |
519 | 530 | } |
520 | 531 | |
— | — | @@ -784,7 +795,12 @@ |
785 | 796 | 'fileName' : fileName |
786 | 797 | } ); |
787 | 798 | }, |
788 | | - |
| 799 | + // The return to form cb: |
| 800 | + 'returnToFormCb' : function (){ |
| 801 | + sendClientMsg( { |
| 802 | + 'event': 'returnToFormCb' |
| 803 | + } ); |
| 804 | + }, |
789 | 805 | // Api proxy does not handle descriptionText rewrite |
790 | 806 | 'rewriteDescriptionText' : false, |
791 | 807 | |
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js |
— | — | @@ -30,15 +30,12 @@ |
31 | 31 | } |
32 | 32 | |
33 | 33 | /* |
34 | | -* Set the mwEmbedVersion ( not set by stopgap ) |
| 34 | +* Set the mwEmbedVersion |
35 | 35 | */ |
36 | | -var MW_EMBED_VERSION = '1.1d'; |
| 36 | +var MW_EMBED_VERSION = '1.1e'; |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * The global mw object: |
40 | | -* |
41 | | -* Any global functions/classes that are not jQuery plugins should make |
42 | | -* there way into the mw namespace |
43 | 40 | */ |
44 | 41 | ( function( mw ) { |
45 | 42 | |
— | — | @@ -49,9 +46,7 @@ |
50 | 47 | mw.version = MW_EMBED_VERSION |
51 | 48 | |
52 | 49 | /** |
53 | | - * Configuration System: |
54 | | - * |
55 | | - * Simple system of inherit defaults, with getter setter functions: |
| 50 | + * Configuration System: |
56 | 51 | */ |
57 | 52 | |
58 | 53 | // Local scope configuration var: |
— | — | @@ -577,12 +572,13 @@ |
578 | 573 | } |
579 | 574 | node = node['p']; |
580 | 575 | } |
581 | | - if ( !node['t'] ) |
| 576 | + if ( !node['t'] ) { |
582 | 577 | node['t'] = ''; |
| 578 | + } |
583 | 579 | // Don't put }} closures into output: |
584 | | - if ( txt[a] && txt[a] != '}' ) |
| 580 | + if ( txt[a] && txt[a] != '}' ) { |
585 | 581 | node['t'] += txt[a]; |
586 | | - |
| 582 | + } |
587 | 583 | } |
588 | 584 | return node; |
589 | 585 | } |
— | — | @@ -1380,6 +1376,7 @@ |
1381 | 1377 | } |
1382 | 1378 | ); |
1383 | 1379 | } |
| 1380 | + |
1384 | 1381 | /** |
1385 | 1382 | * mediaWiki JSON a wrapper for jQuery getJSON: |
1386 | 1383 | * |
— | — | @@ -2831,8 +2828,8 @@ |
2832 | 2829 | "mwe-load-drag-item" : "Loading dragged item", |
2833 | 2830 | "mwe-ok" : "OK", |
2834 | 2831 | "mwe-cancel" : "Cancel", |
2835 | | - "mwe-enable-gadget" : "Enable mwEmbed gadget for all pages", |
2836 | | - "mwe-enable-gadget-done" : "mwEmbed gadget has been enabled", |
| 2832 | + "mwe-enable-gadget" : "Enable multimedia beta ( mwEmbed ) for all pages", |
| 2833 | + "mwe-enable-gadget-done" : "multimedia beta gadget has been enabled", |
2837 | 2834 | "mwe-must-login-gadget" : "To enable gadget you must <a target=\"_new\" href=\"$1\">login</a>", |
2838 | 2835 | "mwe-test-plural" : "I ran {{PLURAL:$1|$1 test|$1 tests}}" |
2839 | 2836 | } ); |