It means I wish when it is used as exclamation.
A: Vuoi che ti accompagni?
B: Magari!
It has that meaning in a sentence using the subjunctive mood too.
Magari potessi venire anche io al concerto!
Magari fosse vero che sono fidanzato con Veronica!
Magari non fosse venuta alla festa! Mi ha fatto litigare con la mia ragazza, che se ne è andata prima che potessi darle il regalo.
When used with the Simple Present and the Simple Past, it normally means maybe, possibly.
Magari non sapeva niente.
Magari non è stato avvisato in tempo.
Magari è solo in ritardo.
Notice that you could read Magari non c'ero! instead of Magari non ci fossi stato, but in both the cases it means "I wish I was not there." As in English, the subjunctive mood is often replaced from the indicative mood, at least colloquially.
In that case, the difference is made from the intonation.