Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
filter.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
10 Oct 2008 at 22:12 UTC
Updated:
26 Nov 2008 at 12:01 UTC
Jump to comment: Most recent file
Comments
Comment #2
moshe weitzman commentedWe cache filtered string by md5(text). do we need to add language to the cache key?
Comment #3
nedjo@moshe weitzman: Yes, I think you're right.
In url() and l() we can pass a language in the $options array, but in that case it's a language object and not a string. Maybe for consistency we should be passing an object here as well?
Comment #4
stella commentedHere's an updated patch that includes the language string in the cache key.
Cheers,
Stella
Comment #5
nedjoThanks Stella!
A minor point. I'm thinking we should use $langcode instead of $language for the variable name, for consistency in the rest of core where $language tends to be a language object and $langcode the code, as used here.
Comment #6
stella commentedHere's an updated patch which uses $langcode instead. I've also attached a patch to update the hook_filter() api documentation.
Comment #7
dries commentedIt would be good if you could describe in the phpdoc (i) the format of the language code and more importantly (ii) why the language code matters and what it could/would be used for.
I'm also wondering if this affects any of our tests -- it should.
Comment #8
stella commentedI'm using the latest version of Drupal from HEAD. I ran all of the simple tests before I made the change and again afterwards. No additional simple tests failed because of the application of the patch.
Will take a look at improving the php documentation.
Cheers,
Stella
Comment #9
stella commentedUpdated patch with improved function documentation.
I was wondering though, if no language code is provided to check_markup(), should check_markup() provide the code of the current language to hook_filter() or should it be left to the hook_filter() to determine the current language code if it requires it? Currently, the patch assumes the latter.
Cheers,
Stella
Comment #10
moshe weitzman commentedI know that I got us started down this road, but I really was asking if the langcode is needed as a cache key. If the md5($text) is a perfect match, can't we be sure that the cached text is good and we need not run filters?
Comment #11
dries commentedThe documentation improvements look good. I'm still curious what language-specific filter you're working on.
Let's wait for the reply to Moshe's question in #10 too.
Comment #12
nedjo@dries: The need for passing a $langcode to filters came up in #265565: Multilanguage support (at least for 6.x), a feature request on the Word filter module.
That module enables filtering of specified words. For example, all occurrences of "dime" might be replaced with "quarter".
The issue is that many words have the same form in different languages. (Words that are spelled the same in different languages are technically called "interlingual homographs"). E.g., "dime" is "ten cent coin" in English but is also a word in Spanish (it means "tell me").
Whether or not the meaning is the same in different languages, the correct replacement likely is different. To know whether or not "dime" should be replaced with "ten cent coin" using the Word filter module, we need to know what language we're working with.
[But maybe, given the history of dorpje > drop > druppel > Drupal we want to be careful about how much we fix the problem of interlingual similarities--sometimes they prove to be a spur to creativity :) ]
@moshe: The theoretical use case for including the $langcode in the cache ID would be that the full string being processed is identical in more than one language, but should be handled differently. This is definitely an edge case, but I guess it would occur if we had a single-word string, or else some unusual string that is mostly language neutral (a company name, language, etc.) but includes an "interlingual homograph". So, I guess, we're safer including the $langcode.
@stella: re whether we should feed the current language, my initial thought is, it may provide more flexibility and therefor be better to leave that to the filter implementing the hook, as the current patch does. That way, a filter can decide how to respond specifically to an unknown language (e.g., by skipping filtering).
Comment #13
moshe weitzman commentedwow - good answer. i'll support a langcode in the key.
Comment #14
sun+1 for this change.
First thought:
I'd like to propose (ugh, slightly scope creep) to revert to "language", but don't do:
Do this instead:
Comment #15
nedjo@sun: I agree that having better parallelism between our different object types would be good, but, yes, it's beyond the scope for this issue.
And there are a couple of reasons that this wouldn't work even if we did have parallel naming.
First, it may not be an object at all that's being filtered--check_markup is used in many different contexts in contrib.
Second, even if it is an object, a given object type may have more than one field that needs filtering, so we can't assume it's a body that we're filtering. Comment is an example:
Comment #16
dries commented@nedjo: thanks for the clarification -- that is really helpful. It seems like a fairly special case, but I do support the change nonetheless. It is a valid use case after all.
I've run the tests, and this looks like it is ready to be committed. I committed it to CVS HEAD. Two things left to do before this issue can be marked fixed:
* We have to commit the documentation update.
* We have to update the module upgrade instructions in the handbook.
Thanks!
Comment #17
stella commentedI've committed the API documentation update.
Suggestion for module upgrade instructions:
Comment #18
stella commentedModule upgrade instructions updated on http://drupal.org/node/224333
Cheers,
Stella