Issue Details (XML | Word | Printable)

Key: MDL-14582
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Dongsheng Cai
Reporter: guy thomas
Votes: 0
Watchers: 5
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Filters 2.0

Created: 28/Apr/08 11:36 PM   Updated: 06/Apr/09 12:06 PM
Return to search
Component/s: Filters
Affects Version/s: 2.0
Fix Version/s: 2.0

File Attachments: 1. Text File filter2.patch (52 kB)
2. Text File MDL-14582_filter_plugins.patch (61 kB)
3. Text File MDL-14582_filters.patch (51 kB)
4. Text File MDL-14582_lib.patch (5 kB)
5. Text File MDL-14582_weblib_filterlib.patch (6 kB)
6. PDF File Moodle Censorship Filter Modification.pdf (87 kB)

Issue Links:
Relates
 

Participants: Dongsheng Cai, Eloy Lafuente (stronk7), guy thomas, Martin Dougiamas and Tim Hunt
Security Level: None
QA Assignee: Eloy Lafuente (stronk7)
Resolved date: 19/Dec/08
Affected Branches: MOODLE_20_STABLE
Fixed Branches: MOODLE_20_STABLE


 Description  « Hide
1) OOP formats, making them pluggable (this is apart but could be good idea for 2.0)
2) OOP filters
3) Allow each filter to alter the md5key generated, via filter method. filter->hash() will return a unique string, the results for this could be something like, in this example: "censor:seecensoredwords" for users having the capability, or: "censor:" for the rest. Note that adding this info to the hash sounds nice because it automatically invalidates records when filters are changed, and that isn't happening right now.
4) Make the rest of format_text() and format_string() to work as now, but using that "custom" $md5key that contains all the particularities of the text being formatted.

This improvement will help fix this bug:
> Students at our school figured out they could swear if they put the word within a hyperlink - e.g.
> <a href='#'>SwearWord</a>

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Dongsheng Cai added a comment - 30/Apr/08 11:13 AM
Put a patch here for further discuss.

1. isteacher is a deprecated functions, so in my patch, I use has_capability('moodle/site:doanything', $context) instead
2. I use return filter_phrases($text, $words, true); instead of a <dummytag>, cause your students might swear using <dummytag>swear<dummytag>

Please review


Eloy Lafuente (stronk7) added a comment - 02/May/08 09:48 AM
Some comments:

1) Look the get_context_instance(CONTEXT_SYSTEM, SITEID) as commented.
2) I like the approach of hiding the original to all but admins, but...
3) Require MD approval and fixfor versions (I think we could run it for some time in HEAD in our servers and then backport to 1.9 and 1.8).


Dongsheng Cai added a comment - 07/May/08 11:01 AM
Journal mod has been moved to contrib.

Dongsheng Cai added a comment - 07/May/08 11:12 AM
I incorrectly closed this issue, reopen it.

Martin Dougiamas added a comment - 07/May/08 01:17 PM
Note that filtered text gets cached so we shouldn't use capabilities at all ... it's possible to prevent caching when this filter is used but do we really want that sort of a performance hit (all texts processed again for every user every time)?

If we do then it shouldn't rely on doanything, but some special capability like

filter/censor:seecensoredwords


guy thomas added a comment - 07/May/08 06:03 PM
Forgot about the caching side of things.

One possible resolution to this issue is to cache twice - one cache with censored text and one for people with the capability to read uncensored swears.
When the page is being rendered the system would decide which cache to use according to users capabilities.

Another possible solution is to create a new filtering mechanism which is pre-write to the db.
Using this method, the text would be written to two tables if a swear was used.

I.e.

moodle_messages gets the censored text

a new table

moodle_prefilter gets the text prior to any filtering taking place

Obviously I've just scratched the surface with this pre-write filter idea but I can expand on it if you think it is a viable solution.


Eloy Lafuente (stronk7) added a comment - 08/May/08 01:24 AM
Well,

perhaps this is a matter, for 2.0 to do something like this (to bring this and similar issues fixed for ever):

1) OOP formats, making them pluggable (this is apart but could be good idea for 2.0)
2) OOP filters
3) Allow each filter to alter the md5key generated, via filter method. filter->gethash(), the results for this could be something like, in this example: "censor:seecensoredwords" for users having the capability, or: "censor:" for the rest. Note that adding this info to the hash sounds nice because it automatically invalidates records when filters are changed, and that isn't happening right now.
4) Make the rest of format_text() and format_string() to work as now, but using that "custom" $md5key that contains all the particularities of the text being formatted.

Note that right now, for example, we are adding manually the current_language() to the cache, because of the lang filter. This will fit in the schema commented above automatically.

Guy, I'm not really sure if the "intermediate" cache (before filtering) that you comment is really a good idea or no. Perhaps you can try to perform some basic implementation and measure differences? I guess we'll lost more time reading and witting it than the time needed to format the texts, but... who knows.

Dong, how do you see the proposal? IMO could be a nice thing to change (one more) for Moodle 2.0. Comment it with MD...ciao


Dongsheng Cai added a comment - 14/May/08 04:49 PM
Sounds good, I will start to work on this issue after 1.9.1 release

Martin Dougiamas added a comment - 20/May/08 12:28 PM
Alternatively, just admit that blanket censorship of people's words through technical means is unworkable in the long run and to just put more effort into doing it socially. Set up some rules of conduct and introduce penalties for breaking them. Reducing student grades is an obvious one but I'm sure you can get creative.

Martin Dougiamas added a comment - 20/May/08 01:12 PM
But I do like Eloy's idea in general of letting all filters modify the hash

Eloy Lafuente (stronk7) added a comment - 22/May/08 09:00 AM
grrr. sorry by the delay. I'll review this tomorrow (when I receive this mail). Ciao

Dongsheng Cai added a comment - 22/May/08 05:20 PM
A new method is added in the abstract class

Dongsheng Cai added a comment - 28/May/08 11:27 AM
Replace all the filter functions with OOP Filters.

Dongsheng Cai added a comment - 28/May/08 11:28 AM
The changes to weblib.php and filterlib.php.

Dongsheng Cai added a comment - 28/May/08 11:28 AM
Please review, TIA

Dongsheng Cai added a comment - 17/Jun/08 04:09 PM
Because of $DB conversion, the old patch is not valid any more, I attach two new patch here, Eloy, can you have a look?

Martin Dougiamas added a comment - 11/Dec/08 02:02 PM
Changing name of this bug ...

Dongsheng Cai added a comment - 11/Dec/08 04:34 PM
New patches against the lastest HEAD.

Dongsheng Cai added a comment - 15/Dec/08 12:02 PM
This new patch provide back-compatible with old filter plugins.

Dongsheng Cai added a comment - 19/Dec/08 11:19 AM
resolve it for testing, feel free to reopen it
Thanks

Tim Hunt added a comment - 06/Apr/09 12:06 PM
See also, MDL-7336 / http://docs.moodle.org/en/Development:Filter_enable/disable_by_context

Note that http://docs.moodle.org/en/Development:Filters was not updated, which is OK, because I may be about to change things a bit.