Page MenuHomePhabricator

CSS background with root-relative URL causes exception in css minifier for wikis using the document root as its script path
Closed, ResolvedPublic

Description

Affected versions

This is happening when testing MediaWiki 1.36-rc.0

Testing this on mediawiki.org doesn't cause this issue (maybe it has been fixed and needs a backport?)

Testing on MediaWiki 1.35 doesn't cause this issue

Steps to reproduce

  1. Go to MediaWiki:Common.css
  2. Add some valid CSS styles, including this one: #test { background:url('/resources/src/mediawiki.skinning/images/spinner.gif'); }
  3. Save the page

Expected results

You get those styles applied

Actual results

No style from the page is applied (including MediaWiki:"skinname".css).

This can be tested on a personal css page, or hitting preview.

Real-life impact

I'm testing an upgrade to MediaWiki 1.36.rc.0 from MediaWiki 1.34

Our wiki has some script that wants to display a spinner gif, and we found one that ships with MediaWiki located at /resources/src/mediawiki.skinning/images/spinner.gif (previously inside the mediawiki.legacy folder).

Because of that, we had this in MediaWiki:Common.css:

.imageswitch_state_loading {
	background:url('/resources/src/mediawiki.skinning/images/spinner.gif') center no-repeat;
}

When upgraded, styles were not being displayed. When looking for errors in logs I found this:

2021-05-07 20:00:18 test1wikidex23 wikidexwiki: [e75f78c265f41acaba826861] /load.php?lang=es&modules=site.styles&only=styles&skin=monobook   Exception: Base-URL must be absolute if reference is not fragment-only
#0 $IP/vendor/wikimedia/minify/src/CSSMin.php(414): Net_URL2->resolve(Net_URL2)
#1 $IP/vendor/wikimedia/minify/src/CSSMin.php(441): Wikimedia\Minify\CSSMin::resolveUrl(string, string)
#2 $IP/vendor/wikimedia/minify/src/CSSMin.php(327): Wikimedia\Minify\CSSMin::remapOne(string, string, boolean, string, boolean)
#3 [internal function]: Wikimedia\Minify\CSSMin::Wikimedia\Minify\{closure}(array)
#4 $IP/vendor/wikimedia/minify/src/CSSMin.php(316): preg_replace_callback(string, Closure, string)
#5 [internal function]: Wikimedia\Minify\CSSMin::Wikimedia\Minify\{closure}(array)
#6 $IP/vendor/wikimedia/minify/src/CSSMin.php(292): preg_replace_callback(string, Closure, string)
#7 $IP/includes/libs/MemoizedCallable.php(128): Wikimedia\Minify\CSSMin::remap(string, boolean, string, boolean)
#8 $IP/includes/libs/MemoizedCallable.php(158): MemoizedCallable->invokeArgs(array)
#9 $IP/includes/resourceloader/ResourceLoaderWikiModule.php(309): MemoizedCallable::call(array, array)
#10 $IP/includes/resourceloader/ResourceLoaderModule.php(773): ResourceLoaderWikiModule->getStyles(ResourceLoaderContext)
#11 $IP/includes/resourceloader/ResourceLoaderModule.php(721): ResourceLoaderModule->buildContent(ResourceLoaderContext)
#12 $IP/includes/resourceloader/ResourceLoader.php(1188): ResourceLoaderModule->getModuleContent(ResourceLoaderContext)
#13 $IP/includes/resourceloader/ResourceLoader.php(896): ResourceLoader->makeModuleResponse(ResourceLoaderContext, array, array)
#14 $IP/load.php(51): ResourceLoader->respond(ResourceLoaderContext)
#15 $IP/load.php(38): wfLoadMain()

I looked at our MediaWiki:Common.css page and found the url() statements with relative URLs. Making them absolute fixed the issue, but it was nasty to get the wiki without any CSS customization because of this.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

On my main localhost wiki, I could not reproduce:

Common.css
.imageswitch_state_loading {
  background: url('/mediawiki/resources/src/mediawiki.skinning/images/spinner.gif') center no-repeat;
}
body {
  background: orange;
}

This renders without server-side error on my localhost, with the body style applied.

I suspect this may have to do with your wiki using the document root as its script path. It is not recommended to operate a wiki in that way. Note that this is different from using the root for the article path, while that is also not recommended, having at least some script directory does avoid the vast majority of potential problems.

Having said that, MediaWiki does try to make root installs work as best as possible. And, when I use composer mw-install:sqlite && composer serve on a plain MediaWiki core checkout, which uses the root directory as script path, I can reproduce this error:

