X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FGlobalFunctions.php;h=cc998c722361bd734e74e16d244c57c0b1c7c9fe;hb=f05953f948dc0c707c988b99e82e9c9632294d6a;hp=5f17ad86276c4e1abdc3892ffc0dc43c9777fed2;hpb=316509d9083b4b86dea516b640a7e11dc3924b7c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 5f17ad8627..cc998c7223 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 @@ -2521,6 +2522,7 @@ function wfForeignMemcKey( $db, $prefix, ...$args ) { * @return string */ function wfGlobalCacheKey( ...$args ) { + wfDeprecated( __METHOD__, '1.30' ); return ObjectCache::getLocalClusterInstance()->makeGlobalKey( ...$args ); } @@ -2562,10 +2564,10 @@ function wfWikiID() { * @todo Replace calls to wfGetDB with calls to LoadBalancer::getConnection() * on an injected instance of LoadBalancer. * - * @return \Wikimedia\Rdbms\Database + * @return \Wikimedia\Rdbms\DBConnRef */ function wfGetDB( $db, $groups = [], $wiki = false ) { - return wfGetLB( $wiki )->getConnection( $db, $groups, $wiki ); + return wfGetLB( $wiki )->getMaintenanceConnectionRef( $db, $groups, $wiki ); } /** @@ -2756,30 +2758,27 @@ function wfStripIllegalFilenameChars( $name ) { } /** - * Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit + * Raise PHP's memory limit (if needed). * - * @return int Resulting value of the memory limit. + * @internal For use by Setup.php */ -function wfMemoryLimit() { - global $wgMemoryLimit; - $memlimit = wfShorthandToInteger( ini_get( 'memory_limit' ) ); - if ( $memlimit != -1 ) { - $conflimit = wfShorthandToInteger( $wgMemoryLimit ); - if ( $conflimit == -1 ) { +function wfMemoryLimit( $newLimit ) { + $oldLimit = wfShorthandToInteger( ini_get( 'memory_limit' ) ); + // If the INI config is already unlimited, there is nothing larger + if ( $oldLimit != -1 ) { + $newLimit = wfShorthandToInteger( $newLimit ); + if ( $newLimit == -1 ) { wfDebug( "Removing PHP's memory limit\n" ); Wikimedia\suppressWarnings(); - ini_set( 'memory_limit', $conflimit ); + ini_set( 'memory_limit', $newLimit ); Wikimedia\restoreWarnings(); - return $conflimit; - } elseif ( $conflimit > $memlimit ) { - wfDebug( "Raising PHP's memory limit to $conflimit bytes\n" ); + } elseif ( $newLimit > $oldLimit ) { + wfDebug( "Raising PHP's memory limit to $newLimit bytes\n" ); Wikimedia\suppressWarnings(); - ini_set( 'memory_limit', $conflimit ); + ini_set( 'memory_limit', $newLimit ); Wikimedia\restoreWarnings(); - return $conflimit; } } - return $memlimit; } /** @@ -2909,72 +2908,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 ); } /**