Roger Federer rolled back the years to produce a stirring comeback against Novak Djokovic and reach the final of the Dubai Open.