Mattflaschen has uploaded a new change for review.

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

Change subject: Also support skin.json for updating JSON AutoloadClasses
......................................................................

Also support skin.json for updating JSON AutoloadClasses

Bug: T88194
Change-Id: Ib56680e6e0e983184e31c336dcac174922a86551
---
M includes/utils/AutoloadGenerator.php
1 file changed, 60 insertions(+), 55 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/68/217768/1

diff --git a/includes/utils/AutoloadGenerator.php 
b/includes/utils/AutoloadGenerator.php
index dd1a38a..5cbda45 100644
--- a/includes/utils/AutoloadGenerator.php
+++ b/includes/utils/AutoloadGenerator.php
@@ -130,74 +130,80 @@
                // We need to check whether an extenson.json exists or not, and
                // incase it doesn't, update the autoload.php file.
 
-               if ( file_exists( $this->basepath . '/extension.json' ) ) {
-                       require_once __DIR__ . 
'/../../includes/json/FormatJson.php';
-                       $key = 'AutoloadClasses';
-                       $json = FormatJson::decode( file_get_contents( 
$this->basepath
-                               . '/extension.json' ), true );
-                       unset( $json[$key] );
-                       // Inverting the key-value pairs so that they become of 
the
-                       // format class-name : path when they get converted 
into json.
-                       foreach ( $this->classes as $path => $contained ) {
-                               foreach ( $contained as $fqcn ) {
+               $jsonFilenames = array( 'extension.json', 'skin.json' );
+               foreach ( $jsonFilenames as $jsonFilename ) {
+                       if ( file_exists( $this->basepath . "/$jsonFilename" ) 
) {
+                               require_once __DIR__ . 
'/../../includes/json/FormatJson.php';
+                               $key = 'AutoloadClasses';
+                               $json = FormatJson::decode( file_get_contents( 
$this->basepath
+                                               . "/$jsonFilename" ), true );
+                               unset( $json[$key] );
+                               // Inverting the key-value pairs so that they 
become of the
+                               // format class-name : path when they get 
converted into json.
+                               foreach ( $this->classes as $path => $contained 
) {
+                                       foreach ( $contained as $fqcn ) {
+
+                                               // Using substr to remove the 
leading '/'
+                                               $json[$key][$fqcn] = substr( 
$path, 1 );
+                                       }
+                               }
+                               foreach ( $this->overrides as $path => $fqcn ) {
 
                                        // Using substr to remove the leading 
'/'
                                        $json[$key][$fqcn] = substr( $path, 1 );
                                }
+
+                               // Sorting the list of autoload classes.
+                               ksort( $json[$key] );
+
+                               // Update file, using constants for the required
+                               // formatting.
+                               file_put_contents( $this->basepath . 
"/$jsonFilename",
+                                       FormatJson::encode( $json, true ) . 
"\n" );
+                               return;
                        }
-                       foreach ( $this->overrides as $path => $fqcn ) {
+               }
 
-                               // Using substr to remove the leading '/'
-                               $json[$key][$fqcn] = substr( $path, 1 );
-                       }
+               // No existing JSON file found; update/generate PHP file
+               $content = array();
 
-                       // Sorting the list of autoload classes.
-                       ksort( $json[$key] );
-
-                       // Update extension.json, using constants for the 
required
-                       // formatting.
-                       file_put_contents( $this->basepath . '/extension.json',
-                               FormatJson::encode( $json, true ) . "\n" );
-               } else {
-                       $content = array();
-
-                       // We need to generate a line each rather than 
exporting the
-                       // full array so __DIR__ can be prepended to all the 
paths
-                       $format = "%s => __DIR__ . %s,";
-                       foreach ( $this->classes as $path => $contained ) {
-                               $exportedPath = var_export( $path, true );
-                               foreach ( $contained as $fqcn ) {
-                                       $content[$fqcn] = sprintf(
-                                               $format,
-                                               var_export( $fqcn, true ),
-                                               $exportedPath
-                                       );
-                               }
-                       }
-
-                       foreach ( $this->overrides as $fqcn => $path ) {
+               // We need to generate a line each rather than exporting the
+               // full array so __DIR__ can be prepended to all the paths
+               $format = "%s => __DIR__ . %s,";
+               foreach ( $this->classes as $path => $contained ) {
+                       $exportedPath = var_export( $path, true );
+                       foreach ( $contained as $fqcn ) {
                                $content[$fqcn] = sprintf(
                                        $format,
                                        var_export( $fqcn, true ),
-                                       var_export( $path, true )
+                                       $exportedPath
                                );
                        }
+               }
 
-                       // sort for stable output
-                       ksort( $content );
+               foreach ( $this->overrides as $fqcn => $path ) {
+                       $content[$fqcn] = sprintf(
+                               $format,
+                               var_export( $fqcn, true ),
+                               var_export( $path, true )
+                       );
+               }
 
-                       // extensions using this generator are appending to the 
existing
-                       // autoload.
-                       if ( $this->variableName === 'wgAutoloadClasses' ) {
-                               $op = '+=';
-                       } else {
-                               $op = '=';
-                       }
+               // sort for stable output
+               ksort( $content );
 
-                       $output = implode( "\n\t", $content );
-                       file_put_contents(
-                               $this->basepath . '/autoload.php',
-                               <<<EOD
+               // extensions using this generator are appending to the existing
+               // autoload.
+               if ( $this->variableName === 'wgAutoloadClasses' ) {
+                       $op = '+=';
+               } else {
+                       $op = '=';
+               }
+
+               $output = implode( "\n\t", $content );
+               file_put_contents(
+                       $this->basepath . '/autoload.php',
+                       <<<EOD
 <?php
 // This file is generated by $commandName, do not adjust manually
 // @codingStandardsIgnoreFile
@@ -208,8 +214,7 @@
 );
 
 EOD
-                       );
-               }
+               );
        }
        /**
         * Ensure that Unix-style path separators ("/") are used in the path.

-- 
To view, visit https://gerrit.wikimedia.org/r/217768
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib56680e6e0e983184e31c336dcac174922a86551
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <mflasc...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to