[ticket/11151] Bundle as a function

Bundling the last page generation inside a function.

PHPBB3-11151