Fix theme selection issue, reduce duplication of calls and update maintenance.php to V3.

Hi Bas,

This sorts an issue reported on https://moodle.org/mod/forum/discuss.php?d=251492#p1091160 and should also improve performance.  I've looked through the 'blocks_for_region' code and its quite complex, so calling only once should help.

Also upgraded maintenance.php to V3.

Cheers,

Gareth