Page MenuHomePhabricator

Temporary account users should have the same ParserOptions as anonymous users
Closed, ResolvedPublic

Description

Ensure anonymous ParserOptions are used when getting parser options for a temporary user.

There are several static methods for constructing a ParserOptions object: ParserOptions::newFromAnon, ::newFromUser, ::newFromContext, and ::newCanonical (deprecated). Ensure that temporary users are treated the same as anon users when choosing between these.

Event Timeline

ParserOptions::newFromUser() and ParserOptions::newFromAnon() both go through the same ParserOptions::__construct(UserIdentity $user, ?Language $lang = null) contructor, which in turn goes through ParserOptions::initialiseFromUser. So I think as long as that latter function handles temporary users correctly, you should be good.

The key seems to be the UserOptionsLookup() (which should return the same options for anonymous and temporary users) and the 'user lang' (ParserOptions::$options['userlang']) which should be set to the wiki content language to be consistent with anonymous users.

I don't think you need a ParserOptions::newFromTemporaryUser() method, since it would basically just do the exact same thing as ParserOptions::newFromUser() assuming that you put the right logic in UserOptionsLookup and/or ParserOptions::initialiseFromUser.

And to elaborate some more, I think ParserOptions::$user should be the actual temporary user, or else things like ~~~~ in PST probably won't work. So that means you shouldn't use ParserOptions::newFromAnon(), you need to just ensure that ParserOptions::newFromUser ends up with the same settings that the anon user would have.

Thanks @cscott.

The key seems to be the UserOptionsLookup() (which should return the same options for anonymous and temporary users) and the 'user lang' (ParserOptions::$options['userlang']) which should be set to the wiki content language to be consistent with anonymous users.

This shouldn't need any changes since preferences are disabled for temp accounts (T332415).

So it looks like the main thing to do here is to check that temp users get newFromUser instead of newFromAnon, as per T337042#9612005.

Summary

It looks like there's nothing to update here.

Question

Are there any code paths that take a user and call ParserOptions::newFromAnon if it's a temporary user but ParserOptions::newFromUser if it's a fully registered user?

If so, update them to call newFromUser on the temp user too.

Strategy

Search all WMF deployed repos for ParserOptions::newFromAnon, excluding tests: https://codesearch.wmcloud.org/deployed/?q=ParserOptions%3A%3AnewFromAnon&excludeFiles=.%2ATest.php

Search results

MediaWiki core

  • includes/Output/OutputPage.php - User isn't safe to load. No fix.
  • includes/Rest/Handler/Helper/HtmlInputTransformHelper.php - Called for all users. No fix.
  • includes/Rest/Handler/Helper/HtmlOutputRendererHelper.php - Called for all users. No fix.
  • includes/Revision/RevisionRenderer.php - Only called if no user passed in. No fix.
  • includes/content/Renderer/ContentParseParams.php - Called for all users. No fix.
  • includes/editpage/PreloadedContentBuilder.php - Comment says the user is not needed. No fix.
  • includes/jobqueue/jobs/ParsoidCachePrewarmJob.php - Called for all users. No fix.
  • includes/language/MessageCache.php - User isn't safe to load. No fix.
  • includes/page/WikiPage.php - Called for all users. No fix.
  • includes/parser/Parsoid/Config/PageConfigFactory.php - Only called if no user passed in. No fix.
  • maintenance/compareLanguageConverterOutput.php - Called for all users. No fix.
  • maintenance/formatInstallDoc.php - Called for all users. No fix.
  • maintenance/parse.php - Called for all users. No fix.
  • maintenance/prewarmParsoidParserCache.php - Called for all users. No fix.

Extension:DiscussionTools
Extension:FeaturedFeeds
Extension:Flow
Extension:Graph
Extension:Kartographer
Extension:Math
Extension:ProofreadPage
Extension:Scribunto
Extension:SpamBlacklist
Extension:TextExtracts

  • These extensions all call newFromAnon but never call newFromUser. Therefore newfromAnon is never called for a temp user where newFromUser is called for a registered user.

Extension:SecurePoll

  • cli/wm-scripts/sendMail.php - Called for all users. No fix.