[ticket/10037] Apply attached patch with a few changes

PHPBB3-10037