Topic on Project:Support desk

Replacement for $wgUser?

4
Sudalopa (talkcontribs)

Hi, what should be used in lieu of $wgUser? Manual:User.php says it's deprecated and Manual:$wgUser says it shouldn't be used in new code. I'm trying to disable access to certain API modules based on a person's user groups as shown on API:Restricting API usage:

if ( !in_array( 'sysop', $wgUser->getGroups() ) ) {
 	$wgAPIModules['edit'] = 'ApiDisabled';
 }

How should I do it now? Thanks

MarkAHershberger (talkcontribs)

I know it has been a year, but I was searching for the answer and came across this question. Here is what I've found.

You need to get a context object and use that to get the user. If all else fails, you can use RequestContext::getMain(), but often objects that you're dealing with will have a better context for you.

For example, if you have an Article object, you'll be able to do the following:

$user = $article->getContext()->getUser();
Legoktm (talkcontribs)

I don't think that code has ever worked to be honest. Instead, try revoking the writeapi right from non-sysops.

Ciencia Al Poder (talkcontribs)

Note that revoking writeapi will disable the ability of users to add pages to their watchlist, from the page itself.

Reply to "Replacement for $wgUser?"