Copied changes from joomla 1.6-2.5 branch