(bug 42600) (bug 24375) Fix doMaintenance.php exit procedures.

Fixed the post-execution calls in doMaintenance.php
to perform proper cleanup after the maintenance
script runs (modeled after MediaWiki::restInPeace).

Added a global call to wfWaitForSlaves() and then
wfDoUpdates() in doMaintenance.php to ensure that
deferred updates are always performed at the end
of maintenance scripts (and that they're performed
after the slaves catch up to avoid lag).

Also added calls to shutdown the DB factory so
that implicit transactions are committed and the
connections are closed.

Change-Id: I6f9580559d75f4761c5ddb504b2e3380e2e562a3
Merge "(bug 42600) (bug 24375) Fix doMaintenance.php exit procedures."