```php
global $wgChatDebugEnabled;
```

is missing at the top of the function