From 66a011797d8e2fdead7265b9403b1827d36bd59a Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 4 Jul 2019 16:54:24 +0100 Subject: [PATCH] OutputPage: Load html5shiv without indirection of load.php This library was introduced in 3a30e03645f, to make sure Grade C stylesheets that apply to HTML5 elements that older browsers might not know yet, work as expected in old IE. It originally committed a minified version and loaded it directly as an HTML script tag in a conditional comment. This had minimal impact on anything else, and was easy to maintain. In 68237fb1a74, this was changed to commit the unminified version instead because Debian maintainers don't like packaging software that contain minified files, despite being a simple file, unmodified from the original (upstream publishes it in minified form, with license header), published under a compatible free license, and embedded in a license-compliant manner. We then registered it as an unused ResourceLoader module, to be minified on-the-fly at run-time. Support for "server-registered client-unregistered" modules was removed last week in c554ee8e64e because nothing needed it anymore (except html5shiv apparently), which resulted in this module being registered client-side on all page views for all users (in latest master). This doesn't break anything, but it is a regression performance-wise. Restore this by (mostly) going to how it was before: A simple static file, committed to Git, served as-is. Not related to, served by, pulled through, nor registered with, ResourceLoader in any way. Only difference with the original approach is that it is no longer minified, which means a few more bytes transferred on old IE page views, which is considered an acceptable compromise. Bug: T201483 Change-Id: Ib0020b6bd015679b61f63eaa8109ed9b83d8ad15 --- includes/OutputPage.php | 20 +++++++++----------- resources/Resources.php | 9 +-------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 28e0a31352..8efce10e90 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -3012,6 +3012,7 @@ class OutputPage extends ContextSource { * @return string The doctype, opening "", and head element. */ public function headElement( Skin $sk, $includeStyle = true ) { + $config = $this->getConfig(); $userdir = $this->getLanguage()->getDir(); $sitedir = MediaWikiServices::getInstance()->getContentLanguage()->getDir(); @@ -3026,7 +3027,7 @@ class OutputPage extends ContextSource { $this->setHTMLTitle( $this->msg( 'pagetitle', $this->getPageTitle() )->inContentLanguage() ); } - if ( !Html::isXmlMimeType( $this->getConfig()->get( 'MimeType' ) ) ) { + if ( !Html::isXmlMimeType( $config->get( 'MimeType' ) ) ) { // Add // This should be before since it defines the charset used by // text including the text inside <title>. @@ -3044,18 +3045,15 @@ class OutputPage extends ContextSource { $pieces = array_merge( $pieces, array_values( $this->getHeadLinksArray() ) ); $pieces = array_merge( $pieces, array_values( $this->mHeadItems ) ); + // This library is intended to run on older browsers that MediaWiki no longer + // supports as Grade A. For these Grade C browsers, we provide an experience + // using only HTML and CSS. Where standards-compliant browsers are able to style + // unknown HTML elements without issue, old IE ignores these styles. + // The html5shiv library fixes that. // Use an IE conditional comment to serve the script only to old IE + $shivUrl = $config->get( 'ResourceBasePath' ) . '/resources/lib/html5shiv/html5shiv.js'; $pieces[] = '<!--[if lt IE 9]>' . - ResourceLoaderClientHtml::makeLoad( - new ResourceLoaderContext( - $this->getResourceLoader(), - new FauxRequest( [] ) - ), - [ 'html5shiv' ], - ResourceLoaderModule::TYPE_SCRIPTS, - [ 'raw' => '1', 'sync' => '1' ], - $this->getCSPNonce() - ) . + Html::linkedScript( $shivUrl, $this->getCSPNonce() ) . '<![endif]-->'; $pieces[] = Html::closeElement( 'head' ); diff --git a/resources/Resources.php b/resources/Resources.php index 39eb0e8184..c24e3eb29c 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -2820,14 +2820,7 @@ return [ ], ], - /** - * html5shiv - * - * This library is intended to run on older browsers - * that MediaWiki no longer supports as Grade A, and - * is not loaded through the normal module loading - * system. - */ + // @todo FIXME: Remove 7 days after Ib0020b6bd0156 is deployed to all wikis. 'html5shiv' => [ 'scripts' => [ 'resources/lib/html5shiv/html5shiv.js' -- 2.20.1