CLOZE question cuts out most of content

CLOZE question cuts out most of content

by Jeff Forssell -
Number of replies: 19
I try to save:

<strong>1.A)</strong> Givet denna talföljd:&nbsp;&nbsp; 2&nbsp;&nbsp; 4&nbsp;&nbsp; 6&nbsp;&nbsp;&nbsp; 8&nbsp;&nbsp; ...
<br />
<br />{1:NUMERICAL:=20:0#Det var RÄTT! Svaret för Aritmetisk serie fås med första termen + 9*differensen 2+9*(4-2)=20~%0%Det verkar inte vara rätt. Svaret för Aritmetisk serie fås med första termen + 9*differensen. Prova igen!}
<br />

but all that turns up is

<strong>1.A)</strong> Givet denna talföljd:

I'm using Moodle 1.6.1  2006050510
Average of ratings: -
In reply to Jeff Forssell

Re: CLOZE question cuts out most of content

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This is a known bug that has us all totally baffled. I really hope someone can work out why it broke and how to fix it reliably, so we can get this sorted.
In reply to Jeff Forssell

Re: CLOZE question cuts out most of content

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Jeff,

See my bug report #6068. You may want to use my suggested bug fix. In file question\type\multianswer\questiontype.php, towards the end, comment out this line:

//    $text = html_entity_decode($text);

Joseph

PS We are still waiting for someone to explain the use of that html_entity_decode() call, other than causing the mentioned bug. thoughtful

Attachment image-0000.jpg
In reply to Joseph Rézeau

Re: CLOZE question cuts out most of content

by Jeff Forssell -
I can see that you got my code to work (Unless you've learned Swedish lately!).

I'll contact the adm and see if it will work "at home".

I won't need any Christmas presents if you keep this up! Thank you! 
In reply to Joseph Rézeau

Re: CLOZE question cuts out most of content

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hey, I've just worked out why html_entity_decode breaks things.

It is a character encoding issue. That function is not UTF-8 aware. In particular, html_entity_decode(' '); gives you a string one byte long, and that byte is 0xa0. That is not a valid UTF-8 string, so later, when Moodle tries to treat the string as UTF-8, it gets as far as that character, and stops.

So, in the modern Unicode world, html_entity_decode is evil and should be avoided at all costs.

Unfortunately, the Cloze question type uses it a lot. Ho hum.
In reply to Tim Hunt

Re: CLOZE question cuts out most of content

by N Hansen -
Tim-That would probably explain the problem I was having because I had unicode characters in mine. But when was this introduced? I had no problems with 1.5, it's only with newly edited questions in 1.6. Have you figure out whether we need that html_entity_decode for something important?
In reply to N Hansen

Re: CLOZE question cuts out most of content

by Alexander Kuo -
I agree!
I have about 300 cloze questions built in Moodle 1.5. And after I upgrade to 1.6. This problem comes out! "&nbsp" strings come from the 1.6 new HTML editor because in HTMLarea a new plugin "get-html.js" exists. In Moodle 1.5, you will get a normal blank space if you press "SPACE" key. But in Moodle 1.6, you will get some "&nbsp". Besides, the new plugin in HTMLarea will append a <br> tag between two paragraphs, which will cause an empty space line. If I disable "get-html.js", everything goes fine as in Moodle 1.5.   
Alexander
In reply to Alexander Kuo

Re: CLOZE question cuts out most of content

by N Hansen -
I emailed Martin about this, since there have been lots of reports all over about problems with this file in 1.6 and I figure since the reports are scattered no one at Moodle HQ may have noticed.
In reply to Tim Hunt

Re: CLOZE question cuts out most of content

by Jeff Forssell -
I looked up html_entity_decode at http://se2.php.net/html_entity_decode
and it says that

Description

string html_entity_decode ( string string [, int quote_style [, string charset]] )

and  has

Table 2. Supported charsets

Charset Aliases Description
ISO-8859-1 ISO8859-1 Western European, Latin-1
ISO-8859-15 ISO8859-15 Western European, Latin-9. Adds the Euro sign, French and Finnish letters missing in Latin-1(ISO-8859-1).
UTF-8   ASCII compatible multi-byte 8-bit Unicode.
(there are more charsets)

So maybe we could just add the optional [, string charset]].
In reply to Jeff Forssell

Re: CLOZE question cuts out most of content

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Except that trying to specify UTF-8 in PHP 4.x does not work reliably.

Since Moodle is now using UFT-8 everywhere, there should be no need to encode and decode entitites all ove the place. We should be able to make the code simpler and more reliable.
In reply to Tim Hunt

Re: CLOZE question cuts out most of content

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
>Tim: "there should be no need to encode and decode entitites all over the place"

That is precisely what I would like to know: why can't we strip all (3) calls to  html_entity_decode() in file question\type\multianswer\questiontype.php as suggested in my bug #6068 fix? What might potential adverse effects be? Does anyone know?

Joseph

In reply to Joseph Rézeau

Re: CLOZE question cuts out most of content

by N Hansen -
Joseph-That sample I gave you of my cloze that worked for you but wasn't working for me, was that with the html_entity_decode() removed?
In reply to N Hansen

