summaryrefslogtreecommitdiff
path: root/lib/exe
diff options
context:
space:
mode:
Diffstat (limited to 'lib/exe')
-rw-r--r--lib/exe/css.php92
-rw-r--r--lib/exe/detail.php2
-rw-r--r--lib/exe/indexer.php13
-rw-r--r--lib/exe/js.php98
-rw-r--r--lib/exe/xmlrpc.php15
5 files changed, 148 insertions, 72 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php
index 6c1d60751..925b78a76 100644
--- a/lib/exe/css.php
+++ b/lib/exe/css.php
@@ -45,23 +45,23 @@ function css_out(){
if(!$tpl) $tpl = $conf['template'];
// The generated script depends on some dynamic options
- $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tpl.$type,'.css');
+ $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].$INPUT->int('preview').DOKU_BASE.$tpl.$type,'.css');
// load styl.ini
- $styleini = css_styleini($tpl);
+ $styleini = css_styleini($tpl, $INPUT->bool('preview'));
// 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'];
+ $config_cascade['userstyle']['screen'] = array($config_cascade['userstyle']['default']);
}
// cache influencers
$tplinc = tpl_incdir($tpl);
$cache_files = getConfigFiles('main');
$cache_files[] = $tplinc.'style.ini';
- $cache_files[] = $tplinc.'style.local.ini'; // @deprecated
$cache_files[] = DOKU_CONF."tpl/$tpl/style.ini";
$cache_files[] = __FILE__;
+ if($INPUT->bool('preview')) $cache_files[] = $conf['cachedir'].'/preview.ini';
// Array of needed files and their web locations, the latter ones
// are needed to fix relative paths in the stylesheets
@@ -82,8 +82,10 @@ function css_out(){
$files[$mediatype] = array_merge($files[$mediatype], $styleini['stylesheets'][$mediatype]);
}
// load user styles
- if(isset($config_cascade['userstyle'][$mediatype])){
- $files[$mediatype][$config_cascade['userstyle'][$mediatype]] = DOKU_BASE;
+ if(!empty($config_cascade['userstyle'][$mediatype])) {
+ foreach($config_cascade['userstyle'][$mediatype] as $userstyle) {
+ $files[$mediatype][$userstyle] = DOKU_BASE;
+ }
}
$cache_files = array_merge($cache_files, array_keys($files[$mediatype]));
@@ -162,12 +164,15 @@ function css_out(){
* most of this function is error handling to show a nice useful error when
* LESS compilation fails
*
- * @param $css
+ * @param string $css
* @return string
*/
function css_parseless($css) {
+ global $conf;
+
$less = new lessc();
$less->importDir[] = DOKU_INC;
+ $less->setPreserveComments(!$conf['compress']);
if (defined('DOKU_UNITTEST')){
$less->importDir[] = TMP_DIR;
@@ -222,6 +227,10 @@ function css_parseless($css) {
* (sans the surrounding __ and with a ini_ prefix)
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $css
+ * @param array $replacements array(placeholder => value)
+ * @return string
*/
function css_applystyle($css, $replacements) {
// we convert ini replacements to LESS variable names
@@ -250,10 +259,14 @@ function css_applystyle($css, $replacements) {
* the stylesheet modes
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
* @param string $tpl the used template
+ * @param bool $preview load preview replacements
* @return array with keys 'stylesheets' and 'replacements'
*/
-function css_styleini($tpl) {
+function css_styleini($tpl, $preview=false) {
+ global $conf;
+
$stylesheets = array(); // mode, file => base
$replacements = array(); // placeholder => value
@@ -275,23 +288,6 @@ function css_styleini($tpl) {
}
}
- // load template's style.local.ini
- // @deprecated 2013-08-03
- $ini = $incbase.'style.local.ini';
- if(file_exists($ini)){
- $data = parse_ini_file($ini, true);
-
- // stylesheets
- if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){
- $stylesheets[$mode][$incbase.$file] = $webbase;
- }
-
- // replacements
- if(is_array($data['replacements'])){
- $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase));
- }
- }
-
// load configs's style.ini
$webbase = DOKU_BASE;
$ini = DOKU_CONF."tpl/$tpl/style.ini";
@@ -310,6 +306,19 @@ function css_styleini($tpl) {
}
}
+ // allow replacement overwrites in preview mode
+ if($preview) {
+ $webbase = DOKU_BASE;
+ $ini = $conf['cachedir'].'/preview.ini';
+ if(file_exists($ini)) {
+ $data = parse_ini_file($ini, true);
+ // replacements
+ if(is_array($data['replacements'])) {
+ $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'], $webbase));
+ }
+ }
+ }
+
return array(
'stylesheets' => $stylesheets,
'replacements' => $replacements
@@ -320,6 +329,10 @@ function css_styleini($tpl) {
* Amend paths used in replacement relative urls, refer FS#2879
*
* @author Chris Smith <chris@jalakai.co.uk>
+ *
+ * @param array $replacements with key-value pairs
+ * @param string $location
+ * @return array
*/
function css_fixreplacementurls($replacements, $location) {
foreach($replacements as $key => $value) {
@@ -351,11 +364,11 @@ function css_interwiki(){
$iwlinks = getInterwiki();
foreach(array_keys($iwlinks) as $iw){
$class = preg_replace('/[^_\-a-z0-9]+/i','_',$iw);
- if(@file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.png')){
+ if(file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.png')){
echo "a.iw_$class {";
echo ' background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.png)';
echo '}';
- }elseif(@file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.gif')){
+ }elseif(file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.gif')){
echo "a.iw_$class {";
echo ' background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.gif)';
echo '}';
@@ -403,6 +416,10 @@ function css_filetypes(){
/**
* Loads a given file and fixes relative URLs with the
* given location prefix
+ *
+ * @param string $file file system path
+ * @param string $location
+ * @return string
*/
function css_loadfile($file,$location=''){
$css_file = new DokuCssFile($file);
@@ -418,7 +435,7 @@ class DokuCssFile {
protected $filepath; // file system path to the CSS/Less file
protected $location; // base url location of the CSS/Less file
- private $relative_path = null;
+ protected $relative_path = null;
public function __construct($file) {
$this->filepath = $file;
@@ -433,7 +450,7 @@ class DokuCssFile {
* @return string the CSS/Less contents of the file
*/
public function load($location='') {
- if (!@file_exists($this->filepath)) return '';
+ if (!file_exists($this->filepath)) return '';
$css = io_readFile($this->filepath);
if (!$location) return $css;
@@ -451,7 +468,7 @@ class DokuCssFile {
*
* @return string relative file system path
*/
- private function getRelativePath(){
+ protected function getRelativePath(){
if (is_null($this->relative_path)) {
$basedir = array(DOKU_INC);
@@ -501,6 +518,9 @@ class DokuCssFile {
* Convert local image URLs to data URLs if the filesize is small
*
* Callback for preg_replace_callback
+ *
+ * @param array $match
+ * @return string
*/
function css_datauri($match){
global $conf;
@@ -528,9 +548,11 @@ function css_datauri($match){
* Returns a list of possible Plugin Styles (no existance check here)
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $mediatype
+ * @return array
*/
function css_pluginstyles($mediatype='screen'){
- global $lang;
$list = array();
$plugins = plugin_list();
foreach ($plugins as $p){
@@ -549,6 +571,9 @@ function css_pluginstyles($mediatype='screen'){
* Very simple CSS optimizer
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $css
+ * @return string
*/
function css_compress($css){
//strip comments through a callback
@@ -585,6 +610,9 @@ function css_compress($css){
* Keeps short comments (< 5 chars) to maintain typical browser hacks
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param array $matches
+ * @return string
*/
function css_comment_cb($matches){
if(strlen($matches[2]) > 4) return '';
@@ -596,7 +624,7 @@ function css_comment_cb($matches){
*
* Strips one line comments but makes sure it will not destroy url() constructs with slashes
*
- * @param $matches
+ * @param array $matches
* @return string
*/
function css_onelinecomment_cb($matches) {
diff --git a/lib/exe/detail.php b/lib/exe/detail.php
index cc29d5b87..ec1a9b874 100644
--- a/lib/exe/detail.php
+++ b/lib/exe/detail.php
@@ -37,7 +37,7 @@ $AUTH = auth_quickaclcheck($IMG);
if($AUTH >= AUTH_READ){
// check if image exists
$SRC = mediaFN($IMG,$REV);
- if(!@file_exists($SRC)){
+ if(!file_exists($SRC)){
//doesn't exist!
http_status(404);
$ERROR = 'File not found';
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php
index 3ab117736..d2a4d45f7 100644
--- a/lib/exe/indexer.php
+++ b/lib/exe/indexer.php
@@ -51,8 +51,9 @@ exit;
/**
* Trims the recent changes cache (or imports the old changelog) as needed.
*
- * @param media_changes If the media changelog shall be trimmed instead of
- * the page changelog
+ * @param bool $media_changes If the media changelog shall be trimmed instead of
+ * the page changelog
+ * @return bool
*
* @author Ben Coburn <btcoburn@silicodon.net>
*/
@@ -67,9 +68,9 @@ function runTrimRecentChanges($media_changes = false) {
// Trims the recent changes cache to the last $conf['changes_days'] recent
// changes or $conf['recent'] items, which ever is larger.
// The trimming is only done once a day.
- if (@file_exists($fn) &&
+ if (file_exists($fn) &&
(@filemtime($fn.'.trimmed')+86400)<time() &&
- !@file_exists($fn.'_tmp')) {
+ !file_exists($fn.'_tmp')) {
@touch($fn.'.trimmed');
io_lock($fn);
$lines = file($fn);
@@ -83,7 +84,7 @@ function runTrimRecentChanges($media_changes = false) {
io_saveFile($fn.'_tmp', ''); // presave tmp as 2nd lock
$trim_time = time() - $conf['recent_days']*86400;
$out_lines = array();
-
+ $old_lines = array();
for ($i=0; $i<count($lines); $i++) {
$log = parseChangelogLine($lines[$i]);
if ($log === false) continue; // discard junk
@@ -198,7 +199,7 @@ function sendGIF(){
header('Content-Length: '.strlen($img));
header('Connection: Close');
print $img;
- flush();
+ tpl_flush();
// Browser should drop connection after this
// Thinks it's got the whole image
}
diff --git a/lib/exe/js.php b/lib/exe/js.php
index bec12ef7a..16d22daf2 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -14,7 +14,7 @@ require_once(DOKU_INC.'inc/init.php');
// Main (don't run when UNIT test)
if(!defined('SIMPLE_TEST')){
- header('Content-Type: text/javascript; charset=utf-8');
+ header('Content-Type: application/javascript; charset=utf-8');
js_out();
}
@@ -30,9 +30,14 @@ function js_out(){
global $conf;
global $lang;
global $config_cascade;
+ global $INPUT;
+
+ // decide from where to get the template
+ $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t')));
+ if(!$tpl) $tpl = $conf['template'];
// The generated script depends on some dynamic options
- $cache = new cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.js');
+ $cache = new cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tpl,'.js');
$cache->_event = 'JS_CACHE_USE';
// load minified version for some files
@@ -51,11 +56,9 @@ function js_out(){
DOKU_INC.'lib/scripts/delay.js',
DOKU_INC.'lib/scripts/cookie.js',
DOKU_INC.'lib/scripts/script.js',
- DOKU_INC.'lib/scripts/tw-sack.js',
DOKU_INC.'lib/scripts/qsearch.js',
DOKU_INC.'lib/scripts/tree.js',
DOKU_INC.'lib/scripts/index.js',
- DOKU_INC.'lib/scripts/drag.js',
DOKU_INC.'lib/scripts/textselection.js',
DOKU_INC.'lib/scripts/toolbar.js',
DOKU_INC.'lib/scripts/edit.js',
@@ -63,17 +66,19 @@ function js_out(){
DOKU_INC.'lib/scripts/locktimer.js',
DOKU_INC.'lib/scripts/linkwiz.js',
DOKU_INC.'lib/scripts/media.js',
-# deprecated DOKU_INC.'lib/scripts/compatibility.js',
+ DOKU_INC.'lib/scripts/compatibility.js',
# disabled for FS#1958 DOKU_INC.'lib/scripts/hotkeys.js',
DOKU_INC.'lib/scripts/behaviour.js',
DOKU_INC.'lib/scripts/page.js',
- tpl_incdir().'script.js',
+ tpl_incdir($tpl).'script.js',
);
// add possible plugin scripts and userscript
$files = array_merge($files,js_pluginscripts());
- if(isset($config_cascade['userscript']['default'])){
- $files[] = $config_cascade['userscript']['default'];
+ if(!empty($config_cascade['userscript']['default'])) {
+ foreach($config_cascade['userscript']['default'] as $userscript) {
+ $files[] = $userscript;
+ }
}
$cache_files = array_merge($files, getConfigFiles('main'));
@@ -90,7 +95,7 @@ function js_out(){
$json = new JSON();
// add some global variables
print "var DOKU_BASE = '".DOKU_BASE."';";
- print "var DOKU_TPL = '".tpl_basedir()."';";
+ print "var DOKU_TPL = '".tpl_basedir($tpl)."';";
print "var DOKU_COOKIE_PARAM = " . $json->encode(
array(
'path' => empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'],
@@ -102,7 +107,7 @@ function js_out(){
// load JS specific translations
$lang['js']['plugins'] = js_pluginstrings();
- $templatestrings = js_templatestrings();
+ $templatestrings = js_templatestrings($tpl);
if(!empty($templatestrings)) {
$lang['js']['template'] = $templatestrings;
}
@@ -154,9 +159,11 @@ function js_out(){
* Load the given file, handle include calls and print it
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $file filename path to file
*/
function js_load($file){
- if(!@file_exists($file)) return;
+ if(!file_exists($file)) return;
static $loaded = array();
$data = io_readFile($file);
@@ -175,7 +182,7 @@ function js_load($file){
if($ifile{0} != '/') $ifile = dirname($file).'/'.$ifile;
- if(@file_exists($ifile)){
+ if(file_exists($ifile)){
$idata = io_readFile($ifile);
}else{
$idata = '';
@@ -189,6 +196,8 @@ function js_load($file){
* Returns a list of possible Plugin Scripts (no existance check here)
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @return array
*/
function js_pluginscripts(){
$list = array();
@@ -206,6 +215,8 @@ function js_pluginscripts(){
* - Nothing is returned for plugins without an entry for $lang['js']
*
* @author Gabriel Birke <birke@d-scribe.de>
+ *
+ * @return array
*/
function js_pluginstrings() {
global $conf;
@@ -213,10 +224,10 @@ function js_pluginstrings() {
$plugins = plugin_list();
foreach ($plugins as $p){
if (isset($lang)) unset($lang);
- if (@file_exists(DOKU_PLUGIN."$p/lang/en/lang.php")) {
+ if (file_exists(DOKU_PLUGIN."$p/lang/en/lang.php")) {
include DOKU_PLUGIN."$p/lang/en/lang.php";
}
- if (isset($conf['lang']) && $conf['lang']!='en' && @file_exists(DOKU_PLUGIN."$p/lang/".$conf['lang']."/lang.php")) {
+ if (isset($conf['lang']) && $conf['lang']!='en' && file_exists(DOKU_PLUGIN."$p/lang/".$conf['lang']."/lang.php")) {
include DOKU_PLUGIN."$p/lang/".$conf['lang']."/lang.php";
}
if (isset($lang['js'])) {
@@ -231,18 +242,21 @@ function js_pluginstrings() {
*
* - $lang['js'] must be an array.
* - Nothing is returned for template without an entry for $lang['js']
+ *
+ * @param string $tpl
+ * @return array
*/
-function js_templatestrings() {
+function js_templatestrings($tpl) {
global $conf;
$templatestrings = array();
- if (@file_exists(tpl_incdir()."lang/en/lang.php")) {
- include tpl_incdir()."lang/en/lang.php";
+ if (file_exists(tpl_incdir($tpl)."lang/en/lang.php")) {
+ include tpl_incdir($tpl)."lang/en/lang.php";
}
- if (isset($conf['lang']) && $conf['lang']!='en' && @file_exists(tpl_incdir()."lang/".$conf['lang']."/lang.php")) {
- include tpl_incdir()."lang/".$conf['lang']."/lang.php";
+ if (isset($conf['lang']) && $conf['lang']!='en' && file_exists(tpl_incdir($tpl)."lang/".$conf['lang']."/lang.php")) {
+ include tpl_incdir($tpl)."lang/".$conf['lang']."/lang.php";
}
if (isset($lang['js'])) {
- $templatestrings[$conf['template']] = $lang['js'];
+ $templatestrings[$tpl] = $lang['js'];
}
return $templatestrings;
}
@@ -252,6 +266,9 @@ function js_templatestrings() {
* as newline
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $string
+ * @return string
*/
function js_escape($string){
return str_replace('\\\\n','\\n',addslashes($string));
@@ -261,6 +278,8 @@ function js_escape($string){
* Adds the given JavaScript code to the window.onload() event
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $func
*/
function js_runonstart($func){
echo "jQuery(function(){ $func; });".NL;
@@ -275,6 +294,9 @@ function js_runonstart($func){
* @author Nick Galbreath <nickg@modp.com>
* @author Andreas Gohr <andi@splitbrain.org>
* @link http://code.google.com/p/jsstrip/
+ *
+ * @param string $s
+ * @return string
*/
function js_compress($s){
$s = ltrim($s); // strip all initial whitespace
@@ -289,7 +311,11 @@ function js_compress($s){
// items that don't need spaces next to them
$chars = "^&|!+\-*\/%=\?:;,{}()<>% \t\n\r'\"[]";
- $regex_starters = array("(", "=", "[", "," , ":", "!");
+ // items which need a space if the sign before and after whitespace is equal.
+ // E.g. '+ ++' may not be compressed to '+++' --> syntax error.
+ $ops = "+-";
+
+ $regex_starters = array("(", "=", "[", "," , ":", "!", "&", "|");
$whitespaces_chars = array(" ", "\t", "\n", "\r", "\0", "\x0B");
@@ -389,19 +415,27 @@ function js_compress($s){
// whitespaces
if( $ch == ' ' || $ch == "\r" || $ch == "\n" || $ch == "\t" ){
- // leading spaces
- if($i+1 < $slen && (strpos($chars,$s[$i+1]) !== false)){
- $i = $i + 1;
- continue;
- }
- // trailing spaces
- // if this ch is space AND the last char processed
- // is special, then skip the space
$lch = substr($result,-1);
- if($lch && (strpos($chars,$lch) !== false)){
- $i = $i + 1;
- continue;
+
+ // Only consider deleting whitespace if the signs before and after
+ // are not equal and are not an operator which may not follow itself.
+ if ((!$lch || $s[$i+1] == ' ')
+ || $lch != $s[$i+1]
+ || strpos($ops,$s[$i+1]) === false) {
+ // leading spaces
+ if($i+1 < $slen && (strpos($chars,$s[$i+1]) !== false)){
+ $i = $i + 1;
+ continue;
+ }
+ // trailing spaces
+ // if this ch is space AND the last char processed
+ // is special, then skip the space
+ if($lch && (strpos($chars,$lch) !== false)){
+ $i = $i + 1;
+ continue;
+ }
}
+
// else after all of this convert the "whitespace" to
// a single space. It will get appended below
$ch = ' ';
diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php
index c09daa17c..6a0163106 100644
--- a/lib/exe/xmlrpc.php
+++ b/lib/exe/xmlrpc.php
@@ -20,9 +20,14 @@ class dokuwiki_xmlrpc_server extends IXR_Server {
$this->remote = new RemoteAPI();
$this->remote->setDateTransformation(array($this, 'toDate'));
$this->remote->setFileTransformation(array($this, 'toFile'));
- $this->IXR_Server();
+ parent::__construct();
}
+ /**
+ * @param string $methodname
+ * @param array $args
+ * @return IXR_Error|mixed
+ */
function call($methodname, $args){
try {
$result = $this->remote->call($methodname, $args);
@@ -40,10 +45,18 @@ class dokuwiki_xmlrpc_server extends IXR_Server {
}
}
+ /**
+ * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp
+ * @return IXR_Date
+ */
function toDate($data) {
return new IXR_Date($data);
}
+ /**
+ * @param string $data
+ * @return IXR_Base64
+ */
function toFile($data) {
return new IXR_Base64($data);
}