On 2016-12-20 06:22, Daniel Barrett wrote:
My goal is to remove some special pages for anonymous users but permit logged-in users to see them. Is there a better way to check for a logged-in user at this hook point? Or a better way to remove special pages for anonymous users?
Bartosz DziewoĆski mailto:matma.rex@gmail.com replied:
Yes, the list of special pages can't depend on anything related to the current user.
Instead, you should check whether the user is logged in when displaying the special page. You can just call `$this->requireLogin();` at the beginning of the special page's execute() function...
Brad Jorsch (Anomie) added:
And to hide a special page on Special:SpecialPages from users who can't use it, have the page's userCanExecute() return false when appropriate and have isRestricted() return true. If the check is based on having one user right, this can be easily done by passing the user right as the $restriction parameter to SpecialPage::__construct().
Thanks! Since I am trying to hide *all* special pages (except login, logout, and search), from anonymous users, not just custom special pages that I wrote, these solutions won't quite work. I'll try using the hook "SpecialPageBeforeExecute" to check if the user is logged in, then blocking the execution if not. Then maybe a separate hook to prevent special pages from showing up in the search box auto-suggestions, maybe "ApiOpenSearchSuggest"?
As an additional note, even after removing the problematic code, VisualEditor is still not loading. I guess the errors I saw were red herrings. Now there are no errors at all showing up when VE fails. :-( I'll do some more debugging and follow up.
DanB