MWX/Invite/notes

From Woozle Writes Code
< MWX‎ | Invite
Revision as of 01:18, 8 September 2020 by Woozle (talk | contribs)
Jump to navigation Jump to search

Notes

MW API: selectively enabling account request

dead end

The tricky part of this is the interface with MediaWiki to selectively allow a visitor (i.e. one who has a valid invite code) to request an account when visitors are not generally allowed to access that page.

The class for creating pages based on the "Create account" page is apparently LoginSignupSpecialPage... except the documentation says "This feature was removed completely in version 1.33." (...and yet the file is still present in 1.34.2)

The actual class for handling account requests appears to be SpecialCreateAccount. Tentatively, I am descending my page from that, and overriding its methods when a valid invite has not been received.

hook interception

MW API: checking for permission

This bit was easier, but I did find several ways to do it. There's an obvious best way, but the others may be useful in future.

First you get the object for the current User. SpecialPages have a built-in function so you don't have to use the $wgUser global:

$mwoUser = $this->getUser();

The obvious best way to find out if the user has permission to create other accounts:

$mwoUser->isAllowedToCreateAccount();

Other ways:

// 1. get groups for user, then get perms for those groups
$arGroups = $mwoUser->getEffectiveGroups();
$arPerms = \User::getGroupPermissions($arGroups);
            
// 2. get perms for user
$arPerms = $mwoUser->getRights();

// 3. get flag for whether the user has the "create account" permission
$canMakeUsers = $mwoUser->isAllowed('createaccount');

related discussions