CONTRIB-4304 Restructure lib.php by Jenny Gray

Signed-off-by: Joseph Rézeau <moodle@rezeau.org>