From c724f835ca0ea1d00fd396356d1821c2798c11d8 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Tue, 5 Jan 2010 17:29:43 +0000 Subject: [PATCH] MDL-21242 moving yui2 skin away from theme CSS, this improves browser caching and finally we may load skin from the internet too --- lib/ajax/ajaxlib.php | 22 ++++++++++++++++++++-- lib/outputlib.php | 21 +++++---------------- theme/styles.php | 3 +-- theme/styles_debug.php | 5 +---- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index f71682f8ea..94ac28fc90 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -118,7 +118,7 @@ class page_requirements_manager { * @param moodle_page $page * @param core_renderer $output */ - function setup_core_javascript(moodle_page $page, core_renderer $output) { + protected function setup_core_javascript(moodle_page $page, core_renderer $output) { global $CFG; // JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot. @@ -498,6 +498,9 @@ class page_requirements_manager { * Returns basic YUI3 JS loading code. * YUI3 is using autoloading of both CSS and JS code. * + * Major benefit of this compared to standard js/csss loader is much improved + * caching, better browser cache utilisation, much fewer http requests. + * * @return string */ protected function get_yui3lib_headcode() { @@ -511,15 +514,30 @@ class page_requirements_manager { /** * Returns basic YUI2 JS loading code. * It can be called manually at any time. + * If called manually the result needs to be output using echo(). + * + * Major benefit of this compared to standard js loader is much improved + * caching, better browser cache utilisation, much fewer http requests. + * + * All YUI2 CSS is loaded automatically. * * @return string JS embedding code */ public function get_yui2lib_code() { - // All YUI2 CSS is loaded automatically + global $CFG; + if ($this->headdone) { $code = $this->yui2loader->script_embed(); } else { $code = $this->yui2loader->script(); + if ($this->yui2loader->combine) { + $skinurl = $this->yui2loader->comboBase . $CFG->yui2version . '/build/assets/skins/sam/skin.css'; + } else { + $skinurl = $this->yui2loader->base . 'assets/skins/sam/skin.css'; + } + // please note this is a temporary hack until we fully migrate to later YUI3 that has all the widgets + // we can not use moodle_url because the url fomrat for combo loader is "a bit" non-standard + $code .= "\n".''."\n"; } $code = str_replace('&', '&', $code); $code = str_replace('&', '&', $code); diff --git a/lib/outputlib.php b/lib/outputlib.php index 8b58ee610c..3bc688cbe9 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -580,7 +580,6 @@ class theme_config { $rev = theme_get_revision(); $urls = array(); - //TODO: MDL-21242 add here link to full YUI2 skin.css - get the url from the $page->requires instance if ($rev > -1) { $params = array('theme'=>$this->name,'rev'=>$rev); @@ -616,19 +615,17 @@ class theme_config { file_put_contents($candidatesheet, serialize($css)); } - $url = $CFG->httpswwwroot.'/theme/styles_debug.php'; - $urls = array(); - $urls[] = new moodle_url($url, array('theme'=>$this->name,'type'=>'yui2')); + $baseurl = $CFG->httpswwwroot.'/theme/styles_debug.php'; foreach ($css['plugins'] as $plugin=>$unused) { - $urls[] = new moodle_url($url, array('theme'=>$this->name,'type'=>'plugin', 'subtype'=>$plugin)); + $urls[] = new moodle_url($baseurl, array('theme'=>$this->name,'type'=>'plugin', 'subtype'=>$plugin)); } foreach ($css['parents'] as $parent=>$sheets) { foreach ($sheets as $sheet=>$unused2) { - $urls[] = new moodle_url($url, array('theme'=>$this->name,'type'=>'parent', 'subtype'=>$parent, 'sheet'=>$sheet)); + $urls[] = new moodle_url($$baseurl, array('theme'=>$this->name,'type'=>'parent', 'subtype'=>$parent, 'sheet'=>$sheet)); } } foreach ($css['theme'] as $sheet=>$unused) { - $urls[] = new moodle_url($url, array('sheet'=>$sheet, 'theme'=>$this->name, 'type'=>'theme')); // sheet first in order to make long urls easier to read + $urls[] = new moodle_url($baseurl, array('sheet'=>$sheet, 'theme'=>$this->name, 'type'=>'theme')); // sheet first in order to make long urls easier to read } } @@ -642,15 +639,7 @@ class theme_config { public function css_content() { global $CFG; - $css = array('yui2'=>array(), 'plugins'=>array(), 'parents'=>array(), 'theme'=>array()); - - // legacy YUI2 stylesheets, YUI3 stylesheets are loaded on the fly - $yui2_sheets = "\n\n/*** Standard YUI2 sheets ***/\n\n"; - $yui2_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui2version/build/assets/skins/sam/skin.css"); - //TODO: MDL-21242 move this YUI2 CSS hack to css_urls(), the page requirements manager should return the correct yui_combo.php?2.x.x/build/skinks/sam/skin.css - - // search for all images in yui2 CSS and serve them through the yui_image.php script - $css['yui2'][] = preg_replace('/([a-z-]+)\.(png|gif)/', 'yui_image.php?file='.$CFG->yui2version.'/$1.$2', $yui2_sheets); + $css = array('plugins'=>array(), 'parents'=>array(), 'theme'=>array()); // get all plugin sheets $excludes = null; diff --git a/theme/styles.php b/theme/styles.php index c4ea5204bd..969700e9b3 100644 --- a/theme/styles.php +++ b/theme/styles.php @@ -32,7 +32,7 @@ $themename = min_optional_param('theme', 'standard', 'SAFEDIR'); $type = min_optional_param('type', 'all', 'SAFEDIR'); $rev = min_optional_param('rev', 0, 'INT'); -if (!in_array($type, array('all', 'ie', 'editor', 'yui2', 'plugins', 'parents', 'theme'))) { +if (!in_array($type, array('all', 'ie', 'editor', 'plugins', 'parents', 'theme'))) { header('HTTP/1.0 404 not found'); die('Theme was not found, sorry.'); } @@ -116,7 +116,6 @@ function send_ie_css($themename, $rev) { $css = <<