# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/lib/moodlelib.php
--- moodle/lib/moodlelib.php Base (1.1500)
+++ moodle/lib/moodlelib.php Locally Modified (Based On 1.1500)
@@ -9236,7 +9236,7 @@
  * @return array
  */
 function get_performance_info() {
-    global $CFG, $PERF, $DB;
+    global $CFG, $PERF, $DB, $PAGE;
 
     $info = array();
     $info['html'] = '';         // holds userfriendly HTML representation
@@ -9286,6 +9286,33 @@
         }
     }
 
+     $jsmodules = $PAGE->requires->get_loaded_modules();
+     if ($jsmodules) {
+         $yuicount = 0;
+         $othercount = 0;
+         $details = '';
+         foreach ($jsmodules as $module => $backtraces) {
+             if (strpos($module, 'yui') === 0) {
+                 $yuicount += 1;
+             } else {
+                 $othercount += 1;
+             }
+             $details .= "<div class='yui-module'><p>$module</p>";
+             foreach ($backtraces as $backtrace) {
+                 $details .= "<div class='backtrace'>$backtrace</div>";
+             }
+             $details .= '</div>';
+         }
+         $info['html'] .= "<span class='includedyuimodules'>Included YUI modules: $yuicount</span> ";
+         $info['txt'] .= "includedyuimodules: $yuicount ";
+         $info['html'] .= "<span class='includedjsmodules'>Other JavaScript modules: $othercount</span> ";
+         $info['txt'] .= "includedjsmodules: $othercount ";
+         // Slightly odd to output the details in a display: none div. The point
+         // Is that it takes a lot of space, and if you care you can reveal it
+         // using firebug.
+         $info['html'] .= '<div id="yui-module-debug" class="notifytiny">'.$details.'</div>';
+     }
+
     if (!empty($PERF->logwrites)) {
         $info['logwrites'] = $PERF->logwrites;
         $info['html'] .= '<span class="logwrites">Log DB writes '.$info['logwrites'].'</span> ';
Index: moodle/lib/outputrequirementslib.php
--- moodle/lib/outputrequirementslib.php Base (1.56)
+++ moodle/lib/outputrequirementslib.php Locally Modified (Based On 1.56)
@@ -109,6 +109,8 @@
     protected $M_yui_loader;
     /** some config vars exposed in JS, please no secret stuff there */
     protected $M_cfg;
+    /** stores debug backtraces from when JS modules were included in the page */
+    protected $debug_moduleloadstacktraces = array();
 
     /**
      * Page requirements constructor.
@@ -257,8 +259,14 @@
                 }
             }
             $this->M_yui_loader->modules[$name] = $module;
+            if (debugging('', DEBUG_DEVELOPER)) {
+                if (!array_key_exists($name, $this->debug_moduleloadstacktraces)) {
+                    $this->debug_moduleloadstacktraces[$name] = array();
         }
+                $this->debug_moduleloadstacktraces[$name][] = format_backtrace(debug_backtrace());
     }
+        }
+    }
 
     /**
      * Initialise with the bits of JavaScript that every Moodle page should have.
@@ -497,6 +505,14 @@
             throw new coding_exception('Missing YUI3 module details.');
         }
 
+        // Don't load this module if we already have, no need to!
+        if ($this->js_module_loaded($module['name'])) {
+            if (debugging('', DEBUG_DEVELOPER)) {
+                $this->debug_moduleloadstacktraces[$module['name']][] = format_backtrace(debug_backtrace());
+            }
+            return;
+        }
+
         $module['fullpath'] = $this->js_fix_url($module['fullpath'])->out(false);
         // add all needed strings
         if (!empty($module['strings'])) {
@@ -509,14 +525,55 @@
         }
         unset($module['strings']);
 
+        // Process module requirements and attempt to load each. This allows
+        // moodle modules to require each other.
+        if (!empty($module['requires'])){
+            foreach ($module['requires'] as $requirement) {
+                $rmodule = $this->find_module($requirement);
+                if (is_array($rmodule)) {
+                    $this->js_module($rmodule);
+                }
+            }
+        }
+        
         if ($this->headdone) {
             $this->extramodules[$module['name']] = $module;
         } else {
             $this->M_yui_loader->modules[$module['name']] = $module;
         }
+        if (debugging('', DEBUG_DEVELOPER)) {
+            if (!array_key_exists($module['name'], $this->debug_moduleloadstacktraces)) {
+                $this->debug_moduleloadstacktraces[$module['name']] = array();
     }
+            $this->debug_moduleloadstacktraces[$module['name']][] = format_backtrace(debug_backtrace());
+        }
+    }
 
     /**
+     * Returns true if the module has already been loaded.
+     *
+     * @param string|array $modulename
+     * @return bool True if the module has already been loaded
+     */
+    protected function js_module_loaded($module) {
+        if (is_string($module)) {
+            $modulename = $module;
+        } else {
+            $modulename = $module['name'];
+        }
+        return array_key_exists($modulename, $this->M_yui_loader->modules) ||
+               array_key_exists($modulename, $this->extramodules);
+    }
+
+    /**
+     * Returns the stacktraces from loading js modules.
+     * @return array
+     */
+    public function get_loaded_modules() {
+        return $this->debug_moduleloadstacktraces;
+    }
+
+    /**
      * Ensure that the specified CSS file is linked to from this page.
      *
      * Because stylesheet links must go in the <head> part of the HTML, you must call
Index: moodle/mod/quiz/locallib.php
--- moodle/mod/quiz/locallib.php Base (1.202)
+++ moodle/mod/quiz/locallib.php Locally Modified (Based On 1.202)
@@ -1247,7 +1247,6 @@
 
 function quiz_get_js_module() {
     global $PAGE;
-    $PAGE->requires->js_module('core_question_engine');
     return array(
         'name' => 'mod_quiz',
         'fullpath' => '/mod/quiz/module.js',
Index: moodle/theme/base/style/core.css
--- moodle/theme/base/style/core.css Base (1.73)
+++ moodle/theme/base/style/core.css Locally Modified (Based On 1.73)
@@ -128,6 +128,8 @@
 .arrow,
 .arrow_button input {font-family: Arial,Helvetica,Courier,sans-serif;}
 
+#yui-module-debug {display:none;}
+
 /**
  * Header
  */
