# 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/ajax/ajaxlib.php
--- moodle/lib/ajax/ajaxlib.php Base (1.78)
+++ moodle/lib/ajax/ajaxlib.php Locally Modified (Based On 1.78)
@@ -694,7 +694,7 @@
  * are indented to be used as a fluid API, so you can say things like
  *     $PAGE->requires->yui_lib('autocomplete')->in_head();
  *
- * This class (with the help of {@link ajax_resolve_yui_lib()}) knows about the
+ * This class (with the help of {@link yui_translation::libraries}) knows about the
  * dependancies between the different YUI libraries, and will include all the
  * other libraries required by the one you ask for. It also knows which YUI
  * libraries require css files. If the library you ask for requires CSS files,
@@ -720,22 +720,17 @@
      *
      * @param page_requirements_manager $manager the page_requirements_manager we are associated with.
      * @param string $libname The name of the YUI library you want. See the array
-     * defined in {@link ajax_resolve_yui_lib()} for a list of known libraries.
+     * {@link yui_translation::libraries} for a list of known libraries.
      */
     public function __construct(page_requirements_manager $manager, $libname) {
         parent::__construct($manager, '');
         $this->when = page_requirements_manager::WHEN_AT_END;
 
-        list($jsurls, $cssurls) = ajax_resolve_yui_lib($libname);
+        $jsurls = yui_translation::resolve_js_requirments($libname);
         foreach ($jsurls as $jsurl) {
             $this->jss[] = $manager->js($jsurl, true);
         }
-        foreach ($cssurls as $cssurl) {
-            // this might be a bit problematic because it requires yui to be
-            // requested before print_header() - this was not required in 1.9.x
-            $manager->css($cssurl, true);
         }
-    }
 
     public function get_html() {
         // Since we create a required_js for each of our files, that will generate the HTML.
@@ -1148,29 +1143,20 @@
     }
 }
 
-
 /**
- * Given the name of a YUI library, return a list of the .js and .css files that
- * it requries.
+ * This class provides a set of static methods that can be used to resolve YUI
+ * lib JS and CSS dependancies.
  *
- * This method takes note of the $CFG->useexternalyui setting.
- *
- * If $CFG->debug is set to DEBUG_DEVELOPER then this method will return links to
- * the -debug version of the YUI files, otherwise it will return links to the -min versions.
- *
- * @param string $libname the name of a YUI library, for example 'autocomplete'.
- * @return array with two elementes. The first is an array of the JavaScript URLs
- *      that must be loaded to make this library work, in the order they should be
- *      loaded. The second element is a (possibly empty) list of CSS files that
- *      need to be loaded.
+ * @copyright 2009 Sam Hemelryk
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
  */