Re: CLOZE question cuts out most of content

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Nicole, the cloze code sample you gave me worked for me in both 1.6 and 1.7 without having to remove the html_entity_decode() function. As far as I can tell your problem was not related to html_entity_decode().
Joseph
In reply to Joseph Rézeau

Re: CLOZE question cuts out most of content

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The potential adverse effects are if the data in import files, or sitting in the database, has had html_entity_encode applied to it. Then users may see encoded HTML entities in the question text, rather than the correct characters. But I am beginning to think that this is such a mess, we should first strip out the html_entity_decode() calls as you suggest, and if that exposes other bugs, then we will just have to fix the other bugs too. Since it is broken at the moment, I think we can afford to take some risks on the way to making it unbroken.
In reply to Joseph Rézeau

Re: CLOZE question cuts out most of content

by Jeff Forssell -
My adm commented out one (1) call to the decode and CLOZE is working.
You mention that there are 3 calls. Should all 3 be taken away?

I'm still having some strange things happening with feedback for alternative answers, intervals.

This code:
<strong>1.A)</strong> Givet denna talföljd: 2 4 6 8 ...
<br />a) Bestäm det tionde elementet i talföljden.
<br />b) Beräkna summan av de tjugofem första elementen i talföljden.
<br />{1:NUMERICAL:=650:0#Det var RÄTT! Svaret för Aritmetisk serie fås med 25*(2+50/2) = 650~%05%50:0#Det var inte sökta svaret (summan) men ett steg på vägen, nämligen värdet av 25:e termen. Nu behöver du bara ta antalet termer * medelvärdet av 1sta och 25:e termen.&lt;br&gt; &lt;b&gt;Prova igen!&lt;/b&gt;~%0%10000.01:10000#Det verkar inte vara rätt. Summan för en aritmetisk serie kan fås med (antalet termer)*(medelvärdet av 1sta och n:te termen)&lt;br&gt; &lt;b&gt;Prova igen!&lt;/b&gt;}
<br /> orig:
<br />
<br />{1:NUMERICAL:=20:0#Det var RÄTT! Svaret för Aritmetisk serie fås med första termen + 9*differensen&lt;br&gt; 2+9*(4-2)~%0%10000.01:10000#Det verkar inte vara rätt. &lt;br&gt;n:te termen för Aritmetisk serie fås med första termen + (n-1)*differensen. &lt;b&gt;Prova igen!&lt;/b&gt;}
<br />b) Beräkna summan av de tjugofem första elementen i talföljden.
<br />{1:NUMERICAL:=650:0#Det var RÄTT! Svaret för Aritmetisk serie fås med 25*(2+50/2) = 650~%05%50:0#Det var inte sökta svaret (summan) men ett steg på vägen, nämligen värdet av 25:e termen. Nu behöver du bara ta antalet termer * medelvärdet av 1sta och 25:e termen.&lt;br&gt; &lt;b&gt;Prova igen!&lt;/b&gt;~%0%10000.01:10000#Det verkar inte vara rätt. Summan för en aritmetisk serie kan fås med (antalet termer)*(medelvärdet av 1sta och n:te termen)&lt;br&gt; &lt;b&gt;Prova igen!&lt;/b&gt;}
<br />
<br />

should in the last box give special feedback for "50" but gives the "general" (my hack for 0,01 to 20000) feedback. The middle box should give the general  feedback for "50" but gave nothing. I tried copying the code for the last box above the (previous) first box (which made it middle box). Now the last box gives right feedback for "50" and general feedback for "500" and right feedback for 650. But the same code pasted in higher up doesn't  give the proper feedback for "50"  (but gives the  general feedback for it too)

But the general feedback for the middle box doesn't work, though (I think) it is constructed the same as the last box.

I know the combination of Swedish and Math and Layout hardly makes this easy to analyze, but if anyone has a suggestion, I'm "all ears".
In reply to Jeff Forssell

Re: CLOZE question cuts out most of content

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
>Jeff: I know the combination of Swedish and Math and Layout hardly makes this easy to analyze

That's for sure! thoughtful

Sorry I can't help you at all on this one, my Swedish being non-existent and I never ever use the NUMERICAL type of question either.

Joseph

In reply to Joseph Rézeau

Re: CLOZE question cuts out most of content

by Jeff Forssell -
Our developing server now has 1.6. If the reg exp question type you made is dropped in there, is it also functioning in the embedded questions?  That could actually be used very flexibly even for many numerical questions. (especially since the present numerical question has a lot of lacks:  no feedback for "wrong" answers, in consistent units handling.)
In reply to Jeff Forssell

Re: CLOZE question cuts out most of content

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Jeff (and others),
You can download my regexp question type from the Modules and plugins download area. I've just made it compatible with Moodle 1.6.1+.
Please read carefully the readme.txt instructions before installing.
Enjoy!
Joseph
In reply to Jeff Forssell

Re: CLOZE question cuts out most of content

by N Hansen -
That would explain my problems-I've got Latin 2 and one Greek character mixed in with Latin 1 all on the same page sometimes.
In reply to N Hansen

Re: CLOZE question cuts out most of content

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Coud you post an example of this combination of characters?