MediaWiki WYSIWYG Editor Reset Images Bug [Solved]

For over 3 years no one wrote a solution for reset images caption error on mediawiki script, which also is on durpal and some other applications getting used, but its hard to believe that. link to bug

If you have plugin WYSIWYG installed for mediaWiki application. Then you might have tried to add pictures through the rich editor with a caption of the picture, when you click on the source code or even just click save, you will see the image caption is no longer on preview. it has been stripped out automatically, so any pages you have with images that has caption and you save it with rich editor, then it will strip out all the caption for all the images.

after looking around solution for this issue, i haven’t really found it, there was ticket on ckEditor site, which state about the bug, but no solution for more then 3 years now. so i just did my own debugging and manage to find a reasonable solution and thought to share with the people who might still have this problem and want to solve it.

 Editor:

CKeditorSkin.body.php on line 197

CKeditorSkin.body.php file is located in /extensions/WYSIWYG/

Problem:

if( isset( $fp['alt'] ) && !empty( $fp['alt'] ) && $fp['alt'] != 'Image:' . $orginal ) {
    $ret .= "alt=\"" . htmlspecialchars( $fp['alt'] ) . "\" ";
} else {
    $ret .= "alt=\"\" ";
}

Solution:

if( isset( $fp['alt'] ) && !empty( $fp['alt'] ) && $fp['alt'] != 'Image:' . $orginal ) {
    $ret .= "alt=\"" . htmlspecialchars( $fp['alt'] ) . "\" ";
} else if (isset($fp['caption']))
{
    $ret .= "alt=\"" . htmlspecialchars( $fp['caption'] ) . "\" ";
} else {
    $ret .= "alt=\"\" ";
}

Leave a Reply

Your email address will not be published. Required fields are marked *