Needs work
Project:
Inline
Version:
5.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
3 Mar 2007 at 06:33 UTC
Updated:
2 Jun 2011 at 23:30 UTC
Jump to comment: Most recent file
I would like to use img_assist together with other wiki filters (mostly Mediawiki). For that the generated code must be changed depending on the wiki syntax used.
At the moment, only HTML and img_assist filter syntax is supported. The attached patch can also create output for Mediawiki, Dokuwiki and Creole syntax.
I just added these to the insertion modes and added javascript functions for each. Is this the right way to add these additional options, or do you prefer another way?
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | img_assist_plugin.js_.txt | 1.16 KB | rötzi |
| #8 | pearwiki_filter_img_assist.patch | 1.14 KB | rötzi |
| #7 | pearwiki_img_assist.patch | 16.34 KB | rötzi |
| #6 | img_assist_plugin.patch | 5.99 KB | rötzi |
| img_assist_wiki_filters.patch | 4.24 KB | rötzi |
Comments
Comment #1
rötzi commentedNote that not all formatting options are supported by the different outputs. I checked against pearwiki_filter on my tests, and this filter does not support all possible syntax options on image tags for the different wiki filters.
Comment #2
koorneef commented+1
This is a very important patch for making wiki's and images more user friendly.
I applied the patch and it worked as advertised.
Comment #3
zoo33 commentedI think with this added flexibility there would have to be a configuration option for selecting what formats should be available to the users.
The patch looks clean enough. I'm just thinking: where will we end up if more input formats are added? For example, you could do the same for Markdown and Textile.
A nice solution would be to have a subdirectory called filters where we could put files that handled one filter each: img_assist_filter_standard.inc, img_assist_filter_html.inc, img_assist_filter_mediawiki.inc etc. (Maybe there would also have to be javascript counterparts in there: img_assist_filter_standard.js etc.) That way, people could easily add their own filters without altering img_assist.
That's kind of a big challange though. Anyone interested in working on a solution like that? Is it even a good idea?
Comment #4
rötzi commentedYou certainly go in the right direction.
One question is if the plugins should be in the img_assist directory or in the respective filter directories. So if pearwiki_filter and textile filter provide a plugin, I would say it makes more sense to keep them in the filter directories.
I would say the standard Drupal way is to provide a hook where other modules (i.e. pearwiki_filter, textile img_assist and so on) can provide an additional output type. Then you can call those hooks and collect the needed data (javascript, filter name, maybe stylesheet). Whit this data you include the needed javascript files and provide the UI to select which filters should be available for selection.
The php part is rather simple, I don't know that much about javascript, but if you have a naming convention for the functions you could just call a 'img_assist_filter_$filtername' function in javascript which creates the output. But I don't know if you can call a function by name in javascript as you can do in PHP.
I have seen that the HTML part is handled differently though. I didn't look at it more closely and don't know if it could just be integrated into the hook system or if it is a special case.
Comment #5
zoo33 commentedYou're right, there is no need to add an additional plug-in mechanism when we already have one (the module system). Implementing this as Drupal modules would also make it easy for admins to enable/disable formats: just enable the modules that correspond to the formats you want to use. (It would also make it possible for input format modules like Pearwiki_filter to implement the necessary hooks for integration with img_assist, so you wouldn't actually have to create any additional modules – although it might be better to keep this functionality separate.)
A natural consequence of this would be that img_assist's input filter should be moved to it's own module which takes care of the filter work and implements these new hooks. The HTML format is indeed a special case and could be kept as a standard fallback format in img_assist.module. We could do this without changing the user's view of img_assist at all (except admins would have to enable two modules instead of one).
A good start would be to outline an example module. I'd take img_assist's filter and try to make an example module out of that. That should make it obvious what hooks need to be created and what arguments they should have. It sure sounds like interesting work, but I don't have time to do it right now.
I think this is a good plan!
Comment #6
rötzi commentedI have actually started with implementing this. Take a look, it should alredy work (I haven't tried TinyMCE, but the it should behave the same. pearwiki filter works). How I did it:
- Added a hook 'img_assist'.
- Added function '_img_assist_filter_data' which collects data from hooks.
- module img_assist implements hook for it's filter tag and HTML code (it works this way too, no special case needed)
- img_assist.js checks if a function named 'getFilterTag_$format' exists
-- if yes, call it
-- if no, call default 'getFilterTag'. this should maintain compatibility with TinyMCE, but I havent tested it.
I tested Opera and Firefox for the javascript part.
As you see in the patch, the 'css' data field is not used at the moment, so maybe this can be omitted.
Another issue is that the same javascript files are included more than once.
Comment #7
rötzi commentedpatch for pearwiki_filter to work with this
Comment #8
rötzi commentedIgnore the last patch, this is the correct one for pearwiki_filter
Comment #9
rötzi commentedAnd this javascript file needs to be put into the pearwiki_filter module directory
Comment #10
zoo33 commentedWow, that's awesome! I guess it's true: talk is silver, code is gold, right? :)
I haven't tested this, nor have I looked properly at the code, but it all sounds very good! And the patch actually looks a lot smaller than I thought, which is promising.
I will test and review this properly as soon as I can. I've got some day job type work to do first...
Comment #11
zoo33 commentedOK, I've looked through the code a little more now. Looks good! It's nice to see how easy it would be for an input format module to implement this.
So, I had a couple of thoughts, still without having tested it:
Thanks for the work you put into this, I think it'll come out great! The Drupal kids are gonna love you for this! (I will anyway.) :)
Comment #12
rötzi commented1. This would be nice for usability when input fields which are not supported get hidden. But since this is needed in the javascript this should probably be provided via the javascript file and not in the hook. Or how would you access this information in the img_assist.js file?
2. For me the reason that pearwiki_filter needs this is enough justification ;) But the way that 'module_invoke_all' works is by merging all results of the different hooks, so it makes sense to do it that way.
3. ok
4. I don't really understand what you mean...
5. No, haven't checked anything related to TinyMCE yet
6. This should be as easy as moving all filter related function to it's own file.
Comment #13
zoo33 commentedNot sure... Maybe trough some query string? Anyway, that can definitely be saved for a later time.
Sorry. The question is simply: Should filter modules be able to talk to TinyMCE through img_assist? That would make it possible for a tag like [myimagetag|1354] to be interpreted by TinyMCE and displayed as an image in the WYSIWYG field. Now that I think about it though, it would probably be more reasonable to have such modules provide their own TinyMCE plugins (like "drupalimage", which is img_assist's plugin).
So, what we need now is testing I guess. And more reviews wouldn't hurt. We should also test how this behaves with TinyMCE. I'll do that as soon as I can, as well as doing another filter implementation as a way of testing the developer part of it.
Comment #14
zoo33 commentedSorry, haven't had any time to work on this so far. It wouldn't hurt if someone could help reviewing and testing this patch.
Comment #15
kpm commentedSorry for the dumb question, but how does one apply such a patch??
Comment #16
zoo33 commentedTake a look at this page in the handbook.
Comment #17
ashtonium commentedsubscribing. I should be able to do some testing on this in a few days.
As far as moving to a seperate module, there are a number of generalized, "hookable" filter modules springing up, it may be possible to merge/piggyback with one of them.
Comment #18
sunAren't those input filters supporting HTML? If they do, this issue should only force img_assist filter to come first, i.e. in front of all other input filters.
Comment #19
sunImg_Assist certainly won't be able to support and maintain all of these input filter tags. However,
1) Implement a new
hook_image_syntax()that allows input filters to describe how they interprete images.2) On processing of img_assist filter, img_assist invokes
module_invoke_all('image_syntax')to retrieve a custom image syntax (or uses default HTML if nothing is returned) and render the image tag.3) Ensure that img_assist is always executed in front of other input filters.
Now the show stopper:
All of this won't work out, if more than one input filter is installed (+ enabled) that provides an alternative input syntax and therefore would implement this hook.
Comment #20
Neto Mussauer commentedHi all,
I try to apply the patch and get the error message:
netomussauer@netomussauer-laptop:~/backup/diversos/arquivos/drupal/sagu-pro/modulos/img_assist$ patch < img_assist_wiki_filters.patch
patching file img_assist.js
Hunk #1 FAILED at 131.
1 out of 1 hunk FAILED -- saving rejects to file img_assist.js.rej
patching file img_assist.module
Hunk #1 succeeded at 327 (offset 12 lines).
Hunk #2 succeeded at 957 with fuzz 2 (offset 1 line).
patching file img_assist_textarea.js
Hunk #1 succeeded at 79 with fuzz 1 (offset 3 lines).
Sorry for my english, im a brazilian guy
Comment #21
zoo33 commentedPlease note that when you change the title, you change the whole issue's title.
As for applying these patches, you will probably have a hard time due to the fact that there has been so many changes to the module since they were rolled. The patch program gets confused. You can either check out a version from CVS from the time when the patches were posted and try to apply them, or someone will have to examine them manually and roll new patches.
But I think this effort could use some rethinking. Sun's thoughts above seem like a good starting point.
Comment #22
sunSo now that work on Inline API has begun, this feature request fits much better there. This is a feature, any input filter would benefit from - because of that, I'm moving this issue to Inline's queue.
Comment #23
grub commentedCan anybody provide a similar patch for 6.x?
Comment #24
elBradford commentedUsing the latest dev version (6.x-3.x-dev) I just replaced line 76 of img_assist_textarea.js with
and it works for the PEAR wiki filter I have running. This was simpler than figuring out how to patch version 6.
Comment #25
elBradford commentedI've gotten it to work even better by adding the following lines of code:
var size = formObj['edit-size-label'][formObj['edit-size-label'].selectedIndex].text;in the getFilterTag function in img_assist_textarea.js followed by
var content = '[[Image:' + captionTitle + '|' + align + '|' + width + 'x' + height + 'px' + '|' + captionDesc + '|' + size.toLowerCase() +']]';The size variable gives me the size selected in the dropdown menu which I can then use in the PEAR wiki module as described here: #1177192: Use image module presets in image