+ /**
+ * @param string $type Either "extension" or "skin"
+ * @param string $parentRelPath The parent directory relative to $IP
+ * @param string $name The extension or skin name
+ * @return Status An object containing an error list. If there were no errors, an associative
+ * array of information about the extension can be found in $status->value.
+ */
+ protected function getExtensionInfo( $type, $parentRelPath, $name ) {
+ if ( $this->getVar( 'IP' ) === null ) {
+ throw new Exception( 'Cannot find extensions since the IP variable is not yet set' );
+ }
+ if ( $type !== 'extension' && $type !== 'skin' ) {
+ throw new InvalidArgumentException( "Invalid extension type" );
+ }
+ $absDir = $this->getVar( 'IP' ) . "/$parentRelPath/$name";
+ $relDir = "../$parentRelPath/$name";
+ if ( !is_dir( $absDir ) ) {
+ return Status::newFatal( 'config-extension-not-found', $name );
+ }
+ $jsonFile = $type . '.json';
+ $fullJsonFile = "$absDir/$jsonFile";
+ $isJson = file_exists( $fullJsonFile );
+ $isPhp = false;
+ if ( !$isJson ) {
+ // Only fallback to PHP file if JSON doesn't exist
+ $fullPhpFile = "$absDir/$name.php";
+ $isPhp = file_exists( $fullPhpFile );
+ }
+ if ( !$isJson && !$isPhp ) {
+ return Status::newFatal( 'config-extension-not-found', $name );
+ }
+
+ // Extension exists. Now see if there are screenshots
+ $info = [];
+ if ( is_dir( "$absDir/screenshots" ) ) {
+ $paths = glob( "$absDir/screenshots/*.png" );
+ foreach ( $paths as $path ) {
+ $info['screenshots'][] = str_replace( $absDir, $relDir, $path );
+ }
+ }
+
+ if ( $isJson ) {
+ $jsonStatus = $this->readExtension( $fullJsonFile );
+ if ( !$jsonStatus->isOK() ) {
+ return $jsonStatus;
+ }
+ $info += $jsonStatus->value;
+ }
+
+ return Status::newGood( $info );
+ }
+