I don't have enough time right now to have a deeper look at your code, but:
$token = $token = $wgUser->editToken();
Although this isn't an error, it's still unnecessary.
Next, are you really using these quotes: ” instead of ". I think this happened when you copied the code because it'll result in an syntax error. Additionally, you shouldn't put pure variables into quotes, there's no reason why I would do so.
You should urlencode all parameters, not just the token.