* Remove some use of `count()` in favour of boolean checks.
* Where trivial to do, add native return types to remove doubt
of the value possibly not being an array.
* Follow-up I7d97a4cdc9 (d4df7daa) and mark more methods as private
that were wrongly marked public en-mass when we added visibility
attributes but have no use outside core on a SpecialPage class that
generally has no use case for being extended or instantiated
outside core.
Change-Id: Iaf28b6132097fe34872c2a2da374ff00593ca6a9
64 lines
1.4 KiB
PHP
64 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki;
|
|
|
|
/**
|
|
* @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
|
|
*
|
|
* @return bool|string False if no such file exists, otherwise returns
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* Obtains the full paths of COPYING or LICENSE files if they exist.
|
|
*
|
|
* @since 1.35
|
|
* @param string $extDir Path to the extensions root directory
|
|
* @return string[] Returns an array of zero or more paths.
|
|
*/
|
|
public static function getLicenseFileNames( string $extDir ): array {
|
|
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;
|
|
}
|
|
}
|