Summary
On a wiki that doesn't set $wgArticlePath explicitly, maintenance scripts and a php-fpm/CGI web server end up with different article paths (/index.php/$1 on the CLI, /index.php?title=$1 on the web). Parsoid output that a maintenance script writes to the parser cache carries the CLI's article path in its <base href> and link hrefs, and when VisualEditor later loads that cached HTML on the web it no longer recognizes any of the wikilinks as internal: pages with categories fail to open entirely (TypeError: Cannot read properties of undefined (reading 'match') in ve.dm.MWCategoryMetaItem.static.toDataElement), and on other pages every wikilink turns into an uneditable alien node.
Technical notes
Why the CLI and the web disagree. $wgUsePathInfo has a SAPI-dependent default (MainConfigSchema::getDefaultUsePathInfo()): it's false whenever PHP_SAPI contains cgi (which includes php-fpm's fpm-fcgi), apache2filter, or isapi, and true for cli. The default for $wgArticlePath is in turn either "$wgScript/$1" or "$wgScript?title=$1" depending on that setting. The installer only writes $wgArticlePath to LocalSettings.php when short URLs are configured, so a stock install behind nginx or Apache with php-fpm hits this. Wikimedia production sets $wgArticlePath explicitly and isn't affected; Quibble-based CI doesn't, and is.
Why the cache entry keeps the wrong path. SiteConfig::determineArticlePath() splits the article path at its last / into a base URI and a relative link prefix. Output parsed on the CLI therefore has a base of https://example.org/index.php/ with hrefs like ./Foo, while output parsed on the web has a base of https://example.org/ with hrefs like ./index.php?title=Foo. Since T431358 (41f3fec051f) ParsoidParser also records the base in the ParserOutput as core:base-uri, which ExpandRelativeAttrs uses for read views and PageBundleParserOutputConverter uses for the <base href> in REST/VE HTML. So each cached entry is internally consistent, but nothing in the parser cache key (idhash:useParsoid=1) or its validity checks depends on the article path, and the web happily serves whichever version was written last.
Why VisualEditor breaks. mw.libs.ve.getTargetDataFromHref() (in ve.utils.parsoid.js) resolves each href against the document base and then only treats it as internal if it matches either wgScript with a lone title parameter or the wgArticlePath of the *current* request. On a ?title= wiki, https://example.org/index.php/Category:Foo matches neither, so the function returns { isInternal: false }. MWCategoryMetaItem.toDataElement then calls targetData.title.match() on an undefined title and VE fails to load. Ordinary wikilinks fall through to MWExternalLinkAnnotation, which declines Parsoid links that lack mw:ExtLink (T267282), so they're alienated rather than crashing. I didn't find a path that corrupts saved content, but VE is unusable on the affected page until the cache entry is purged or expires.
(Note the asymmetry: on a wiki where the web uses the path-info form, VE accepts both link forms, because the query form still matches the wgScript + title rule. Only ?title= wikis are hurt.)
Read views (unverified). ExpandRelativeAttrs expands the cached ./Foo hrefs into https://example.org/index.php/Foo. MediaWiki itself routes that fine, since WebRequest::getPathInfo() parses REQUEST_URI and always recognizes $wgScript/$1, but a web server whose PHP handler only matches URLs ending in .php (a common nginx location ~ \.php$ setup) won't hand those requests to PHP at all, so the links may 404 there.
What writes Parsoid output to the parser cache from the CLI:
- maintenance/prewarmParsoidParserCache.php, which has existed since 1.41. It parses with ParserOptions::newFromAnon() plus setUseParsoid(), which is exactly the cache key VE and anonymous Parsoid read views use, and with --force it overwrites perfectly good entries. This is reproducible today with no configuration changes.
- Once Parsoid becomes the default parser (T432762, Gerrit 1347796), every edit made from the CLI saves its canonical output via DerivedPageDataUpdater::doParserCacheUpdate(). That covers edit.php, importTextFiles.php, importDump.php without --no-updates (ImportableOldRevisionImporter runs doUpdates()), and edits made by jobs under runJobs.php (ReplaceText, MassMessage, and so on). This is what broke the GrowthExperiments browser tests on 1347796: CI runs Apache with php-fpm and no $wgArticlePath, and PrepareBrowserTests creates its fixture pages with importTextFiles.php.
- RefreshLinksJob and ContentHandler::getParserOutputForIndexing() don't save to the parser cache, so they're not involved.
Steps to reproduce (current master, Parsoid not the default):
- Run the wiki under php-fpm (or simulate it with if ( PHP_SAPI !== 'cli' ) { $wgUsePathInfo = false; }), leave $wgArticlePath unset, and use a parser cache that the CLI and the web share, such as CACHE_DB.
- Create a page containing a wikilink and a category, e.g. [[Foo]] [[Category:Bar]].
- Purge the page and fetch /rest.php/v1/page/<Title>/html. You get <base href="https://example.org/"/> and href="./index.php?title=Category:Bar".
- Run php maintenance/run.php prewarmParsoidParserCache --force --start-from <page_id> --namespace main.
- Fetch the same REST URL again. It's now a cache hit with <base href="https://example.org/index.php/"/> and href="./Category:Bar".
- Open the page in VisualEditor. It fails to load with the match TypeError above; without the category it loads, but every wikilink is an alien node.
I reproduced steps 3–5 on a local wiki. For step 6 I ran VE's getTargetDataFromHref() in node against those hrefs and the current request config; the resulting crash is the one seen in the GrowthExperiments Cypress run (quibble-with-GrowthExperiments-extensions-browser-tests-only-vendor-php83, build 19870).
Possible fixes (these aren't mutually exclusive):
- VisualEditor: when an href is ./-relative and resolves under the document's own <base href>, treat it as a Parsoid resource name instead of comparing it to the current wgArticlePath. That makes VE indifferent to whatever article path was in effect when the HTML was generated, and is probably the most robust fix.
- Core: treat cached Parsoid output whose core:base-uri doesn't match the current SiteConfig::baseURI() as a cache miss, or fold the article path into the cache key or validity check.
- Core: make sure the CLI and the web agree on the article path in the first place, e.g. have the installer always write $wgArticlePath, stop making the $wgUsePathInfo default depend on the SAPI, or at least log a warning when a maintenance script caches Parsoid output while $wgArticlePath isn't set explicitly.
- CI: have Quibble set $wgUsePathInfo or $wgArticlePath explicitly in the LocalSettings it generates. This only fixes CI. In the meantime GrowthExperiments can set $wgUsePathInfo = true in its Cypress LocalSettings, so the CLI and php-fpm both use the path-info form, which is also the link shape production uses.