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

http://tracker.phpbb.com/browse/PHPBB3-10037