Page MenuHomePhabricator

$parser->getUser() returns anon while processing parser tags during a write
Open, Needs TriagePublic

Description

I'm working on a parser tag that needs to know the current user -- even when the parser tag is first inserted.

I have code like:

  function tagFunction( Parser $parser, PPFrame $frame, $arg ) {
        $user = $parser->getUser();
    	if ( $user->isAnon() ) { // During writes the user isn't properly loaded.
		global $wgUser;
		$user = $wgUser;
        }
        if ( $user->isAnon() ) {
             throw new MWException( "No such thing as anon users on this wiki" );
        }
  }

Without the first isAnon() check, the exception is always thrown on writes that include the tag.

Event Timeline

MarkAHershberger raised the priority of this task from to Needs Triage.
MarkAHershberger updated the task description. (Show Details)
MarkAHershberger subscribed.

Oh, I should point out that during reads the first isAnon is always false (since this wiki uses SSO to log in users).

IIRC pages get rendered with anonymous settings for caching purposes on edit. They may also be rendered with anonymous settings during background updates. And in general, page renderings that've been cached may be presented to other users with the same basic render settings...