Enforce model aliases when generating order by clauses.

Invalid SQL could be created by sorting on an invalid alias, with
a field that exists on the model.

Fixes #3797
Simplify how fullBase is calculated.

Using FULL_BASE_URL fixes URL generation when URL rewriting is
disabled.

Fixes #3777