Added a permission model for pages

Including necessary additions to `install.php` and `upgrade.php`. Big thanks to @onmoon for the original implementation!

Also includes a bug fix to `reorder_pages()` and an enhancement to error message sanitising in order to retain prettified errors.