-function ajax_resolve_yui_lib($libname) {
-    global $CFG;
-
-    // Note, we always use yahoo-dom-event, even if we are only asked for part of it.
-    // because another part of the code may later ask for other bits. It is easier, and
-    // not very inefficient, just to always use (and get browsers to cache) the combined file.
-    static $translatelist = array(
+class yui_translation {
+    /**
+     * An array of YUI library dependencies
+     * @var array
+     */
+    public static $libraries = array(
         'yahoo' => 'yahoo-dom-event',
         'animation' => array('yahoo-dom-event', 'animation'),
         'autocomplete' => array(
@@ -1249,22 +1235,36 @@
                 'js' => array('yahoo-dom-event', 'logger', 'yuitest'),
                 'css' => array('logger/assets/logger.css', 'yuitest/assets/testlogger.css')),
     );
-    if (!isset($translatelist[$libname])) {
+    /**
+     * Given the name of a YUI library, return a list of .js files that
+     * it requries.
+     *
+     * This method takes note of the $CFG->useexternalyui setting.
+     *
+     * If $CFG->debug is set to DEBUG_DEVELOPER then this method will return links to
+     * the -debug version of the YUI files, otherwise it will return links to the -min versions.
+     *
+     * @param string $libname the name of a YUI library, for example 'autocomplete'.
+     * @return array (possibly empty) list of JS files that
+     *      need to be loaded.
+     */
+    public static function resolve_js_requirments($libname) {
+        global $CFG;
+
+        // Note, we always use yahoo-dom-event, even if we are only asked for part of it.
+        // because another part of the code may later ask for other bits. It is easier, and
+        // not very inefficient, just to always use (and get browsers to cache) the combined file.
+        if (!isset(self::$libraries[$libname])) {
         throw new coding_exception('Unknown YUI library ' . $libname);
     }
-
-    $data = $translatelist[$libname];
+        $data = self::$libraries[$libname];
     if (!is_array($data)) {
         $jsnames = array($data);
-        $cssfiles = array();
     } else if (isset($data['js']) && isset($data['css'])) {
         $jsnames = $data['js'];
-        $cssfiles = $data['css'];
     } else {
         $jsnames = $data;
-        $cssfiles = array();
     }
-
     $debugging = debugging('', DEBUG_DEVELOPER);
     if ($debugging) {
         $suffix = '-debug.js';
@@ -1272,13 +1272,11 @@
         $suffix = '-min.js';
     }
     $libpath = $CFG->httpswwwroot . '/lib/yui/';
-
     $externalyui = !empty($CFG->useexternalyui);
     if ($externalyui) {
         include($CFG->libdir.'/yui/version.php'); // Sets $yuiversion.
         $libpath = 'http://yui.yahooapis.com/' . $yuiversion . '/build/';
     }
-
     $jsurls = array();
     foreach ($jsnames as $js) {
         if ($js == 'yahoo-dom-event') {
@@ -1293,14 +1291,83 @@
             $jsurls[] = $libpath . $js . '/' . $js . $suffix;
         }
     }
+        return $jsurls;
+    }
+    /**
+     * Given the name of a YUI library, return a list of .css files that
+     * it requries.
+     *
+     * This method takes note of the $CFG->useexternalyui setting.
+     *
+     * If $CFG->debug is set to DEBUG_DEVELOPER then this method will return links to
+     * the -debug version of the YUI files, otherwise it will return links to the -min versions.
+     *
+     * @param string $libname the name of a YUI library, for example 'autocomplete'.
+     * @return array (possibly empty) list of CSS files that
+     *      need to be loaded.
+     */
+    public static function resolve_css_requirements($libname) {
+        global $CFG;
 
+        // Note, we always use yahoo-dom-event, even if we are only asked for part of it.
+        // because another part of the code may later ask for other bits. It is easier, and
+        // not very inefficient, just to always use (and get browsers to cache) the combined file.
+
+        if (!isset(yui_translation::$libraries[$libname])) {
+            throw new coding_exception('Unknown YUI library ' . $libname);
+        }
+
+        $data = yui_translation::$libraries[$libname];
+        if (!is_array($data)) {
+            $cssfiles = array();
+        } else if (isset($data['js']) && isset($data['css'])) {
+            $cssfiles = $data['css'];
+        } else {
+            $cssfiles = array();
+        }
+
+        $debugging = debugging('', DEBUG_DEVELOPER);
+        if ($debugging) {
+            $suffix = '-debug.js';
+        } else {
+            $suffix = '-min.js';
+        }
+        $libpath = $CFG->httpswwwroot . '/lib/yui/';
+
+        $externalyui = !empty($CFG->useexternalyui);
+        if ($externalyui) {
+            include($CFG->libdir.'/yui/version.php'); // Sets $yuiversion.
+            $libpath = 'http://yui.yahooapis.com/' . $yuiversion . '/build/';
+        }
     $cssurls = array();
     foreach ($cssfiles as $css) {
         $cssurls[] = $libpath . $css;
     }
-
-    return array($jsurls, $cssurls);
+        return $cssurls;
 }
+    /**
+     * Returns an array of all CSS files for all YUI lib's
+     * 
+     * @return array
+     */
+    public static function all_required_css() {
+        $cssfiles = Array();
+        $libpath = $CFG->httpswwwroot . '/lib/yui/';
+        $externalyui = !empty($CFG->useexternalyui);
+        if ($externalyui) {
+            include($CFG->libdir.'/yui/version.php'); // Sets $yuiversion.
+            $libpath = 'http://yui.yahooapis.com/' . $yuiversion . '/build/';
+        }
+        foreach (self::$libraries as $library) {
+            if (is_array($library) && array_key_exists('css', $library) && is_array($library['css'])) {
+                foreach ($library['css'] as $cssfile) {
+                    $cssfiles[] = $libpath.$cssfile;
+                }
+            }
+        }
+        return $cssfiles;
+    }
+}
 
 /**
  * Return the HTML required to link to a JavaScript file.
@@ -1443,5 +1510,3 @@
     }
 
 }
-
-?>
Index: moodle/theme/standard/config.php
--- moodle/theme/standard/config.php Base (1.32)
+++ moodle/theme/standard/config.php Locally Modified (Based On 1.32)
@@ -38,6 +38,12 @@
 $THEME->standardsheets = true;
 $THEME->pluginsheets = array('mod', 'block', 'format', 'gradereport');
 
+// yuisheets controls which YUI CSS sheets get included with this page. By default
+// (if not set for example) all CSS for all YUI lib's will be loaded to ensure
+// everything is available and overridable. Setting this to true is the same as not
+// setting it, it can also be an array of lib's to load CSS for if the list is known
+$THEME->yuisheets = true;
+
 $THEME->metainclude = false;
 $THEME->parentmetainclude = false;
 $THEME->standardmetainclude = true;
Index: moodle/theme/styles.php
--- moodle/theme/styles.php Base (1.4)
+++ moodle/theme/styles.php Locally Modified (Based On 1.4)
@@ -120,6 +120,17 @@
     }
 }
 
+// Prepare to load the YUI css stylesheets, by default we will load ALL possible
+// CSS for every YUI lib we know about, see MDL-19935 for reasons why
+// We will look at $THEME->yuisheets which can be true|false|array or libs
+if (empty($THEME->yuisheets) || $THEME->yuisheets===true) {
+    $files = array_merge($files, yui_translation::all_required_css());
+} else if (!empty($THEME->yuisheets) && is_array($THEME->yuisheets)) {
+    foreach ($THEME->yuisheets as $yuilib) {
+        $files = array_merge($files, yui_translation::resolve_css_requirements($yuilib));
+    }
+}
+
 // Now work out which stylesheets we shold be serving from this theme.
 if ($themename == $fortheme) {
     $themesheets = $THEME->sheets;
