X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FGlobalFunctions.php;h=2cde17323617af21de431311d87b11b6cd09339f;hb=06032ec11e671f3e2c68a0d66b2348c828b9098e;hp=1741958681e3f185e1e3449288b86a54e1f04de4;hpb=22ac82f4cd7960735339d23865fce21665ea9c17;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 1741958681..2cde173236 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -24,14 +24,15 @@ if ( !defined( 'MEDIAWIKI' ) ) { die( "This file is part of MediaWiki, it is not a valid entry point" ); } +use MediaWiki\BadFileLookup; use MediaWiki\Linker\LinkTarget; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; use MediaWiki\ProcOpenError; use MediaWiki\Session\SessionManager; use MediaWiki\Shell\Shell; -use Wikimedia\WrappedString; use Wikimedia\AtEase\AtEase; +use Wikimedia\WrappedString; /** * Load an extension @@ -1126,6 +1127,7 @@ function wfLogProfilingData() { if ( isset( $ctx['forwarded_for'] ) || isset( $ctx['client_ip'] ) || isset( $ctx['from'] ) ) { + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $ctx['proxy'] = $_SERVER['REMOTE_ADDR']; } @@ -2114,6 +2116,7 @@ function wfEscapeShellArg( ...$args ) { * including errors from limit.sh * - profileMethod: By default this function will profile based on the calling * method. Set this to a string for an alternative method to profile from + * @phan-param array{duplicateStderr?:bool,profileMethod?:string} $options * * @return string Collected stdout as a string * @deprecated since 1.30 use class MediaWiki\Shell\Shell @@ -2132,6 +2135,7 @@ function wfShellExec( $cmd, &$retval = null, $environ = [], } $includeStderr = isset( $options['duplicateStderr'] ) && $options['duplicateStderr']; + // @phan-suppress-next-line PhanTypeInvalidDimOffset $profileMethod = $options['profileMethod'] ?? wfGetCaller(); try { @@ -2188,6 +2192,7 @@ function wfShellExecWithStderr( $cmd, &$retval = null, $environ = [], $limits = * @param array $options Associative array of options: * 'php': The path to the php executable * 'wrapper': Path to a PHP wrapper to handle the maintenance script + * @phan-param array{php?:string,wrapper?:string} $options * @return string */ function wfShellWikiCmd( $script, array $parameters = [], array $options = [] ) { @@ -2195,6 +2200,7 @@ function wfShellWikiCmd( $script, array $parameters = [], array $options = [] ) // Give site config file a chance to run the script in a wrapper. // The caller may likely want to call wfBasename() on $script. Hooks::run( 'wfShellWikiCmd', [ &$script, &$parameters, &$options ] ); + // @phan-suppress-next-line PhanTypeInvalidDimOffset $cmd = [ $options['php'] ?? $wgPhpCli ]; if ( isset( $options['wrapper'] ) ) { $cmd[] = $options['wrapper']; @@ -2891,6 +2897,7 @@ function wfUnpack( $format, $data, $length = false ) { $result = unpack( $format, $data ); Wikimedia\restoreWarnings(); + // @phan-suppress-next-line PhanTypeComparisonFromArray Phan issue #3160 if ( $result === false ) { // If it cannot extract the packed data. throw new MWException( "unpack could not unpack binary data" ); @@ -2907,72 +2914,27 @@ function wfUnpack( $format, $data, $length = false ) { * * Any subsequent links on the same line are considered to be exceptions, * i.e. articles where the image may occur inline. * + * @deprecated since 1.34, use the BadFileLookup service directly instead + * * @param string $name The image name to check * @param Title|bool $contextTitle The page on which the image occurs, if known * @param string|null $blacklist Wikitext of a file blacklist * @return bool */ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) { - # Handle redirects; callers almost always hit wfFindFile() anyway, - # so just use that method because it has a fast process cache. - $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name ); // get the final name - $name = $file ? $file->getTitle()->getDBkey() : $name; - - # Run the extension hook - $bad = false; - if ( !Hooks::run( 'BadImage', [ $name, &$bad ] ) ) { - return (bool)$bad; - } - - $cache = ObjectCache::getLocalServerInstance( 'hash' ); - $key = $cache->makeKey( - 'bad-image-list', ( $blacklist === null ) ? 'default' : md5( $blacklist ) - ); - $badImages = $cache->get( $key ); - - if ( $badImages === false ) { // cache miss - if ( $blacklist === null ) { - $blacklist = wfMessage( 'bad_image_list' )->inContentLanguage()->plain(); // site list - } - # Build the list now - $badImages = []; - $lines = explode( "\n", $blacklist ); - foreach ( $lines as $line ) { - # List items only - if ( substr( $line, 0, 1 ) !== '*' ) { - continue; - } - - # Find all links - $m = []; - if ( !preg_match_all( '/\[\[:?(.*?)\]\]/', $line, $m ) ) { - continue; - } - - $exceptions = []; - $imageDBkey = false; - foreach ( $m[1] as $i => $titleText ) { - $title = Title::newFromText( $titleText ); - if ( !is_null( $title ) ) { - if ( $i == 0 ) { - $imageDBkey = $title->getDBkey(); - } else { - $exceptions[$title->getPrefixedDBkey()] = true; - } - } - } - - if ( $imageDBkey !== false ) { - $badImages[$imageDBkey] = $exceptions; - } - } - $cache->set( $key, $badImages, 60 ); - } - - $contextKey = $contextTitle ? $contextTitle->getPrefixedDBkey() : false; - $bad = isset( $badImages[$name] ) && !isset( $badImages[$name][$contextKey] ); - - return $bad; + $services = MediaWikiServices::getInstance(); + if ( $blacklist !== null ) { + wfDeprecated( __METHOD__ . ' with $blacklist parameter', '1.34' ); + return ( new BadFileLookup( + function () use ( $blacklist ) { + return $blacklist; + }, + $services->getLocalServerObjectCache(), + $services->getRepoGroup(), + $services->getTitleParser() + ) )->isBadFile( $name, $contextTitle ?: null ); + } + return $services->getBadFileLookup()->isBadFile( $name, $contextTitle ?: null ); } /**