From 5ea5952cd11bd384a54c22bdc3b138372f8c4cf0 Mon Sep 17 00:00:00 2001 From: Prateek Saxena Date: Tue, 20 Oct 2015 19:18:31 +0530 Subject: [PATCH] Use mw.Upload.Dialog to upload and insert file Bug: T115748 Change-Id: I2427cd959f0d9b6872866e120e7bd0e7e298ec27 --- .jshintrc | 3 ++- extension.json | 5 ++++- i18n/en.json | 1 + i18n/qqq.json | 1 + modules/jquery.wikiEditor.dialogs.config.js | 23 +++++++++++++++++++-- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.jshintrc b/.jshintrc index 81d1fa7b..5595507f 100644 --- a/.jshintrc +++ b/.jshintrc @@ -29,6 +29,7 @@ "globals": { "mediaWiki": false, "jQuery": false, - "QUnit": false + "QUnit": false, + "OO": true } } diff --git a/extension.json b/extension.json index b7762b25..97246f96 100644 --- a/extension.json +++ b/extension.json @@ -84,6 +84,8 @@ "jquery.wikiEditor.dialogs", "jquery.wikiEditor.toolbar.i18n", "jquery.suggestions", + "mediawiki.Upload.Dialog", + "mediawiki.ForeignStructuredUpload.BookletLayout", "mediawiki.api", "mediawiki.RegExp", "mediawiki.Title", @@ -99,7 +101,8 @@ "wikieditor-toolbar-file-format-none", "wikieditor-toolbar-file-format", "wikieditor-toolbar-tool-file-insert", - "wikieditor-toolbar-tool-file-cancel" + "wikieditor-toolbar-tool-file-cancel", + "wikieditor-toolbar-tool-file-upload" ], "templates": { "dialogInsertFile.html": "templates/dialogInsertFile.html", diff --git a/i18n/en.json b/i18n/en.json index a53e2c45..0697fc12 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -69,6 +69,7 @@ "wikieditor-toolbar-file-format-none": "none", "wikieditor-toolbar-tool-file-insert": "Insert", "wikieditor-toolbar-tool-file-cancel": "Cancel", + "wikieditor-toolbar-tool-file-upload": "Upload", "wikieditor-toolbar-tool-reference": "Reference", "wikieditor-toolbar-tool-reference-example": "Insert footnote text here", "wikieditor-toolbar-tool-reference-cancel": "Cancel", diff --git a/i18n/qqq.json b/i18n/qqq.json index 56748af6..56dd5516 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -91,6 +91,7 @@ "wikieditor-toolbar-file-format-none": "Option in file dialog for no format for the added image.\n{{Identical|None}}", "wikieditor-toolbar-tool-file-insert": "{{Identical|Insert}}", "wikieditor-toolbar-tool-file-cancel": "{{Identical|Cancel}}", + "wikieditor-toolbar-tool-file-upload": "Label for button that opens the upload dialog", "wikieditor-toolbar-tool-reference": "{{Identical|Reference}}", "wikieditor-toolbar-tool-reference-example": "Used as example text when inserting a reference into the editbox from the toolbar", "wikieditor-toolbar-tool-reference-cancel": "{{Identical|Cancel}}", diff --git a/modules/jquery.wikiEditor.dialogs.config.js b/modules/jquery.wikiEditor.dialogs.config.js index 857828b0..203b2f37 100644 --- a/modules/jquery.wikiEditor.dialogs.config.js +++ b/modules/jquery.wikiEditor.dialogs.config.js @@ -3,7 +3,7 @@ */ /*jshint curly:false, noarg:false, quotmark:false, onevar:false */ /*global alert */ -( function ( $, mw ) { +( function ( $, mw, OO ) { var hasOwn = Object.prototype.hasOwnProperty; @@ -781,6 +781,25 @@ $.wikiEditor.modules.dialogs.config = { }, 'wikieditor-toolbar-tool-file-cancel': function () { $( this ).dialog( 'close' ); + }, + 'wikieditor-toolbar-tool-file-upload': function () { + var windowManager = new OO.ui.WindowManager(), + uploadDialog = new mw.Upload.Dialog( { + bookletClass: mw.ForeignStructuredUpload.BookletLayout + } ); + + $( this ).dialog( 'close' ); + $( 'body' ).append( windowManager.$element ); + windowManager.addWindows( [ uploadDialog ] ); + windowManager.openWindow( uploadDialog ); + + uploadDialog.uploadBooklet.on( 'fileSaved', function ( imageInfo ) { + uploadDialog.close(); + windowManager.$element.remove(); + + $.wikiEditor.modules.dialogs.api.openDialog( this, 'insert-file' ); + $( '#wikieditor-toolbar-file-target' ).val( imageInfo.canonicaltitle ); + } ); } }, open: function () { @@ -1224,4 +1243,4 @@ $.wikiEditor.modules.dialogs.config = { }; -}( jQuery, mediaWiki ) ); +}( jQuery, mediaWiki, OO ) );