Wrap libxml_disable_entity_loader() calls in version constraint
[mediawiki.git] / includes / ExtensionInfo.php
bloba24d1d786f8ec7e2a9df5df687b338bbd02636d0
1 <?php
3 namespace MediaWiki;
5 /**
6 * @since 1.35
7 */
8 class ExtensionInfo {
10 /**
11 * Obtains the full path of a AUTHORS or CREDITS file if one exists.
13 * @param string $dir Path to the root directory
15 * @since 1.35
17 * @return bool|string False if no such file exists, otherwise returns
18 * a path to it.
20 public static function getAuthorsFileName( $dir ) {
21 if ( !$dir ) {
22 return false;
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;
35 return false;
38 /**
39 * Obtains the full paths of COPYING or LICENSE files if they exist.
41 * @param string $extDir Path to the extensions root directory
43 * @since 1.35
45 * @return string[] Returns an array of zero or more paths.
47 public static function getLicenseFileNames( $extDir ) {
48 if ( !$extDir ) {
49 return [];
52 $licenseFiles = [];
53 foreach ( scandir( $extDir ) as $file ) {
54 $fullPath = $extDir . DIRECTORY_SEPARATOR . $file;
55 // Allow files like GPL-COPYING and MIT-LICENSE
56 if ( preg_match( '/^([\w\.-]+)?(COPYING|LICENSE)(\.txt)?$/', $file ) &&
57 is_readable( $fullPath ) &&
58 is_file( $fullPath )
59 ) {
60 $licenseFiles[] = $fullPath;
64 return $licenseFiles;