OutputPage: Remove support for non-existent /w/skins/common directory
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 21 May 2018 21:08:02 +0000 (22:08 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 22 May 2018 11:07:42 +0000 (11:07 +0000)
Test Plan:
* Add calls `$this->addScriptFile( 'example.js' )` and
  `$this->addScriptFile( '/example.js' )` to top of OutputPage::output().
* Without this change, two `<script>` are added.
* With this change, only for the latter a script is added,
  and the former triggers a deprecation warning.

Bug: T71277
Bug: T181318
Change-Id: I0576ef09fafa4ba34d52d75f4211fcfa28f4f3b0

includes/OutputPage.php

index c7028db..6c45d9c 100644 (file)
@@ -463,20 +463,22 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Add a JavaScript file out of skins/common, or a given relative path.
+        * Add a JavaScript file to be loaded as `<script>` on this page.
+        *
         * Internal use only. Use OutputPage::addModules() if possible.
         *
-        * @param string $file Filename in skins/common or complete on-server path
-        *              (/foo/bar.js)
+        * @param string $file URL to file (absolute path, protocol-relative, or full url)
         * @param string $version Style version of the file. Defaults to $wgStyleVersion
         */
        public function addScriptFile( $file, $version = null ) {
-               // See if $file parameter is an absolute URL or begins with a slash
-               if ( substr( $file, 0, 1 ) == '/' || preg_match( '#^[a-z]*://#i', $file ) ) {
-                       $path = $file;
-               } else {
-                       $path = $this->getConfig()->get( 'StylePath' ) . "/common/{$file}";
+               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,
+                       // which doesn't exist anymore as of MediaWiki 1.24 per T71277. Ignore.
+                       wfDeprecated( __METHOD__, '1.24' );
+                       return;
                }
+               $path = $file;
                if ( is_null( $version ) ) {
                        $version = $this->getConfig()->get( 'StyleVersion' );
                }