}
/// @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
$context['prefix'] = $wgDebugLogPrefix;
}
- $logger = MWLogger::getInstance( 'wfDebug' );
+ $logger = MWLoggerFactory::getInstance( 'wfDebug' );
$logger->debug( $text, $context );
}
MWDebug::debugMsg( "[{$logGroup}] {$text}\n" );
}
- $logger = MWLogger::getInstance( $logGroup );
+ $logger = MWLoggerFactory::getInstance( $logGroup );
$context['private'] = ( $dest === 'private' );
$logger->info( $text, $context );
}
* @param array $context Additional logging context data
*/
function wfLogDBError( $text, array $context = array() ) {
- $logger = MWLogger::getInstance( 'wfLogDBError' );
+ $logger = MWLoggerFactory::getInstance( 'wfLogDBError' );
$logger->error( trim( $text ), $context );
}
*/
function wfErrorLog( $text, $file, array $context = array() ) {
wfDeprecated( __METHOD__, '1.25' );
- $logger = MWLogger::getInstance( 'wfErrorLog' );
+ $logger = MWLoggerFactory::getInstance( 'wfErrorLog' );
$context['destination'] = $file;
$logger->info( trim( $text ), $context );
}
// any knowledge about an URL and throw an exception instead.
try {
$ctx['url'] = urldecode( $wgRequest->getRequestURL() );
- } catch ( MWException $ignored ) {
+ } catch ( Exception $ignored ) {
// no-op
}
$ctx['output'] = $profiler->getOutput();
- $log = MWLogger::getInstance( 'profileoutput' );
+ $log = MWLoggerFactory::getInstance( 'profileoutput' );
$log->info( "Elapsed: {elapsed}; URL: <{url}>\n{output}", $ctx );
}
*/
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 "<!doctype html>" .
* @param string|null $deprecatedVersion Optionally mark hook as deprecated with version number
*
* @return bool True if no handler aborted the hook
- * @deprecated 1.25
+ * @deprecated 1.25 - use Hooks::run
*/
function wfRunHooks( $event, array $args = array(), $deprecatedVersion = null ) {
return Hooks::run( $event, $args, $deprecatedVersion );
wfDeprecated( __METHOD__, '1.24' );
return IP::isConfiguredProxy( $ip );
}
+
+/**
+ * Returns true if these thumbnail parameters match one that MediaWiki
+ * requests from file description pages and/or parser output.
+ *
+ * $params is considered non-standard if they involve a non-standard
+ * width or any non-default parameters aside from width and page number.
+ * The number of possible files with standard parameters is far less than
+ * that of all combinations; rate-limiting for them can thus be more generious.
+ *
+ * @param File $file
+ * @param array $params
+ * @return bool
+ * @since 1.24 Moved from thumb.php to GlobalFunctions in 1.25
+ */
+function wfThumbIsStandard( File $file, array $params ) {
+ global $wgThumbLimits, $wgImageLimits, $wgResponsiveImages;
+
+ $multipliers = array( 1 );
+ if ( $wgResponsiveImages ) {
+ // These available sizes are hardcoded currently elsewhere in MediaWiki.
+ // @see Linker::processResponsiveImages
+ $multipliers[] = 1.5;
+ $multipliers[] = 2;
+ }
+
+ $handler = $file->getHandler();
+ if ( !$handler || !isset( $params['width'] ) ) {
+ return false;
+ }
+
+ $basicParams = array();
+ if ( isset( $params['page'] ) ) {
+ $basicParams['page'] = $params['page'];
+ }
+
+ $thumbLimits = array();
+ $imageLimits = array();
+ // Expand limits to account for multipliers
+ foreach ( $multipliers as $multiplier ) {
+ $thumbLimits = array_merge( $thumbLimits, array_map(
+ function ( $width ) use ( $multiplier ) {
+ return round( $width * $multiplier );
+ }, $wgThumbLimits )
+ );
+ $imageLimits = array_merge( $imageLimits, array_map(
+ function ( $pair ) use ( $multiplier ) {
+ return array(
+ round( $pair[0] * $multiplier ),
+ round( $pair[1] * $multiplier ),
+ );
+ }, $wgImageLimits )
+ );
+ }
+
+ // Check if the width matches one of $wgThumbLimits
+ if ( in_array( $params['width'], $thumbLimits ) ) {
+ $normalParams = $basicParams + array( 'width' => $params['width'] );
+ // Append any default values to the map (e.g. "lossy", "lossless", ...)
+ $handler->normaliseParams( $file, $normalParams );
+ } else {
+ // If not, then check if the width matchs one of $wgImageLimits
+ $match = false;
+ foreach ( $imageLimits as $pair ) {
+ $normalParams = $basicParams + array( 'width' => $pair[0], 'height' => $pair[1] );
+ // Decide whether the thumbnail should be scaled on width or height.
+ // Also append any default values to the map (e.g. "lossy", "lossless", ...)
+ $handler->normaliseParams( $file, $normalParams );
+ // Check if this standard thumbnail size maps to the given width
+ if ( $normalParams['width'] == $params['width'] ) {
+ $match = true;
+ break;
+ }
+ }
+ if ( !$match ) {
+ return false; // not standard for description pages
+ }
+ }
+
+ // Check that the given values for non-page, non-width, params are just defaults
+ foreach ( $params as $key => $value ) {
+ if ( !isset( $normalParams[$key] ) || $normalParams[$key] != $value ) {
+ return false;
+ }
+ }
+
+ return true;
+}