Wysiwyg editors are often used to embed images, but many users don't want to (or don't understand how to) translate between the URLs of uploaded files and the "add an image" field.

For user accounts with file upload privileges, it would be nice to allow the user to upload files directly in the Wysiwyg editor.

The attached patch defines a means for any particular editor backend to support this kind of upload, and implements the relevant parts for the yui backend.

Compliant backends should:

  1. modify their javascript to add a file upload input which does an AJAX POST to wysiwyg/upload (only if Drupal.settings.wysiwyg.upload_files_allowed is true)
  2. define a php function which accepts the POSTed file(s), and emits to the browser whatever information the javascript in the browser needs (e.g. a JSON response to be fed back to the AJAX requestor)
  3. refer to the php function in the upload callback member of their $editor object. (see changes to editors/yui/yui.inc in this patch for more details).

This patch should apply successfully to 6.x-2.x-dev, and has been tested to work fine with the YUI editor backend version 2.7.0b.

CommentFileSizeAuthor
wysiwyg-upload-image.patch10.75 KBdkg

Comments

dkg’s picture

Note: this plugin would not have been possible without significant work from Dennis at allmybrain.com. Thanks, Dennis!

twod’s picture

Status: Patch (to be ported) » Needs review

Wysiwyg module is about providing basic editor functionality and allowing other modules to extend that. File uploads are an optional part of some editors and we still have much work to do with the basics. I think adding this code would extend the API and the scope of this module to a point which it's not ready for yet. I think Sun would agree with me on this. I do think it would become an excellent add-on module if refactored to use the native plugin hook from Wysiwyg. Such an 'API-extension module' would also help developing this module by requesting additional generic core features/hooks to be implemented for the benefit of all other Wysiwyg-related modules.

Back to the patch itself. All indents should be two spaces per step to conform with the code guidelines. Opening { is not placed on a new line. Function arguments should not have a leading/trailing space.

sun’s picture

Status: Needs review » Closed (won't fix)

Sorry, but TwoD is right. In general, we are not interested in the native file/image uploading functionalities of the supported editors, because those native file browsers/uploaders are circumventing Drupal's file management, access system, and everything else you can think of.

There are already various community efforts to improve the current situation. The most simple implementation would be the usage of IMCE in combination with http://drupal.org/project/imce_wysiwyg. However, there are also some more revolutionizing efforts, namely the combination of http://drupal.org/project/media and http://drupal.org/project/inline (which will soon replace http://drupal.org/project/img_assist)

sun’s picture

That said, imce_wysiwyg does not contain an integration for YUI yet. Patches welcome ;)

dkg’s picture

Thanks for the feedback. i was unaware of these other modules. The patch provided takes care to not do an end-run around the drupal file upload limitations, and rejects uploads that violate quota or file size limits.

But i see your point about using a general upload manager like IMCE which would also provide a browser interface.

I'll look into what it takes to make a patch to integrate IMCE with yui through wysiwyg.