X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FGlobalFunctions.php;h=9518182d82efd1a287c809da33edbe23f52373fe;hb=5ad132533be45f999cec3ea52d959f3504fda83c;hp=1a901f39478a9b9f5c71db628b6ea018b0ab775f;hpb=795a29ce7700a1ad606d06537bd8f7e2e81652bd;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 1a901f3947..9518182d82 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -160,6 +160,80 @@ if ( !function_exists( 'hash_equals' ) ) { } /// @endcond +/** + * Load an extension + * + * This is the closest equivalent to: + * require_once "$IP/extensions/$name/$name.php"; + * as it will process and load the extension immediately. + * + * However, batch loading with wfLoadExtensions will + * be more performant. + * + * @param string $name Name of the extension to load + * @param string|null $path Absolute path of where to find the extension.json file + */ +function wfLoadExtension( $name, $path = null ) { + if ( !$path ) { + global $IP; + $path = "$IP/extensions/$name/extension.json"; + } + ExtensionRegistry::getInstance()->load( $path ); +} + +/** + * Load multiple extensions at once + * + * Same as wfLoadExtension, but more efficient if you + * are loading multiple extensions. + * + * If you want to specify custom paths, you should interact with + * ExtensionRegistry directly. + * + * @see wfLoadExtension + * @param string[] $exts Array of extension names to load + */ +function wfLoadExtensions( array $exts ) { + global $IP; + $registry = ExtensionRegistry::getInstance(); + foreach ( $exts as $ext ) { + $registry->queue( "$IP/extensions/$ext/extension.json" ); + } + + $registry->loadFromQueue(); +} + +/** + * Load a skin + * + * @see wfLoadExtension + * @param string $name Name of the extension to load + * @param string|null $path Absolute path of where to find the skin.json file + */ +function wfLoadSkin( $name, $path = null ) { + if ( !$path ) { + global $IP; + $path = "$IP/skins/$name/skin.json"; + } + ExtensionRegistry::getInstance()->load( $path ); +} + +/** + * Load multiple skins at once + * + * @see wfLoadExtensions + * @param string[] $skins Array of extension names to load + */ +function wfLoadSkins( array $skins ) { + global $IP; + $registry = ExtensionRegistry::getInstance(); + foreach ( $skins as $skin ) { + $registry->queue( "$IP/skins/$skin/skin.json" ); + } + + $registry->loadFromQueue(); +} + /** * Like array_diff( $a, $b ) except that it works with two-dimensional arrays. * @param array $a @@ -1067,21 +1141,25 @@ function wfDebugMem( $exact = false ) { } /** - * Send a line to a supplementary debug log file, if configured, or main debug log if not. - * To configure a supplementary log file, set $wgDebugLogGroups[$logGroup] to a string - * filename or an associative array mapping 'destination' to the desired filename. The - * associative array may also contain a 'sample' key with an integer value, specifying - * a sampling factor. + * Send a line to a supplementary debug log file, if configured, or main debug + * log if not. + * + * To configure a supplementary log file, set $wgDebugLogGroups[$logGroup] to + * a string filename or an associative array mapping 'destination' to the + * desired filename. The associative array may also contain a 'sample' key + * with an integer value, specifying a sampling factor. Sampled log events + * will be emitted with a 1 in N random chance. * * @since 1.23 support for sampling log messages via $wgDebugLogGroups. * @since 1.25 support for additional context data + * @since 1.25 sample behavior dependent on configured $wgMWLoggerDefaultSpi * * @param string $logGroup * @param string $text * @param string|bool $dest Destination of the message: * - 'all': both to the log and HTML (debug toolbar or HTML comments) * - 'log': only to the log and not in HTML - * - 'private': only to the specifc log if set in $wgDebugLogGroups and + * - 'private': only to the specific log if set in $wgDebugLogGroups and * discarded otherwise * For backward compatibility, it can also take a boolean: * - true: same as 'all' @@ -1106,7 +1184,7 @@ function wfDebugLog( $logger = MWLogger::getInstance( $logGroup ); $context['private'] = ( $dest === 'private' ); - $logger->debug( $text, $context ); + $logger->info( $text, $context ); } /** @@ -1177,8 +1255,10 @@ function wfLogWarning( $msg, $callerOffset = 1, $level = E_USER_WARNING ) { * @param string $file Filename * @param array $context Additional logging context data * @throws MWException + * @deprecated since 1.25 Use MWLoggerLegacyLogger::emit or UDPTransport */ function wfErrorLog( $text, $file, array $context = array() ) { + wfDeprecated( __METHOD__, '1.25' ); $logger = MWLogger::getInstance( 'wfErrorLog' ); $context['destination'] = $file; $logger->info( trim( $text ), $context ); @@ -1196,7 +1276,7 @@ function wfLogProfilingData() { $profiler = Profiler::instance(); # Profiling must actually be enabled... - if ( $profiler->isStub() ) { + if ( $profiler instanceof ProfilerStub ) { return; } @@ -1248,7 +1328,7 @@ function wfLogProfilingData() { // any knowledge about an URL and throw an exception instead. try { $ctx['url'] = urldecode( $wgRequest->getRequestURL() ); - } catch ( MWException $ignored ) { + } catch ( Exception $ignored ) { // no-op } @@ -1509,10 +1589,8 @@ function wfMsgForContentNoTrans( $key ) { function wfMsgReal( $key, $args, $useDB = true, $forContent = false, $transform = true ) { wfDeprecated( __METHOD__, '1.21' ); - wfProfileIn( __METHOD__ ); $message = wfMsgGetKey( $key, $useDB, $forContent, $transform ); $message = wfMsgReplaceArgs( $message, $args ); - wfProfileOut( __METHOD__ ); return $message; } @@ -1531,7 +1609,7 @@ function wfMsgReal( $key, $args, $useDB = true, $forContent = false, $transform function wfMsgGetKey( $key, $useDB = true, $langCode = false, $transform = true ) { wfDeprecated( __METHOD__, '1.21' ); - wfRunHooks( 'NormalizeMessageKey', array( &$key, &$useDB, &$langCode, &$transform ) ); + Hooks::run( 'NormalizeMessageKey', array( &$key, &$useDB, &$langCode, &$transform ) ); $cache = MessageCache::singleton(); $message = $cache->get( $key, $useDB, $langCode ); @@ -1837,7 +1915,7 @@ function wfBacktrace( $raw = null ) { $frames = array_map( function ( $frame ) use ( $frameFormat ) { $file = !empty( $frame['file'] ) ? basename( $frame['file'] ) : '-'; - $line = $frame['line'] ?: '-'; + $line = isset( $frame['line'] ) ? $frame['line'] : '-'; $call = $frame['function']; if ( !empty( $frame['class'] ) ) { $call = $frame['class'] . $frame['type'] . $call; @@ -2069,10 +2147,12 @@ function wfVarDump( $var ) { */ function wfHttpError( $code, $label, $desc ) { global $wgOut; - $wgOut->disable(); header( "HTTP/1.0 $code $label" ); header( "Status: $code $label" ); - $wgOut->sendCacheControl(); + if ( $wgOut ) { + $wgOut->disable(); + $wgOut->sendCacheControl(); + } header( 'Content-type: text/html; charset=utf-8' ); print "" . @@ -2964,7 +3044,7 @@ function wfShellWikiCmd( $script, array $parameters = array(), array $options = global $wgPhpCli; // Give site config file a chance to run the script in a wrapper. // The caller may likely want to call wfBasename() on $script. - wfRunHooks( 'wfShellWikiCmd', array( &$script, &$parameters, &$options ) ); + Hooks::run( 'wfShellWikiCmd', array( &$script, &$parameters, &$options ) ); $cmd = isset( $options['php'] ) ? array( $options['php'] ) : array( $wgPhpCli ); if ( isset( $options['wrapper'] ) ) { $cmd[] = $options['wrapper']; @@ -3416,7 +3496,7 @@ function wfResetSessionID() { $_SESSION = $tmp; } $newSessionId = session_id(); - wfRunHooks( 'ResetSessionID', array( $oldSessionId, $newSessionId ) ); + Hooks::run( 'ResetSessionID', array( $oldSessionId, $newSessionId ) ); } /** @@ -3551,7 +3631,7 @@ function wfSplitWikiID( $wiki ) { * * @return DatabaseBase */ -function &wfGetDB( $db, $groups = array(), $wiki = false ) { +function wfGetDB( $db, $groups = array(), $wiki = false ) { return wfGetLB( $wiki )->getConnection( $db, $groups, $wiki ); } @@ -3570,7 +3650,7 @@ function wfGetLB( $wiki = false ) { * * @return LBFactory */ -function &wfGetLBFactory() { +function wfGetLBFactory() { return LBFactory::singleton(); } @@ -3891,7 +3971,7 @@ function wfBCP47( $code ) { /** * Get a cache object. * - * @param int $inputType Cache type, one the the CACHE_* constants. + * @param int $inputType Cache type, one of the CACHE_* constants. * @return BagOStuff */ function wfGetCache( $inputType ) { @@ -3946,6 +4026,7 @@ function wfGetLangConverterCacheStorage() { * @param string|null $deprecatedVersion Optionally mark hook as deprecated with version number * * @return bool True if no handler aborted the hook + * @deprecated 1.25 */ function wfRunHooks( $event, array $args = array(), $deprecatedVersion = null ) { return Hooks::run( $event, $args, $deprecatedVersion ); @@ -4003,7 +4084,6 @@ function wfUnpack( $format, $data, $length = false ) { */ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) { static $badImageCache = null; // based on bad_image_list msg - wfProfileIn( __METHOD__ ); # Handle redirects $redirectTitle = RepoGroup::singleton()->checkRedirect( Title::makeTitle( NS_FILE, $name ) ); @@ -4013,8 +4093,7 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) { # Run the extension hook $bad = false; - if ( !wfRunHooks( 'BadImage', array( $name, &$bad ) ) ) { - wfProfileOut( __METHOD__ ); + if ( !Hooks::run( 'BadImage', array( $name, &$bad ) ) ) { return $bad; } @@ -4064,7 +4143,6 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) { $contextKey = $contextTitle ? $contextTitle->getPrefixedDBkey() : false; $bad = isset( $badImages[$name] ) && !isset( $badImages[$name][$contextKey] ); - wfProfileOut( __METHOD__ ); return $bad; } @@ -4077,7 +4155,7 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) { */ function wfCanIPUseHTTPS( $ip ) { $canDo = true; - wfRunHooks( 'CanIPUseHTTPS', array( $ip, &$canDo ) ); + Hooks::run( 'CanIPUseHTTPS', array( $ip, &$canDo ) ); return !!$canDo; }