Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ExtensionInfo
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 2
156
0.00% covered (danger)
0.00%
0 / 1
 getAuthorsFileName
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
42
 getLicenseFileNames
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2
3namespace MediaWiki\Utils;
4
5/**
6 * @since 1.35
7 */
8class 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 */
67class_alias( ExtensionInfo::class, 'MediaWiki\\ExtensionInfo' );