Common.css
.imageswitch_state_loading {
  background: url('/resources/src/mediawiki.skinning/images/spinner.gif') center no-repeat;
}
body {
  background: orange;
}
[305596e85404d393e3a63425] /load.php?lang=en&modules=site.styles&only=styles&skin=vector   Exception: Base-URL must be absolute if reference is not fragment-only
Backtrace:
from /Users/krinkle/Development/mediawiki/vendor/pear/net_url2/Net/URL2.php(888)
#0 /Users/krinkle/Development/mediawiki/vendor/wikimedia/minify/src/CSSMin.php(414): Net_URL2->resolve(Net_URL2)
#1 /Users/krinkle/Development/mediawiki/vendor/wikimedia/minify/src/CSSMin.php(441): Wikimedia\Minify\CSSMin::resolveUrl(string, string)
…
#10 /Users/krinkle/Development/mediawiki/includes/resourceloader/ResourceLoaderModule.php(773): ResourceLoaderWikiModule->getStyles(ResourceLoaderContext)
#11 /Users/krinkle/Development/mediawiki/includes/resourceloader/ResourceLoaderModule.php(721): ResourceLoaderModule->buildContent(ResourceLoaderContext)
#12 /Users/krinkle/Development/mediawiki/includes/resourceloader/ResourceLoader.php(1188): ResourceLoaderModule->getModuleContent(ResourceLoaderContext)
#13 /Users/krinkle/Development/mediawiki/includes/resourceloader/ResourceLoader.php(896): ResourceLoader->makeModuleResponse(ResourceLoaderContext, array, array)
#14 /Users/krinkle/Development/mediawiki/load.php(51): ResourceLoader->respond(ResourceLoaderContext)
#15 /Users/krinkle/Development/mediawiki/load.php(38): wfLoadMain()
#16 {main}

Problematic modules: {"site.styles":"error"}
Jdforrester-WMF renamed this task from CSS background with root-relative URL causes exception in css minifier to CSS background with root-relative URL causes exception in css minifier for wikis using the document root as its script path.May 7 2021, 10:58 PM

Change 686795 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] resourceloader: Fix path-only URLs in wiki modules when script path is docroot

https://gerrit.wikimedia.org/r/686795

Change 686796 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/libs/Minify@master] CSSMin: Fix remapping of absolute path when base is at document root

https://gerrit.wikimedia.org/r/686796

Change 686798 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/libs/Minify@master] Tag 2.2.2

https://gerrit.wikimedia.org/r/686798

Change 686800 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/vendor@master] Update wikimedia/minify to 2.2.2

https://gerrit.wikimedia.org/r/686800

Change 686801 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] Update wikimedia/minify to 2.2.2

https://gerrit.wikimedia.org/r/686801

Change 686802 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/vendor@REL1_36] Update wikimedia/minify to 2.2.2 (REL1_36 backport)

https://gerrit.wikimedia.org/r/686802

Change 686796 merged by jenkins-bot:

[mediawiki/libs/Minify@master] CSSMin: Fix remapping of path-only URL when base dir is server-less root

https://gerrit.wikimedia.org/r/686796

Change 686798 merged by jenkins-bot:

[mediawiki/libs/Minify@master] Tag 2.2.2

https://gerrit.wikimedia.org/r/686798

Change 686692 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@REL1_36] Update wikimedia/minify to 2.2.2

https://gerrit.wikimedia.org/r/686692

Change 686693 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@REL1_36] resourceloader: Fix path-only URLs in wiki modules when script path is docroot

https://gerrit.wikimedia.org/r/686693

Change 686800 merged by jenkins-bot:

[mediawiki/vendor@master] Update wikimedia/minify to 2.2.2

https://gerrit.wikimedia.org/r/686800

Change 686802 merged by Jforrester:

[mediawiki/vendor@REL1_36] Update wikimedia/minify to 2.2.2 (REL1_36 backport)

https://gerrit.wikimedia.org/r/686802

Change 686801 merged by jenkins-bot:

[mediawiki/core@master] Update wikimedia/minify to 2.2.2

https://gerrit.wikimedia.org/r/686801

Change 686795 merged by jenkins-bot:

[mediawiki/core@master] resourceloader: Fix path-only URLs in wiki modules when script path is docroot

https://gerrit.wikimedia.org/r/686795

Change 686692 merged by jenkins-bot:

[mediawiki/core@REL1_36] Update wikimedia/minify to 2.2.2

https://gerrit.wikimedia.org/r/686692

Change 686693 merged by jenkins-bot:

[mediawiki/core@REL1_36] resourceloader: Fix path-only URLs in wiki modules when script path is docroot

https://gerrit.wikimedia.org/r/686693

Jdforrester-WMF triaged this task as High priority.
Jdforrester-WMF added a subscriber: Jdforrester-WMF.

Thank you, Timo!