Drag-and-drop markers question type not editable after moodle upgrade

Drag-and-drop markers question type not editable after moodle upgrade

by Alexander Lebeth -
Number of replies: 9

After upgrading moodle from version 3.5*) to 3.10, certain questions of type drag-and-drop markers aren't editable anymore. The questions are working fine in the quiz, but when I click the edit link and try to save it (even without changing anything), then  saving is denied by stating "The shape you have defined goes out of the bounds of the background image" (section "Drop-Zones", see screenshot attached).

The issue only occurs in cases where the drag-and-drop background image is of type SVG. Trying to find a solution, I made sure, the internal dimensions of the SVG images don't exceed 400px (as this may cause issues).

This is a major problem for our project, because we heavily rely on SVG background images in all kinds of drag-and-drop questions. Any help much appreciated! To reproduce the issue, I attached an exported trouble-making question in moodle's XML format.

*) Note: Since this issue sleeps silently as long as you don't edit an existing question, the issue may have existed prior to the update from version 3.5 to 3.10.

drag-and-drop background: svg image
Average of ratings: -
In reply to Alexander Lebeth

Re: Drag-and-drop markers question type not editable after moodle upgrade

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hmm. Digging into the code, it seems that ultimately it is using the PHP function getimagesize to find the size of the image. The documentation for that (https://www.php.net/manual/en/function.getimagesize.php) does not make it obvious which file formats it supports (I think it is the ones with a corresponding IMG_... constant listed on https://www.php.net/manual/en/image.constants.php) but it seems that SVG is not supported.

And, we need it to be supported. I created MDL-71430.
In reply to Tim Hunt

Re: Drag-and-drop markers question type not editable after moodle upgrade

by Alexander Lebeth -
Tim, thank you very much for taking care of this issue. As you wrote in MDL-71430, the issue is a dupe of the old issue MDL-55243 from 2016. Since I am not a developer, I don't know what conclusions I have to draw in the light of the issue queue:
  • Will the issue be fixed soon (for me, it doesn't look likely)?
  • Is there a way to use SVG nevertheless by assigning proper width, height and viewbox attributes with proper measurement units (I fiddled around with a pleothora of different combinations, but without success)?
  • Will we have to switch back from SVG to PNG/JPG (a really bitter pill)
And what's a mistery to me: why was it possible to cretate these questions in the first place and use them in a quiz while it's not possible zu edit them now?
For me and my team any advice how to proceed would be very, very valuable!
In reply to Alexander Lebeth

Re: Drag-and-drop markers question type not editable after moodle upgrade

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well, Software development does not proceed in a linear way. The fact that MDL-55243 was created 5 years ago is is not fixed yet does not mean that someone is sitting there fixing it at the rate of one character typed per day, from which you can extrapolate when it might be fixed. wink

What it means is that this was forgotten about. Hopefully, now that you have raised it again, there is a chance that someone will pick it up, and then it might be fixed within a week.

However, it is unlikely to be this week, because all the focus is on getting the Moodle 3.11 release done (due on 10th May, I think). It is difficult to argue that we should try to squeeze in a last-minute fix for an issue that has been sitting there for 5 years. However, once the release is done, then this might get fixed, and then the fix will probably go into 3.11.1 and 3.10.4.

I am slighly puzzled why it used to work and does not any more. Now that I look, I am even more puzzled. The validation code here is all more than 7 years old! It is a bit harder to work out if anything significant has changed in the back-end file code that is used to get the image sizes. It would be very helpful to find difinitively which as the last version in which this worked, then it might be easier to see what had changed.

I don't know if you are in a possition to try random changes to the code (as an alternative to any of your bullet points). It seems to me that it is not considering the possiblity that $imageinfo mgiht be false after this line: https://github.com/moodle/moodle/blob/a5f0b354e7ef8a925cc2693d3c99b90f5445ce6e/question/type/ddmarker/edit_ddmarker_form.php#L273. You could try the effect of adding
 if ($imageinfo === false) {
continue;
}

Just after that line. (But, the real fix is to get Moodle to understand the size of SVGs.) The does open the possibility that what has changed is nothing in Moodle, but rather the way different PHP versions handle variables that are not set.
In reply to Tim Hunt

Re: Drag-and-drop markers question type not editable after moodle upgrade

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

This patch seems to work OK.

diff --git a/question/type/ddmarker/edit_ddmarker_form.php b/question/type/ddmarker/edit_ddmarker_form.php
index a30c81d87ef..e98a7e28337 100644
--- a/question/type/ddmarker/edit_ddmarker_form.php
+++ b/question/type/ddmarker/edit_ddmarker_form.php
@@ -271,6 +271,9 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
                 }
                 // Just return the data for the first good file, there should only be one.
                 $imageinfo = $file->get_imageinfo();
+                if ($imageinfo === false && $file->get_mimetype() == 'image/svg+xml') {
+                   return array(9999, 9999);
+                }
                 $width    = $imageinfo['width'];
                 $height   = $imageinfo['height'];
                 return array($width, $height);

In reply to Joseph Rézeau

Re: Drag-and-drop markers question type not editable after moodle upgrade

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Thanks Joesph. Not a proper solution, but this will probably act as a work-around until we get one.
In reply to Tim Hunt

Re: Drag-and-drop markers question type not editable after moodle upgrade

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Thanks, Tim. Yes, this is only a workaround.
I hope it helped the OP.

Alexander, did you try it? Did it work for you?
In reply to Joseph Rézeau

Re: Drag-and-drop markers question type not editable after moodle upgrade

by Alexander Lebeth -
Sorry it took my so long, but gladly I can confirm the workaround is working! I can edit and save all old questions and they are working as expected. Thank you very much, Joseph & Tim!
In reply to Alexander Lebeth

Re: Drag-and-drop markers question type not editable after moodle upgrade

by Huong Nguyen -
The is_valid_image() was created to check that the image is safe to serve it directly or not, in this case, is jpg, png and gif.
And currently, Moodle is using GD to get the image info (width and height) but GD does not support SVG yet.

The SVG can represent XSS risk, so if we decided to serve it directly, we should consider sanitizing its contents.

We're still discussing this.
Average of ratings: Useful (1)
In reply to Alexander Lebeth

Re: Drag-and-drop markers question type not editable after moodle upgrade

by Huong Nguyen -
Hi guys, the good news is MDL-55243 is tested and will be included in Moodle 3.10.5 and 3.11.1 release.
Thanks,