Images in migrated page descriptions not displayed on a page
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mahara |
Fix Released
|
High
|
Scott Verbeek | ||
21.04 |
Fix Released
|
High
|
Unassigned | ||
21.10 |
Fix Released
|
High
|
Unassigned | ||
22.04 |
Fix Released
|
High
|
Scott Verbeek |
Bug Description
Upgrading from a site before Mahara 21.10 causes problems when images were added to the page description field. The URL is retained but the block ID is not added, therefore not displaying the image on the page.
This was introduced in bug #1913386
To replicate:
1. Install fresh Mahara 20.04.
2. Create a page and add an image to the page description. The URL will look something like http://
3. Upgrade the site to 21.10 / main.
4. View your page.
Result:
- Expected: The page description is now displayed in the block called 'Description' and the image is shown. The URL should look something like:
http://
- Actual: the page description is now displayed in the block called 'Description' but there is a broken image as the URL hasn't changed.
Workaround for portfolios that can be edited:
1. Edit the page.
2. Click the 'Edit block' icon for the 'Description' block. You should see the image in the TinyMCE editor window.
3. Save the block and the image will have the block reference added.
This workaround is not possible for submitted pages. That's why we will need to provide an upgrade step.
no longer affects: | mahara/20.10 |
description: | updated |
I've come up with a bug fix for this. I still need to test and make it use Mahara functions create tests and document but I've got this atm.
```
<?php
function log_debug($message) {
print("DBG: {$message}\n");
}
function append_ image_src_ with_text_ bi_id($ content, $biid) { >loadHTML( htmlspecialchar s_decode( $content) ); getElementsByTa gName(' img') as $tag) {
$imagesource = $tag->getAttrib ute('src' );
$dom = new DOMDocument();
$dom-
foreach ($dom->
// Get the src attribute, if no attribute with the given qualifiedName is found an empty string is returned.
// If it's empty then continue.
if(empty( $imagesource) ) {
continue;
}
// Make sure we only touch our links. $imagesource, '/artefact/ file/download. php?')) {
continue;
if (!strpos(
}
// If the source already contains a text parameter then skip.
parse_ str(parse_ url($imagesourc e, PHP_URL_QUERY), $result);
if(isset( $result[ 'text'] ) && !empty( $result[ 'text'] )) {
continue;
}
// Now that we've got an image from our site append with &text=XYZ
log_debug( "Found {$imagesource}");
$tag-> setAttribute( 'src', "{$imagesource} &text={ $biid}" );
$dom-> saveHTML( ); tsByTagName( 'body') ->item( 0); array_map( [$bodynode- >ownerDocument, "saveHTML" ],iterator_ to_array( $bodynode- >childNodes) ));
}
// The DOMDocument adds some HTML tags which we don't want so get everything in the body.
$bodynode = $dom->getElemen
return implode(
}
$content = '<p><img width="1442" height="" style="" alt="2021- 12-03_11- 12-44-screensho t.png" src="http:// mahara. localhost/ artefact/ file/download. php?text= 7&embedded= 1&descripti on=7"></p>';
$biid = 12346;
if ($content !== $newcontent = append_ image_src_ with_text_ bi_id($ content, $biid)) { debug(" Changed to {$newcontent}"); debug(" Nothing changed");
log_
} else {
log_
}
```