2019-03-21 23:59:32 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
|
|
|
|
|
|
2022-10-03 12:05:50 +00:00
|
|
|
// Whilst MediaWiki is still supporting PHP 7.4+, this lets us run phan on higher versions of PHP
|
|
|
|
|
// like 8.0 without phan trying to get us to make PHP 7.4-incompatible changes. This value should
|
2021-12-20 12:24:56 +00:00
|
|
|
// match the PHP version specified in composer.json and PHPVersionCheck.php.
|
2022-10-03 12:05:50 +00:00
|
|
|
$cfg['minimum_target_php_version'] = '7.4.3';
|
2021-12-20 12:24:56 +00:00
|
|
|
|
2019-03-21 23:59:32 +00:00
|
|
|
$cfg['file_list'] = array_merge(
|
|
|
|
|
$cfg['file_list'],
|
Respond to some messages from Phan on PHP 8.1
* ForkController, OrderedStreamingForkController: indeed pcntl_fork()
can't return false.
* RL\Image: Specify type instead of using suppression, since the issue
name changes.
* VueComponentParser: Accept complaint about nullable nodeValue.
* Disable PHP 8.0 polyfill stubs when running on PHP 8.0+ to avoid
duplicate interface errors.
* Add Socket stub and use it in LegacyHandler instead of multiple
existing suppressions.
* MemcachedPeclBagOStuff: accept complaint recommending !$result over
$result === false when the type is boolean.
* MemcachedPeclBagOStuff: fix probable bug, ignoring errors from
Memcached::getMulti(). Phan noticed that $res=false was unreachable,
but it should probably be reachable.
* DatabaseMysqli: accept complaint that $this->conn->errno is already
known to be an int. It was probably a hack for some previous version
of Phan.
* BcryptPassword, MWOldPassword, MWSaltedPassword: accept complaint that
the !is_string() checks are unnecessary, after code review of PHP.
* Pbkdf2PasswordUsingHashExtension: note that contrary to Phan's
suggestion, this check is necessary.
* DefaultPreferencesFactory: remove an existing hack for
array_diff_key(), no longer necessary on 7.4 and causes an error on
8.1. Use coalesce instead of cast for the remaining
array_intersect_key() hack since it better shows that we are casting
away null.
* FullSearchResultWidget: fix likely bug involving strict comparison
between a float and an int.
* SpecialWatchlist: accept complaint that $selectedHours is
unconditionally a float, being the return value of round(), and thus
the cast is unnecessary.
* Add stub for AllowDynamicProperties, resolving an error in User.php.
* Xml: accept complaint that $encMonth is already known to be an int.
Six errors remain. These need suppressions or otherwise conflict with
PHP 7.4 support.
Bug: T322278
Change-Id: Ie375bbc8ccf22330b9a169e8da98f2bbe26ec8b9
2022-11-03 01:55:46 +00:00
|
|
|
class_exists( Socket::class ) ? [] : [ '.phan/stubs/Socket.php' ],
|
|
|
|
|
class_exists( AllowDynamicProperties::class ) ? [] : [ '.phan/stubs/AllowDynamicProperties.php' ],
|
2023-02-12 14:05:57 +00:00
|
|
|
class_exists( WeakMap::class ) ? [] : [ '.phan/stubs/WeakMap.php' ],
|
2019-03-21 23:59:32 +00:00
|
|
|
[
|
2019-09-01 12:45:11 +00:00
|
|
|
// This makes constants and globals known to Phan before processing all other files.
|
|
|
|
|
// You can check the parser order with --dump-parsed-file-list
|
|
|
|
|
'includes/Defines.php',
|
|
|
|
|
// @todo This isn't working yet, see globals_type_map below
|
|
|
|
|
// 'includes/Setup.php',
|
2022-06-01 21:19:57 +00:00
|
|
|
'tests/phpunit/MediaWikiIntegrationTestCase.php',
|
|
|
|
|
'tests/phpunit/includes/TestUser.php',
|
2019-03-21 23:59:32 +00:00
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
2019-09-01 12:45:11 +00:00
|
|
|
$cfg['exclude_file_list'] = array_merge(
|
|
|
|
|
$cfg['exclude_file_list'],
|
|
|
|
|
[
|
2022-11-09 05:32:23 +00:00
|
|
|
// Avoid microsoft/tolerant-php-parser dependency
|
|
|
|
|
'maintenance/findDeprecated.php',
|
|
|
|
|
'maintenance/CodeCleanerGlobalsPass.php',
|
|
|
|
|
// Avoid nikic/php-parser dependency
|
|
|
|
|
'maintenance/shell.php',
|
2019-09-01 12:45:11 +00:00
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
Respond to some messages from Phan on PHP 8.1
* ForkController, OrderedStreamingForkController: indeed pcntl_fork()
can't return false.
* RL\Image: Specify type instead of using suppression, since the issue
name changes.
* VueComponentParser: Accept complaint about nullable nodeValue.
* Disable PHP 8.0 polyfill stubs when running on PHP 8.0+ to avoid
duplicate interface errors.
* Add Socket stub and use it in LegacyHandler instead of multiple
existing suppressions.
* MemcachedPeclBagOStuff: accept complaint recommending !$result over
$result === false when the type is boolean.
* MemcachedPeclBagOStuff: fix probable bug, ignoring errors from
Memcached::getMulti(). Phan noticed that $res=false was unreachable,
but it should probably be reachable.
* DatabaseMysqli: accept complaint that $this->conn->errno is already
known to be an int. It was probably a hack for some previous version
of Phan.
* BcryptPassword, MWOldPassword, MWSaltedPassword: accept complaint that
the !is_string() checks are unnecessary, after code review of PHP.
* Pbkdf2PasswordUsingHashExtension: note that contrary to Phan's
suggestion, this check is necessary.
* DefaultPreferencesFactory: remove an existing hack for
array_diff_key(), no longer necessary on 7.4 and causes an error on
8.1. Use coalesce instead of cast for the remaining
array_intersect_key() hack since it better shows that we are casting
away null.
* FullSearchResultWidget: fix likely bug involving strict comparison
between a float and an int.
* SpecialWatchlist: accept complaint that $selectedHours is
unconditionally a float, being the return value of round(), and thus
the cast is unnecessary.
* Add stub for AllowDynamicProperties, resolving an error in User.php.
* Xml: accept complaint that $encMonth is already known to be an int.
Six errors remain. These need suppressions or otherwise conflict with
PHP 7.4 support.
Bug: T322278
Change-Id: Ie375bbc8ccf22330b9a169e8da98f2bbe26ec8b9
2022-11-03 01:55:46 +00:00
|
|
|
if ( PHP_VERSION_ID >= 80000 ) {
|
|
|
|
|
// Exclude PHP 8.0 polyfills if PHP 8.0+ is running
|
|
|
|
|
$cfg['exclude_file_list'] = array_merge(
|
|
|
|
|
$cfg['exclude_file_list'],
|
|
|
|
|
[
|
|
|
|
|
'vendor/symfony/polyfill-php80/Resources/stubs/Attribute.php',
|
|
|
|
|
'vendor/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
|
|
|
|
|
'vendor/symfony/polyfill-php80/Resources/stubs/Stringable.php',
|
|
|
|
|
'vendor/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
|
|
|
|
|
'vendor/symfony/polyfill-php80/Resources/stubs/ValueError.php',
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 23:59:32 +00:00
|
|
|
$cfg['autoload_internal_extension_signatures'] = [
|
2023-05-28 11:52:05 +00:00
|
|
|
'excimer' => '.phan/internal_stubs/excimer.phan_php',
|
2019-06-18 19:19:37 +00:00
|
|
|
'imagick' => '.phan/internal_stubs/imagick.phan_php',
|
2019-03-21 23:59:32 +00:00
|
|
|
'memcached' => '.phan/internal_stubs/memcached.phan_php',
|
2019-06-18 19:19:37 +00:00
|
|
|
'pcntl' => '.phan/internal_stubs/pcntl.phan_php',
|
2019-09-01 12:45:11 +00:00
|
|
|
'pgsql' => '.phan/internal_stubs/pgsql.phan_php',
|
2019-06-18 19:19:37 +00:00
|
|
|
'redis' => '.phan/internal_stubs/redis.phan_php',
|
|
|
|
|
'sockets' => '.phan/internal_stubs/sockets.phan_php',
|
2022-11-26 07:18:47 +00:00
|
|
|
'tideways_xhprof' => '.phan/internal_stubs/tideways_xhprof.phan_php',
|
2020-02-25 09:44:56 +00:00
|
|
|
'wikidiff2' => '.phan/internal_stubs/wikidiff.php'
|
2019-03-21 23:59:32 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$cfg['directory_list'] = [
|
|
|
|
|
'includes/',
|
|
|
|
|
'languages/',
|
|
|
|
|
'maintenance/',
|
|
|
|
|
'mw-config/',
|
|
|
|
|
'resources/',
|
2022-06-01 21:19:57 +00:00
|
|
|
'tests/common/',
|
|
|
|
|
'tests/parser/',
|
2022-10-27 14:51:52 +00:00
|
|
|
'tests/phan',
|
2022-06-01 21:19:57 +00:00
|
|
|
'tests/phpunit/mocks/',
|
2020-02-13 18:20:57 +00:00
|
|
|
// Do NOT add .phan/stubs/ here: stubs are conditionally loaded in file_list
|
2019-03-21 23:59:32 +00:00
|
|
|
];
|
|
|
|
|
|
2022-11-09 05:32:23 +00:00
|
|
|
// Include only direct production dependencies in vendor/
|
|
|
|
|
// Omit dev dependencies and most indirect dependencies
|
|
|
|
|
|
|
|
|
|
$composerJson = json_decode(
|
|
|
|
|
file_get_contents( __DIR__ . '/../composer.json' ),
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$directDeps = [];
|
|
|
|
|
foreach ( $composerJson['require'] as $dep => $version ) {
|
|
|
|
|
$parts = explode( '/', $dep );
|
|
|
|
|
if ( count( $parts ) === 2 ) {
|
|
|
|
|
$directDeps[] = $dep;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is a list of all composer packages that are referenced by core but
|
|
|
|
|
// are not listed as requirements in composer.json.
|
|
|
|
|
$indirectDeps = [
|
|
|
|
|
'composer/spdx-licenses',
|
|
|
|
|
'doctrine/dbal',
|
|
|
|
|
'doctrine/sql-formatter',
|
|
|
|
|
'guzzlehttp/psr7',
|
|
|
|
|
'pear/net_url2',
|
|
|
|
|
'pear/pear-core-minimal',
|
|
|
|
|
'phpunit/phpunit',
|
2024-08-12 01:18:57 +00:00
|
|
|
'psr/http-client',
|
|
|
|
|
'psr/http-factory',
|
2022-11-09 05:32:23 +00:00
|
|
|
'psr/http-message',
|
|
|
|
|
'seld/jsonlint',
|
|
|
|
|
'wikimedia/testing-access-wrapper',
|
|
|
|
|
'wikimedia/zest-css',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ( [ ...$directDeps, ...$indirectDeps ] as $dep ) {
|
|
|
|
|
$cfg['directory_list'][] = "vendor/$dep";
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 23:59:32 +00:00
|
|
|
$cfg['exclude_analysis_directory_list'] = [
|
|
|
|
|
'vendor/',
|
2019-09-01 12:45:11 +00:00
|
|
|
'.phan/',
|
2022-06-01 21:19:57 +00:00
|
|
|
'tests/phpunit/',
|
2019-03-21 23:59:32 +00:00
|
|
|
// The referenced classes are not available in vendor, only when
|
|
|
|
|
// included from composer.
|
|
|
|
|
'includes/composer/',
|
|
|
|
|
// Directly references classes that only exist in Translate extension
|
|
|
|
|
'maintenance/language/',
|
|
|
|
|
// External class
|
2019-09-04 18:23:25 +00:00
|
|
|
'includes/libs/objectcache/utils/MemcachedClient.php',
|
2021-03-10 06:11:45 +00:00
|
|
|
// File may be valid, but may contain numerous "errors" such as iterating over an
|
|
|
|
|
// empty array due to the version checking in T246594 not being currently used.
|
|
|
|
|
'includes/PHPVersionCheck.php',
|
2019-03-21 23:59:32 +00:00
|
|
|
];
|
|
|
|
|
|
2023-09-23 12:52:12 +00:00
|
|
|
// TODO: Ideally we'd disable this in core, given we don't need backwards compatibility here and aliases
|
|
|
|
|
// should not be used. However, that would have unwanted side effects such as being unable to test
|
|
|
|
|
// taint-check (T321806).
|
|
|
|
|
$cfg['enable_class_alias_support'] = true;
|
2024-02-16 20:14:08 +00:00
|
|
|
// Exclude Parsoid's src/DOM in favor of .phan/stubs/DomImpl.php
|
|
|
|
|
$cfg['exclude_file_list'] = array_merge(
|
|
|
|
|
$cfg['exclude_file_list'],
|
|
|
|
|
array_map( fn ( $f ) => "vendor/wikimedia/parsoid/src/DOM/{$f}.php", [
|
|
|
|
|
'Attr', 'CharacterData', 'Comment', 'Document', 'DocumentFragment',
|
|
|
|
|
'DocumentType', 'Element', 'Node', 'ProcessingInstruction', 'Text',
|
|
|
|
|
] )
|
|
|
|
|
);
|
|
|
|
|
$cfg['file_list'][] = '.phan/stubs/DomImpl.php';
|
2019-09-12 19:40:57 +00:00
|
|
|
|
2019-03-21 23:59:32 +00:00
|
|
|
$cfg['ignore_undeclared_variables_in_global_scope'] = true;
|
2022-04-27 14:31:59 +00:00
|
|
|
// @todo It'd be great if we could just make phan read these from config-schema.php, to avoid
|
|
|
|
|
// duplicating the types. config-schema.php has JSON types though, not PHP types.
|
|
|
|
|
// @todo As we are removing access to global variables from the code base,
|
|
|
|
|
// remove them from here as well, so phan complains when something tries to use them.
|
2019-08-29 09:59:59 +00:00
|
|
|
$cfg['globals_type_map'] = array_merge( $cfg['globals_type_map'], [
|
|
|
|
|
'IP' => 'string',
|
2023-09-11 21:22:12 +00:00
|
|
|
'wgTitle' => \MediaWiki\Title\Title::class,
|
2019-08-29 09:59:59 +00:00
|
|
|
'wgGalleryOptions' => 'array',
|
2023-10-03 03:51:10 +00:00
|
|
|
'wgDirectoryMode' => 'int',
|
2019-08-29 09:59:59 +00:00
|
|
|
'wgDummyLanguageCodes' => 'string[]',
|
2022-03-16 23:34:23 +00:00
|
|
|
'wgNamespaceProtection' => 'array<int,string|string[]>',
|
2019-08-30 17:56:27 +00:00
|
|
|
'wgNamespaceAliases' => 'array<string,int>',
|
|
|
|
|
'wgLockManagers' => 'array[]',
|
|
|
|
|
'wgForeignFileRepos' => 'array[]',
|
|
|
|
|
'wgDefaultUserOptions' => 'array',
|
|
|
|
|
'wgSkipSkins' => 'string[]',
|
|
|
|
|
'wgLogTypes' => 'string[]',
|
|
|
|
|
'wgLogNames' => 'array<string,string>',
|
|
|
|
|
'wgLogHeaders' => 'array<string,string>',
|
|
|
|
|
'wgLogActionsHandlers' => 'array<string,class-string>',
|
|
|
|
|
'wgPasswordPolicy' => 'array<string,array<string,string|array>>',
|
|
|
|
|
'wgVirtualRestConfig' => 'array<string,array>',
|
|
|
|
|
'wgLocalInterwikis' => 'string[]',
|
2019-09-01 12:45:11 +00:00
|
|
|
'wgDebugLogGroups' => 'string|false|array{destination:string,sample?:int,level:int}',
|
2019-09-01 14:00:35 +00:00
|
|
|
'wgCookiePrefix' => 'string|false',
|
2023-09-11 21:22:12 +00:00
|
|
|
'wgOut' => \MediaWiki\Output\OutputPage::class,
|
2019-09-01 14:00:35 +00:00
|
|
|
'wgExtraNamespaces' => 'string[]',
|
2023-09-11 21:22:12 +00:00
|
|
|
'wgRequest' => \MediaWiki\Request\WebRequest::class,
|
2019-08-29 09:59:59 +00:00
|
|
|
] );
|
2019-03-21 23:59:32 +00:00
|
|
|
|
2020-11-03 23:25:52 +00:00
|
|
|
// Include a local config file if it exists
|
|
|
|
|
if ( file_exists( __DIR__ . '/local-config.php' ) ) {
|
|
|
|
|
require __DIR__ . '/local-config.php';
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 23:59:32 +00:00
|
|
|
return $cfg;
|