Fix various warnings in Moodle 2.5

The first two commits will work fine in all Moodle versions (2.3 - 2.5).
The last commit is Moodle 2.5+ only.