blob: a24d1d786f8ec7e2a9df5df687b338bbd02636d0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<?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.
*
* @param string $extDir Path to the extensions root directory
*
* @since 1.35
*
* @return string[] Returns an array of zero or more paths.
*/
public static function getLicenseFileNames( $extDir ) {
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;
}
}
|