2020-05-04 20:01:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-08-19 09:15:34 +00:00
|
|
|
namespace MediaWiki\Utils;
|
2020-05-04 20:01:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @since 1.35
|
|
|
|
|
*/
|
|
|
|
|
class ExtensionInfo {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Obtains the full path of a AUTHORS or CREDITS file if one exists.
|
|
|
|
|
*
|
|
|
|
|
* @param string $dir Path to the root directory
|
|
|
|
|
*
|
|
|
|
|
* @since 1.35
|
|
|
|
|
*
|
2022-11-09 00:11:22 +00:00
|
|
|
* @return string|false False if no such file exists, otherwise returns
|
2020-05-04 20:01:38 +00:00
|
|
|
* a path to it.
|
|
|
|
|
*/
|
|
|
|
|
public static function getAuthorsFileName( $dir ) {
|
|
|
|
|
if ( !$dir ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( scandir( $dir ) as $file ) {
|
|
|
|
|
$fullPath = $dir . DIRECTORY_SEPARATOR . $file;
|
|
|
|
|
if ( preg_match( '/^(AUTHORS|CREDITS)(\.txt|\.wiki|\.mediawiki)?$/', $file ) &&
|
|
|
|
|
is_readable( $fullPath ) &&
|
|
|
|
|
is_file( $fullPath )
|
|
|
|
|
) {
|
|
|
|
|
return $fullPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-05-05 22:29:39 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Obtains the full paths of COPYING or LICENSE files if they exist.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.35
|
2022-09-28 20:39:23 +00:00
|
|
|
* @param string $extDir Path to the extensions root directory
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[] Returns an array of zero or more paths.
|
2020-05-05 22:29:39 +00:00
|
|
|
*/
|
2022-09-28 20:39:23 +00:00
|
|
|
public static function getLicenseFileNames( string $extDir ): array {
|
2020-05-05 22:29:39 +00:00
|
|
|
if ( !$extDir ) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$licenseFiles = [];
|
|
|
|
|
foreach ( scandir( $extDir ) as $file ) {
|
|
|
|
|
$fullPath = $extDir . DIRECTORY_SEPARATOR . $file;
|
|
|
|
|
// Allow files like GPL-COPYING and MIT-LICENSE
|
|
|
|
|
if ( preg_match( '/^([\w\.-]+)?(COPYING|LICENSE)(\.txt)?$/', $file ) &&
|
|
|
|
|
is_readable( $fullPath ) &&
|
|
|
|
|
is_file( $fullPath )
|
|
|
|
|
) {
|
|
|
|
|
$licenseFiles[] = $fullPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $licenseFiles;
|
|
|
|
|
}
|
2020-05-04 20:01:38 +00:00
|
|
|
}
|
2023-08-19 09:15:34 +00:00
|
|
|
|
2024-03-07 21:56:58 +00:00
|
|
|
/** @deprecated class alias since 1.41 */
|
2023-08-19 09:15:34 +00:00
|
|
|
class_alias( ExtensionInfo::class, 'MediaWiki\\ExtensionInfo' );
|