From 77c497a3e0bc93e1bd8bfd2c2845ce7917c26eff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= <commits@skodak.org>
Date: Sun, 13 Jan 2013 13:22:45 +0100
Subject: [PATCH] MDL-36198 make yuicssreset optional

---
 lib/outputlib.php             |  5 ++++-
 lib/outputrenderers.php       |  5 +++++
 lib/outputrequirementslib.php | 44 +++++++++++++++++++++++++++++++------------
 theme/upgrade.txt             |  5 +++++
 4 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/lib/outputlib.php b/lib/outputlib.php
index 53e9907..9c0b8da 100644
--- a/lib/outputlib.php
+++ b/lib/outputlib.php
@@ -315,6 +315,9 @@ class theme_config {
      */
     public $hidefromselector = false;
 
+    /** @var bool does the theme require YUI CSS reset? */
+    public $yuicssreset = true;
+
     /**
      * @var renderer_factory Instance of the renderer_factory implementation
      * we are using. Implementation detail.
@@ -407,7 +410,7 @@ class theme_config {
 
         $configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'javascripts', 'javascripts_footer',
                               'parents_exclude_javascripts', 'layouts', 'enable_dock', 'enablecourseajax', 'supportscssoptimisation',
-                              'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow', 'hidefromselector', 'doctype');
+                              'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow', 'hidefromselector', 'doctype', 'yuicssreset');
 
         foreach ($config as $key=>$value) {
             if (in_array($key, $configurable)) {
diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php
index 8e57f28..7468e34 100644
--- a/lib/outputrenderers.php
+++ b/lib/outputrenderers.php
@@ -400,6 +400,11 @@ class core_renderer extends renderer_base {
             $this->page->requires->js($jsurl);
         }
 
+        // Conditionally include YUI CSS reset.
+        if ($this->page->theme->yuicssreset) {
+            $output .= $this->page->requires->get_yui_cssreset_code();
+        }
+
         // Get any HTML from the page_requirements_manager.
         $output .= $this->page->requires->get_head_code($this->page, $this);
 
diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php
index d4eff1c..b7fb808 100644
--- a/lib/outputrequirementslib.php
+++ b/lib/outputrequirementslib.php
@@ -929,6 +929,36 @@ class page_requirements_manager {
     }
 
     /**
+     * Returns YUI css reset markup. Theme decides if it gets included on page or not.
+     *
+     * @return string
+     */
+    public function get_yui_cssreset_code() {
+        global $CFG;
+
+        $code = '';
+
+        if ($this->yui3loader->combine) {
+            $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->comboBase
+                    .$CFG->yui3version.'/build/cssreset/cssreset-min.css&amp;'
+                    .$CFG->yui3version.'/build/cssfonts/cssfonts-min.css&amp;'
+                    .$CFG->yui3version.'/build/cssgrids/cssgrids-min.css&amp;'
+                    .$CFG->yui3version.'/build/cssbase/cssbase-min.css" />';
+        } else {
+            $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.'cssreset/cssreset-min.css" />';
+            $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.'cssfonts/cssfonts-min.css" />';
+            $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.'cssgrids/cssgrids-min.css" />';
+            $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.'cssbase/cssbase-min.css" />';
+        }
+
+        if ($this->yui3loader->filter === 'RAW' or $this->yui3loader->filter === 'DEBUG') {
+            $code = str_replace('-min.css', '.css', $code);
+        }
+
+        return $code;
+    }
+
+    /**
      * Returns basic YUI3 JS loading code.
      * YUI3 is using autoloading of both CSS and JS code.
      *
@@ -943,29 +973,19 @@ class page_requirements_manager {
         $code = '';
 
         if ($this->yui3loader->combine) {
-            $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->comboBase
-                     .$CFG->yui3version.'/build/cssreset/reset-min.css&amp;'
-                     .$CFG->yui3version.'/build/cssfonts/fonts-min.css&amp;'
-                     .$CFG->yui3version.'/build/cssgrids/grids-min.css&amp;'
-                     .$CFG->yui3version.'/build/cssbase/base-min.css" />';
             $code .= '<script type="text/javascript" src="'.$this->yui3loader->comboBase
                      .$CFG->yui3version.'/build/simpleyui/simpleyui-min.js&amp;'
                      .$CFG->yui3version.'/build/loader/loader-min.js"></script>';
         } else {
-            $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.'cssreset/reset-min.css" />';
-            $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.'cssfonts/fonts-min.css" />';
-            $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.'cssgrids/grids-min.css" />';
-            $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.'cssbase/base-min.css" />';
             $code .= '<script type="text/javascript" src="'.$this->yui3loader->base.'simpleyui/simpleyui-min.js"></script>';
             $code .= '<script type="text/javascript" src="'.$this->yui3loader->base.'loader/loader-min.js"></script>';
         }
 
-
         if ($this->yui3loader->filter === 'RAW') {
-            $code = str_replace('-min.css', '.css', $code);
+            //$code = str_replace('-min.css', '.css', $code);
             $code = str_replace('-min.js', '.js', $code);
         } else if ($this->yui3loader->filter === 'DEBUG') {
-            $code = str_replace('-min.css', '.css', $code);
+            //$code = str_replace('-min.css', '.css', $code);
             $code = str_replace('-min.js', '-debug.js', $code);
         }
 
diff --git a/theme/upgrade.txt b/theme/upgrade.txt
index a869d16..109e8cb 100644
--- a/theme/upgrade.txt
+++ b/theme/upgrade.txt
@@ -1,6 +1,11 @@
 This files describes API changes in /theme/* themes,
 information provided here is intended especially for theme designer.
 
+=== 2.5 ===
+
+new features:
+* new setting $THEME->yuicssreset = false; that prevents loading of YUI reset and grids CSS
+
 === 2.4 ===
 
 required changes:
-- 
1.7.11.1

