Improve QueryWriter interface.
Improved Replica2, also generates plain PHP file.
P533 patch
Slightly modify replica2 PHP gen.
Minor cleanup.