Fix from XWiki importation
rebased the patch on top of Jean's most recent work and hard-broke lines at 100 characters to simplify patching.