Debian Codegraph @

includes/utils/ExtensionInfo.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Utils;
4
5 /**
6 * @since 1.35
7 */
8 class ExtensionInfo {
9
10 /**
11 * Obtains the full path of a AUTHORS or CREDITS file if one exists.
12 *
13 * @param string $dir Path to the root directory
14 *
15 * @since 1.35
16 *
17 * @return string|false False if no such file exists, otherwise returns
18 * a path to it.
19 */
20 public static function getAuthorsFileName( $dir ) {
21 if ( !$dir ) {
22 return false;
23 }
24
25 foreach ( scandir( $dir ) as $file ) {
26 $fullPath = $dir . DIRECTORY_SEPARATOR . $file;
27 if ( preg_match( '/^(AUTHORS|CREDITS)(\.txt|\.wiki|\.mediawiki)?$/', $file ) &&
28 is_readable( $fullPath ) &&
29 is_file( $fullPath )
30 ) {
31 return $fullPath;
32 }
33 }
34
35 return false;
36 }
37
38 /**
39 * Obtains the full paths of COPYING or LICENSE files if they exist.
40 *
41 * @since 1.35
42 * @param string $extDir Path to the extensions root directory
43 * @return string[] Returns an array of zero or more paths.
44 */
45 public static function getLicenseFileNames( string $extDir ): array {
46 if ( !$extDir ) {
47 return [];
48 }
49
50 $licenseFiles = [];
51 foreach ( scandir( $extDir ) as $file ) {
52 $fullPath = $extDir . DIRECTORY_SEPARATOR . $file;
53 // Allow files like GPL-COPYING and MIT-LICENSE
54 if ( preg_match( '/^([\w\.-]+)?(COPYING|LICENSE)(\.txt)?$/', $file ) &&
55 is_readable( $fullPath ) &&
56 is_file( $fullPath )
57 ) {
58 $licenseFiles[] = $fullPath;
59 }
60 }
61
62 return $licenseFiles;
63 }
64 }
65
66 /** @deprecated class alias since 1.41 */
67 class_alias( ExtensionInfo::class, 'MediaWiki\\ExtensionInfo' );