Oil gains for third straight week on tight supply, China optimism