From 6c47a78cc56b2c460658675c694bd178c31a1830 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Mon, 9 Apr 2012 14:15:29 +0100 Subject: load only one stylesheet for all modes instead of three Instead of three stylesheets for 'all', 'screen' and 'print' modes, they are all loaded into a single stylesheet by wrapping all screen styles in a "@media screen {}" and all print styles in a "@media print {}". The 'all' mode is not wrapped in anything. Potential issues with existing CSS: If any of your screen or print CSS files already contain any "@media" syntax, the CSS will probably break. In that case please add any CSS with "@media" in it to the 'all' mode instead! Also, the 'rtl' mode is hereby deprecated. Please just prefix any RTL styles within your normal CSS files with "[dir=rtl]". This also fixes that RTL styles cannot be added for 'all' or 'print' modes. --- lib/exe/css.php | 125 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 76 insertions(+), 49 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index 69b512205..5468376c6 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -9,6 +9,7 @@ if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching) if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT',1); // we gzip ourself here +if(!defined('NL')) define('NL',"\n"); require_once(DOKU_INC.'inc/init.php'); // Main (don't run when UNIT test) @@ -30,10 +31,12 @@ function css_out(){ global $lang; global $config_cascade; - $mediatype = 'screen'; - if (isset($_REQUEST['s']) && - in_array($_REQUEST['s'], array('all', 'print', 'feed'))) { - $mediatype = $_REQUEST['s']; + if (isset($_REQUEST['s']) && ($_REQUEST['s'] == 'feed')) { + $mediatypes = array('feed'); + $type = 'feed'; + } else { + $mediatypes = array('screen', 'all', 'print'); + $type = ''; } $tpl = trim(preg_replace('/[^\w-]+/','',$_REQUEST['t'])); @@ -46,7 +49,7 @@ function css_out(){ } // The generated script depends on some dynamic options - $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$mediatype,'.css'); + $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$type,'.css'); // load template styles $tplstyles = array(); @@ -57,57 +60,79 @@ function css_out(){ } } - // Array of needed files and their web locations, the latter ones - // are needed to fix relative paths in the stylesheets - $files = array(); - // load core styles - $files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; - // load jQuery-UI theme - $files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; - // load plugin styles - $files = array_merge($files, css_pluginstyles($mediatype)); - // load template styles - if (isset($tplstyles[$mediatype])) { - $files = array_merge($files, $tplstyles[$mediatype]); - } - // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility - if (isset($config_cascade['userstyle']['default'])) { - $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default']; - } - // load user styles - if(isset($config_cascade['userstyle'][$mediatype])){ - $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; - } - // load rtl styles - // @todo: this currently adds the rtl styles only to the 'screen' media type - // but 'print' and 'all' should also be supported - if ($mediatype=='screen') { - if($lang['direction'] == 'rtl'){ - if (isset($tplstyles['rtl'])) $files = array_merge($files, $tplstyles['rtl']); + // start output buffering + ob_start(); + + foreach($mediatypes as $mediatype) { + // Array of needed files and their web locations, the latter ones + // are needed to fix relative paths in the stylesheets + $files = array(); + // load core styles + $files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; + // load jQuery-UI theme + if ($mediatype == 'screen') { + //$files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; + } + // load plugin styles + $files = array_merge($files, css_pluginstyles($mediatype)); + // load template styles + if (isset($tplstyles[$mediatype])) { + $files = array_merge($files, $tplstyles[$mediatype]); + } + // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility + if (isset($config_cascade['userstyle']['default'])) { + $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default']; + } + // load user styles + if(isset($config_cascade['userstyle'][$mediatype])){ + $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; + } + // load rtl styles + // note: this adds the rtl styles only to the 'screen' media type + // @deprecated 2012-04-09: rtl will cease to be a mode of its own, + // please use "[dir=rtl]" in any css file in all, screen or print mode instead + if ($mediatype=='screen') { + if($lang['direction'] == 'rtl'){ + if (isset($tplstyles['rtl'])) $files = array_merge($files, $tplstyles['rtl']); + } } - } - $cache_files = array_merge(array_keys($files), getConfigFiles('main')); - $cache_files[] = $tplinc.'style.ini'; - $cache_files[] = __FILE__; + $cache_files = array_merge(array_keys($files), getConfigFiles('main')); + $cache_files[] = $tplinc.'style.ini'; + $cache_files[] = __FILE__; - // check cache age & handle conditional request - // This may exit if a cache can be used - http_cached($cache->cache, - $cache->useCache(array('files' => $cache_files))); + // check cache age & handle conditional request + // This may exit if a cache can be used + http_cached($cache->cache, + $cache->useCache(array('files' => $cache_files))); - // start output buffering and build the stylesheet - ob_start(); + // build the stylesheet - // print the default classes for interwiki links and file downloads - css_interwiki(); - css_filetypes(); + // print the default classes for interwiki links and file downloads + if ($mediatype == 'screen') { + css_interwiki(); + css_filetypes(); + } - // load files - foreach($files as $file => $location){ - print css_loadfile($file, $location); + // load files + $css_content = ''; + foreach($files as $file => $location){ + $css_content .= css_loadfile($file, $location); + } + switch ($mediatype) { + case 'screen': + print NL.'@media screen { /* START screen styles */'.NL.$css_content.NL.'} /* /@media END screen styles */'.NL; + break; + case 'print': + print NL.'@media print { /* START print styles */'.NL.$css_content.NL.'} /* /@media END print styles */'.NL; + break; + case 'all': + case 'feed': + default: + print NL.'/* START rest styles */ '.NL.$css_content.NL.'/* END rest styles */'.NL; + break; + } } - // end output buffering and get contents $css = ob_get_contents(); ob_end_clean(); @@ -275,6 +300,8 @@ function css_pluginstyles($mediatype='screen'){ if ($mediatype=='screen') { $list[DOKU_PLUGIN."$p/style.css"] = DOKU_BASE."lib/plugins/$p/"; } + // @deprecated 2012-04-09: rtl will cease to be a mode of its own, + // please use "[dir=rtl]" in any css file in all, screen or print mode instead if($lang['direction'] == 'rtl'){ $list[DOKU_PLUGIN."$p/rtl.css"] = DOKU_BASE."lib/plugins/$p/"; } -- cgit v1.2.3 From 3d2fd76a6a87ddf4a45c05091799c09500265307 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Mon, 9 Apr 2012 19:08:20 +0100 Subject: added accidentally removed jquery-ui styles back again --- lib/exe/css.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index 5468376c6..1b2b0c86b 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -71,7 +71,7 @@ function css_out(){ $files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; // load jQuery-UI theme if ($mediatype == 'screen') { - //$files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; + $files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; } // load plugin styles $files = array_merge($files, css_pluginstyles($mediatype)); -- cgit v1.2.3 From bfd0f5975e6e3578b4fa0c712e9779a0861fdc72 Mon Sep 17 00:00:00 2001 From: Tom N Harris Date: Thu, 28 Jun 2012 22:04:10 -0400 Subject: Input wrapper for exe scripts --- lib/exe/css.php | 8 ++++---- lib/exe/detail.php | 4 ++-- lib/exe/fetch.php | 8 ++++---- lib/exe/indexer.php | 7 ++++--- 4 files changed, 14 insertions(+), 13 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index 69b512205..5cc4ab830 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -29,14 +29,14 @@ function css_out(){ global $conf; global $lang; global $config_cascade; + global $INPUT; $mediatype = 'screen'; - if (isset($_REQUEST['s']) && - in_array($_REQUEST['s'], array('all', 'print', 'feed'))) { - $mediatype = $_REQUEST['s']; + if (in_array($INPUT->str('s'), array('all', 'print', 'feed'))) { + $mediatype = $INPUT->str('s'); } - $tpl = trim(preg_replace('/[^\w-]+/','',$_REQUEST['t'])); + $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t'))); if($tpl){ $tplinc = DOKU_INC.'lib/tpl/'.$tpl.'/'; $tpldir = DOKU_BASE.'lib/tpl/'.$tpl.'/'; diff --git a/lib/exe/detail.php b/lib/exe/detail.php index 35186f5dd..ea46bc037 100644 --- a/lib/exe/detail.php +++ b/lib/exe/detail.php @@ -6,9 +6,9 @@ require_once(DOKU_INC.'inc/init.php'); session_write_close(); $IMG = getID('media'); -$ID = cleanID($_REQUEST['id']); +$ID = cleanID($INPUT->str('id')); -if($conf['allowdebug'] && $_REQUEST['debug']){ +if($conf['allowdebug'] && $INPUT->has('debug')){ print '
';
     foreach(explode(' ','basedir userewrite baseurl useslash') as $x){
         print '$'."conf['$x'] = '".$conf[$x]."';\n";
diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php
index 143d40f22..60843460e 100644
--- a/lib/exe/fetch.php
+++ b/lib/exe/fetch.php
@@ -17,10 +17,10 @@
 
   //get input
   $MEDIA  = stripctl(getID('media',false)); // no cleaning except control chars - maybe external
-  $CACHE  = calc_cache($_REQUEST['cache']);
-  $WIDTH  = (int) $_REQUEST['w'];
-  $HEIGHT = (int) $_REQUEST['h'];
-  $REV   = (int) @$_REQUEST['rev'];
+  $CACHE  = calc_cache($INPUT->str('cache'));
+  $WIDTH  = $INPUT->int('w');
+  $HEIGHT = $INPUT->int('h');
+  $REV    = &$INPUT->ref('rev');
   //sanitize revision
   $REV = preg_replace('/[^0-9]/','',$REV);
 
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php
index 738a29503..e149770c0 100644
--- a/lib/exe/indexer.php
+++ b/lib/exe/indexer.php
@@ -20,10 +20,10 @@ if(!$defer){
     sendGIF(); // send gif
 }
 
-$ID = cleanID($_REQUEST['id']);
+$ID = cleanID($INPUT->str('id'));
 
 // Catch any possible output (e.g. errors)
-$output = isset($_REQUEST['debug']) && $conf['allowdebug'];
+$output = $INPUT->has('debug') && $conf['allowdebug'];
 if(!$output) ob_start();
 
 // run one of the jobs
@@ -261,7 +261,8 @@ function sendDigest() {
  * @author Harry Fuecks 
  */
 function sendGIF(){
-    if(isset($_REQUEST['debug'])){
+    global $INPUT;
+    if($INPUT->has('debug')){
         header('Content-Type: text/plain');
         return;
     }
-- 
cgit v1.2.3


From 8108113c244529ec54f11271a6a15e3d1e0a048f Mon Sep 17 00:00:00 2001
From: Tom N Harris 
Date: Thu, 28 Jun 2012 22:15:56 -0400
Subject: Input validation for media manager

---
 lib/exe/mediamanager.php | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

(limited to 'lib/exe')

diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php
index 5f09fe1f8..83166a2f4 100644
--- a/lib/exe/mediamanager.php
+++ b/lib/exe/mediamanager.php
@@ -11,24 +11,23 @@
     session_write_close();  //close session
 
     // handle passed message
-    if($_REQUEST['msg1']) msg(hsc($_REQUEST['msg1']),1);
-    if($_REQUEST['err']) msg(hsc($_REQUEST['err']),-1);
+    if($INPUT->str('msg1')) msg(hsc($INPUT->str('msg1')),1);
+    if($INPUT->str('err')) msg(hsc($INPUT->str('err')),-1);
 
 
     // get namespace to display (either direct or from deletion order)
-    if($_REQUEST['delete']){
-        $DEL = cleanID($_REQUEST['delete']);
+    if($INPUT->str('delete')){
+        $DEL = cleanID($INPUT->str('delete'));
         $IMG = $DEL;
         $NS  = getNS($DEL);
-    }elseif($_REQUEST['edit']){
-        $IMG = cleanID($_REQUEST['edit']);
+    }elseif($INPUT->str('edit')){
+        $IMG = cleanID($INPUT->str('edit'));
         $NS  = getNS($IMG);
-    }elseif($_REQUEST['img']){
-        $IMG = cleanID($_REQUEST['img']);
+    }elseif($INPUT->str('img')){
+        $IMG = cleanID($INPUT->str('img'));
         $NS  = getNS($IMG);
     }else{
-        $NS = $_REQUEST['ns'];
-        $NS = cleanID($NS);
+        $NS = cleanID($INPUT->str('ns'));
     }
 
     // check auth
@@ -76,18 +75,18 @@
     }
 
     // handle meta saving
-    if($IMG && @array_key_exists('save', $_REQUEST['do'])){
-        $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']);
+    if($IMG && @array_key_exists('save', $INPUT->arr('do'))){
+        $JUMPTO = media_metasave($IMG,$AUTH,$INPUT->arr('meta'));
     }
 
-    if($IMG && ($_REQUEST['mediado'] == 'save' || @array_key_exists('save', $_REQUEST['mediado']))) {
-        $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']);
+    if($IMG && ($INPUT->str('mediado') == 'save' || @array_key_exists('save', $INPUT->arr('mediado')))) {
+        $JUMPTO = media_metasave($IMG,$AUTH,$INPUT->arr('meta'));
     }
 
-    if ($_REQUEST['rev'] && $conf['mediarevisions']) $REV = (int) $_REQUEST['rev'];
+    if ($INPUT->int('rev') && $conf['mediarevisions']) $REV = $INPUT->int('rev');
 
-    if($_REQUEST['mediado'] == 'restore' && $conf['mediarevisions']){
-        $JUMPTO = media_restore($_REQUEST['image'], $REV, $AUTH);
+    if($INPUT->str('mediado') == 'restore' && $conf['mediarevisions']){
+        $JUMPTO = media_restore($INPUT->str('image'), $REV, $AUTH);
     }
 
     // handle deletion
@@ -101,7 +100,7 @@
             if ($res & DOKU_MEDIA_EMPTY_NS && !$fullscreen) {
                 // current namespace was removed. redirecting to root ns passing msg along
                 send_redirect(DOKU_URL.'lib/exe/mediamanager.php?msg1='.
-                        rawurlencode($msg).'&edid='.$_REQUEST['edid']);
+                        rawurlencode($msg).'&edid='.$INPUT->str('edid'));
             }
             msg($msg,1);
         } elseif ($res & DOKU_MEDIA_INUSE) {
-- 
cgit v1.2.3


From 361f1762edc347181a45a66ba541ba8f144552c0 Mon Sep 17 00:00:00 2001
From: Tom N Harris 
Date: Fri, 29 Jun 2012 00:03:16 -0400
Subject: fix necessary global declaration

---
 lib/exe/mediamanager.php | 1 +
 1 file changed, 1 insertion(+)

(limited to 'lib/exe')

diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php
index 83166a2f4..04dd178cc 100644
--- a/lib/exe/mediamanager.php
+++ b/lib/exe/mediamanager.php
@@ -10,6 +10,7 @@
     trigger_event('MEDIAMANAGER_STARTED',$tmp=array());
     session_write_close();  //close session
 
+    global $INPUT;
     // handle passed message
     if($INPUT->str('msg1')) msg(hsc($INPUT->str('msg1')),1);
     if($INPUT->str('err')) msg(hsc($INPUT->str('err')),-1);
-- 
cgit v1.2.3