resourceloader: Add support for delivering templates
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index 57deb00..eecb936 100644 (file)
@@ -974,12 +974,20 @@ class ResourceLoader {
                                        case 'messages':
                                                $out .= self::makeMessageSetScript( new XmlJsCode( $messagesBlob ) );
                                                break;
+                                       case 'templates':
+                                               $out .= Xml::encodeJsCall(
+                                                       'mw.templates.set',
+                                                       array( $name, (object)$module->getTemplates() ),
+                                                       ResourceLoader::inDebugMode()
+                                               );
+                                               break;
                                        default:
                                                $out .= self::makeLoaderImplementScript(
                                                        $name,
                                                        $scripts,
                                                        $styles,
-                                                       new XmlJsCode( $messagesBlob )
+                                                       new XmlJsCode( $messagesBlob ),
+                                                       $module->getTemplates()
                                                );
                                                break;
                                }
@@ -1044,15 +1052,20 @@ class ResourceLoader {
         * @param mixed $messages List of messages associated with this module. May either be an
         *   associative array mapping message key to value, or a JSON-encoded message blob containing
         *   the same data, wrapped in an XmlJsCode object.
+        * @param array $templates Keys are name of templates and values are the source of
+        *   the template.
         * @throws MWException
         * @return string
         */
-       public static function makeLoaderImplementScript( $name, $scripts, $styles, $messages ) {
+       public static function makeLoaderImplementScript( $name, $scripts, $styles,
+               $messages, $templates
+       ) {
                if ( is_string( $scripts ) ) {
                        $scripts = new XmlJsCode( "function ( $, jQuery ) {\n{$scripts}\n}" );
                } elseif ( !is_array( $scripts ) ) {
                        throw new MWException( 'Invalid scripts error. Array of URLs or string of code expected.' );
                }
+
                return Xml::encodeJsCall(
                        'mw.loader.implement',
                        array(
@@ -1064,7 +1077,8 @@ class ResourceLoader {
                                // PHP/json_encode() consider empty arrays to be numerical arrays and
                                // output javascript "[]" instead of "{}". This fixes that.
                                (object)$styles,
-                               (object)$messages
+                               (object)$messages,
+                               (object)$templates,
                        ),
                        ResourceLoader::inDebugMode()
                );