Merge "Export mw.Message's string formatter as mw.format"
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index a3f0a48..f516759 100644 (file)
@@ -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