Fix 1046 (part 1)

This branch:

* Fixes link rewrites in absolute mode.
* Makes ```nikola check -l``` do the right thing in absolute mode.
* Fixes for the canonical links in the templates, ```abs_link(permalink)``` is doing the wrong thing when permalink is undefined.
* Handles checking links to folders correctly
* Fixes broken permalink in galleries which worked in rel_path mode by accident.
* Adds integration test for the failing case of #1046 + absolute

Missing for a complete fix of #1046:

 * Fixes for full_path mode