OutputPage: Remove appending of wgStyleVersion to legacy resources
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 21 May 2018 21:21:28 +0000 (22:21 +0100)
committerKrinkle <krinklemail@gmail.com>
Wed, 23 May 2018 20:00:28 +0000 (20:00 +0000)
For addScriptFile(), just remove the appending of wgStyleVersion.
Going forward, anyone still using this, should simply append a query
parameter themselves in a way that is specific to that one url
(instead of relying on a generic global variable). Alternatively, one
could use OutputPage::transformResourcePath if the file is in /w/.

For addStyles(), also remove the appending of wgStyleVersion. Since this
method takes paths relative to /w/skins, we can easily update this to
automatically use transformResourcePath(), so that file-hash based query
parameters are automatically added.

Test Plan:
* Add calls to top of OutputPage::output():
  `$this->addStyle( 'Vector/README.md' );`
  `$this->addScriptFile( "{$GLOBALS['wgScriptPath']}/composer.json" );`
* Before, they are both inserted as `<link>` (head) and `<script>` (body)
  with a query parameter based on wgStyleVersion.
* After, the `<script>` (end of body) has no query.
  After, the stylesheet (head) has a SHA1 content hash as query.

Bug: T181318
Change-Id: Ie5ab5066ef7d07279086bde838d7305e9e4eabaf

includes/OutputPage.php

index 6c45d9c..7f72d36 100644 (file)
@@ -468,9 +468,9 @@ class OutputPage extends ContextSource {
         * Internal use only. Use OutputPage::addModules() if possible.
         *
         * @param string $file URL to file (absolute path, protocol-relative, or full url)
-        * @param string $version Style version of the file. Defaults to $wgStyleVersion
+        * @param string $unused Previously used to change the cache-busting query parameter
         */
-       public function addScriptFile( $file, $version = null ) {
+       public function addScriptFile( $file, $unused = null ) {
                if ( substr( $file, 0, 1 ) !== '/' && !preg_match( '#^[a-z]*://#i', $file ) ) {
                        // This is not an absolute path, protocol-relative url, or full scheme url,
                        // presumed to be an old call intended to include a file from /w/skins/common,
@@ -478,11 +478,7 @@ class OutputPage extends ContextSource {
                        wfDeprecated( __METHOD__, '1.24' );
                        return;
                }
-               $path = $file;
-               if ( is_null( $version ) ) {
-                       $version = $this->getConfig()->get( 'StyleVersion' );
-               }
-               $this->addScript( Html::linkedScript( wfAppendQuery( $path, $version ), $this->getCSPNonce() ) );
+               $this->addScript( Html::linkedScript( $file, $this->getCSPNonce() ) );
        }
 
        /**
@@ -3666,8 +3662,11 @@ class OutputPage extends ContextSource {
                        $url = $style;
                } else {
                        $config = $this->getConfig();
-                       $url = $config->get( 'StylePath' ) . '/' . $style . '?' .
-                               $config->get( 'StyleVersion' );
+                       // Append file hash as query parameter
+                       $url = self::transformResourcePath(
+                               $config,
+                               $config->get( 'StylePath' ) . '/' . $style
+                       );
                }
 
                $link = Html::linkedStyle( $url, $media );