diff options
author | Andreas Gohr <andi@splitbrain.org> | 2023-09-02 14:42:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-02 14:42:51 +0200 |
commit | 5ff5424d8c81c7123d8656a787af2ff85b3dec21 (patch) | |
tree | 322929ee01d892bb3c927e7fe1238369c647f820 /lib/exe | |
parent | 0613df3287b82a98b1e97cf86ed9d4c8fbd16f1c (diff) | |
parent | 91560755291852b8302767d454183a7662666f7e (diff) | |
download | dokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.tar.gz dokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.zip |
Merge pull request #4045 from dokuwiki/autofix
Use Rector to autofix code smell
Diffstat (limited to 'lib/exe')
-rw-r--r-- | lib/exe/ajax.php | 10 | ||||
-rw-r--r-- | lib/exe/css.php | 316 | ||||
-rw-r--r-- | lib/exe/detail.php | 25 | ||||
-rw-r--r-- | lib/exe/fetch.php | 194 | ||||
-rw-r--r-- | lib/exe/indexer.php | 2 | ||||
-rw-r--r-- | lib/exe/jquery.php | 23 | ||||
-rw-r--r-- | lib/exe/js.php | 246 | ||||
-rw-r--r-- | lib/exe/manifest.php | 6 | ||||
-rw-r--r-- | lib/exe/mediamanager.php | 242 | ||||
-rw-r--r-- | lib/exe/opensearch.php | 43 | ||||
-rw-r--r-- | lib/exe/taskrunner.php | 10 | ||||
-rw-r--r-- | lib/exe/xmlrpc.php | 1 |
12 files changed, 583 insertions, 535 deletions
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index 5f49e5135..719064175 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -1,4 +1,5 @@ <?php + /** * DokuWiki AJAX call handler * @@ -6,7 +7,10 @@ * @author Andreas Gohr <andi@splitbrain.org> */ -if (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/../../'); +use dokuwiki\Utf8\Clean; +use dokuwiki\Ajax; + +if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../'); require_once(DOKU_INC . 'inc/init.php'); //close session @@ -18,8 +22,8 @@ header('Content-Type: text/html; charset=utf-8'); //call the requested function global $INPUT; if ($INPUT->has('call')) { - $call = $INPUT->filter([\dokuwiki\Utf8\Clean::class, 'stripspecials'])->str('call'); - new \dokuwiki\Ajax($call); + $call = $INPUT->filter([Clean::class, 'stripspecials'])->str('call'); + new Ajax($call); } else { http_status(404); } diff --git a/lib/exe/css.php b/lib/exe/css.php index 05e55bb56..2df3e6286 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -1,4 +1,5 @@ <?php + /** * DokuWiki StyleSheet creator * @@ -6,17 +7,18 @@ * @author Andreas Gohr <andi@splitbrain.org> */ +use dokuwiki\StyleUtils; use dokuwiki\Cache\Cache; use dokuwiki\Extension\Event; -if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__ .'/../../'); -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'); +if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../'); +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) -if(!defined('SIMPLE_TEST')){ +if (!defined('SIMPLE_TEST')) { header('Content-Type: text/css; charset=utf-8'); css_out(); } @@ -29,49 +31,54 @@ if(!defined('SIMPLE_TEST')){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function css_out(){ +function css_out() +{ global $conf; global $lang; global $config_cascade; global $INPUT; if ($INPUT->str('s') == 'feed') { - $mediatypes = array('feed'); + $mediatypes = ['feed']; $type = 'feed'; } else { - $mediatypes = array('screen', 'all', 'print', 'speech'); + $mediatypes = ['screen', 'all', 'print', 'speech']; $type = ''; } // decide from where to get the template - $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t'))); - if(!$tpl) $tpl = $conf['template']; + $tpl = trim(preg_replace('/[^\w-]+/', '', $INPUT->str('t'))); + if (!$tpl) { + $tpl = $conf['template']; + } // load style.ini - $styleUtil = new \dokuwiki\StyleUtils($tpl, $INPUT->bool('preview')); + $styleUtil = new StyleUtils($tpl, $INPUT->bool('preview')); $styleini = $styleUtil->cssStyleini(); // cache influencers $tplinc = tpl_incdir($tpl); $cache_files = getConfigFiles('main'); - $cache_files[] = $tplinc.'style.ini'; - $cache_files[] = DOKU_CONF."tpl/$tpl/style.ini"; + $cache_files[] = $tplinc . 'style.ini'; + $cache_files[] = DOKU_CONF . "tpl/$tpl/style.ini"; $cache_files[] = __FILE__; - if($INPUT->bool('preview')) $cache_files[] = $conf['cachedir'].'/preview.ini'; + 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 - $media_files = array(); - foreach($mediatypes as $mediatype) { - $files = array(); + $media_files = []; + foreach ($mediatypes as $mediatype) { + $files = []; // load core styles - $files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/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/'; + $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)); @@ -80,8 +87,8 @@ function css_out(){ $files = array_merge($files, $styleini['stylesheets'][$mediatype]); } // load user styles - if(isset($config_cascade['userstyle'][$mediatype]) and is_array($config_cascade['userstyle'][$mediatype])) { - foreach($config_cascade['userstyle'][$mediatype] as $userstyle) { + if (isset($config_cascade['userstyle'][$mediatype]) && is_array($config_cascade['userstyle'][$mediatype])) { + foreach ($config_cascade['userstyle'][$mediatype] as $userstyle) { $files[$userstyle] = DOKU_BASE; } } @@ -91,7 +98,7 @@ function css_out(){ $CSSEvt = new Event('CSS_STYLES_INCLUDED', $media_files[$mediatype]); // Make it preventable. - if ( $CSSEvt->advise_before() ) { + if ($CSSEvt->advise_before()) { $cache_files = array_merge($cache_files, array_keys($media_files[$mediatype]['files'])); } else { // unset if prevented. Nothing will be printed for this mediatype. @@ -117,7 +124,7 @@ function css_out(){ // check cache age & handle conditional request // This may exit if a cache can be used - $cache_ok = $cache->useCache(array('files' => $cache_files)); + $cache_ok = $cache->useCache(['files' => $cache_files]); http_cached($cache->cache, $cache_ok); // start output buffering @@ -131,30 +138,34 @@ function css_out(){ // build the stylesheet foreach ($mediatypes as $mediatype) { - // Check if there is a wrapper set for this type. - if ( !isset($media_files[$mediatype]) ) { + if (!isset($media_files[$mediatype])) { continue; } $cssData = $media_files[$mediatype]; // Print the styles. - print NL; - if ( $cssData['encapsulate'] === true ) print $cssData['encapsulationPrefix'] . ' {'; - print '/* START '.$cssData['mediatype'].' styles */'.NL; + echo NL; + if ($cssData['encapsulate'] === true) { + echo $cssData['encapsulationPrefix'] . ' {'; + } + echo '/* START ' . $cssData['mediatype'] . ' styles */' . NL; // load files - foreach($cssData['files'] as $file => $location){ + foreach ($cssData['files'] as $file => $location) { $display = str_replace(fullpath(DOKU_INC), '', fullpath($file)); - print "\n/* XXXXXXXXX $display XXXXXXXXX */\n"; - print css_loadfile($file, $location); + echo "\n/* XXXXXXXXX $display XXXXXXXXX */\n"; + echo css_loadfile($file, $location); } - print NL; - if ( $cssData['encapsulate'] === true ) print '} /* /@media '; - else print '/*'; - print ' END '.$cssData['mediatype'].' styles */'.NL; + echo NL; + if ($cssData['encapsulate'] === true) { + echo '} /* /@media '; + } else { + echo '/*'; + } + echo ' END ' . $cssData['mediatype'] . ' styles */' . NL; } // end output buffering and get contents @@ -171,14 +182,14 @@ function css_out(){ $css = css_parseless($css); // compress whitespace and comments - if($conf['compress']){ + if ($conf['compress']) { $css = css_compress($css); } // embed small images right into the stylesheet - if($conf['cssdatauri']){ - $base = preg_quote(DOKU_BASE,'#'); - $css = preg_replace_callback('#(url\([ \'"]*)('.$base.')(.*?(?:\.(png|gif)))#i','css_datauri',$css); + if ($conf['cssdatauri']) { + $base = preg_quote(DOKU_BASE, '#'); + $css = preg_replace_callback('#(url\([ \'"]*)(' . $base . ')(.*?(?:\.(png|gif)))#i', 'css_datauri', $css); } http_cached_finish($cache->cache, $css); @@ -193,43 +204,44 @@ function css_out(){ * @param string $css * @return string */ -function css_parseless($css) { +function css_parseless($css) +{ global $conf; $less = new lessc(); - $less->importDir = array(DOKU_INC); + $less->importDir = [DOKU_INC]; $less->setPreserveComments(!$conf['compress']); - if (defined('DOKU_UNITTEST')){ + if (defined('DOKU_UNITTEST')) { $less->importDir[] = TMP_DIR; } try { return $less->compile($css); - } catch(Exception $e) { + } catch (Exception $e) { // get exception message - $msg = str_replace(array("\n", "\r", "'"), array(), $e->getMessage()); + $msg = str_replace(["\n", "\r", "'"], [], $e->getMessage()); // try to use line number to find affected file - if(preg_match('/line: (\d+)$/', $msg, $m)){ - $msg = substr($msg, 0, -1* strlen($m[0])); //remove useless linenumber + if (preg_match('/line: (\d+)$/', $msg, $m)) { + $msg = substr($msg, 0, -1 * strlen($m[0])); //remove useless linenumber $lno = $m[1]; // walk upwards to last include $lines = explode("\n", $css); - for($i=$lno-1; $i>=0; $i--){ - if(preg_match('/\/(\* XXXXXXXXX )(.*?)( XXXXXXXXX \*)\//', $lines[$i], $m)){ + for ($i = $lno - 1; $i >= 0; $i--) { + if (preg_match('/\/(\* XXXXXXXXX )(.*?)( XXXXXXXXX \*)\//', $lines[$i], $m)) { // we found it, add info to message - $msg .= ' in '.$m[2].' at line '.($lno-$i); + $msg .= ' in ' . $m[2] . ' at line ' . ($lno - $i); break; } } } // something went wrong - $error = 'A fatal error occured during compilation of the CSS files. '. - 'If you recently installed a new plugin or template it '. - 'might be broken and you should try disabling it again. ['.$msg.']'; + $error = 'A fatal error occured during compilation of the CSS files. ' . + 'If you recently installed a new plugin or template it ' . + 'might be broken and you should try disabling it again. [' . $msg . ']'; echo ".dokuwiki:before { content: '$error'; @@ -252,19 +264,20 @@ function css_parseless($css) { * This also adds the ini defined placeholders as less variables * (sans the surrounding __ and with a ini_ prefix) * - * @author Andreas Gohr <andi@splitbrain.org> - * * @param string $css - * @param array $replacements array(placeholder => value) + * @param array $replacements array(placeholder => value) * @return string + * + * @author Andreas Gohr <andi@splitbrain.org> */ -function css_applystyle($css, $replacements) { +function css_applystyle($css, $replacements) +{ // we convert ini replacements to LESS variable names // and build a list of variable: value; pairs $less = ''; - foreach((array) $replacements as $key => $value) { + foreach ((array)$replacements as $key => $value) { $lkey = trim($key, '_'); - $lkey = '@ini_'.$lkey; + $lkey = '@ini_' . $lkey; $less .= "$lkey: $value;\n"; $replacements[$key] = $lkey; @@ -274,43 +287,45 @@ function css_applystyle($css, $replacements) { $css = strtr($css, $replacements); // now prepend the list of LESS variables as the very first thing - $css = $less.$css; + $css = $less . $css; return $css; } /** * Wrapper for the files, content and mediatype for the event CSS_STYLES_INCLUDED * - * @author Gerry Weißbach <gerry.w@gammaproduction.de> - * * @param string $mediatype type ofthe current media files/content set * @param array $files set of files that define the current mediatype * @return array + * + * @author Gerry Weißbach <gerry.w@gammaproduction.de> */ -function css_filewrapper($mediatype, $files=array()){ - return array( - 'files' => $files, - 'mediatype' => $mediatype, - 'encapsulate' => $mediatype != 'all', - 'encapsulationPrefix' => '@media '.$mediatype - ); +function css_filewrapper($mediatype, $files = []) +{ + return [ + 'files' => $files, + 'mediatype' => $mediatype, + 'encapsulate' => $mediatype != 'all', + 'encapsulationPrefix' => '@media ' . $mediatype + ]; } /** * Prints the @media encapsulated default styles of DokuWiki * - * @author Gerry Weißbach <gerry.w@gammaproduction.de> - * * This function is being called by a CSS_STYLES_INCLUDED event * The event can be distinguished by the mediatype which is: * DW_DEFAULT + * + * @author Gerry Weißbach <gerry.w@gammaproduction.de> */ -function css_defaultstyles(){ +function css_defaultstyles() +{ // print the default classes for interwiki links and file downloads - print '@media screen {'; + echo '@media screen {'; css_interwiki(); css_filetypes(); - print '}'; + echo '}'; } /** @@ -324,11 +339,12 @@ function css_defaultstyles(){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function css_interwiki(){ +function css_interwiki() +{ // default style echo 'a.interwiki {'; - echo ' background: transparent url('.DOKU_BASE.'lib/images/interwiki.svg) 0 0 no-repeat;'; + echo ' background: transparent url(' . DOKU_BASE . 'lib/images/interwiki.svg) 0 0 no-repeat;'; echo ' background-size: 1.2em;'; echo ' padding: 0 0 0 1.4em;'; echo '}'; @@ -355,30 +371,31 @@ function css_interwiki(){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function css_filetypes(){ +function css_filetypes() +{ // default style echo '.mediafile {'; - echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/svg/file.svg) 0px 1px no-repeat;'; + echo ' background: transparent url(' . DOKU_BASE . 'lib/images/fileicons/svg/file.svg) 0px 1px no-repeat;'; echo ' background-size: 1.2em;'; echo ' padding-left: 1.5em;'; echo '}'; // additional styles when icon available // scan directory for all icons - $exts = array(); - if($dh = opendir(DOKU_INC.'lib/images/fileicons/svg')){ - while(false !== ($file = readdir($dh))){ - if(preg_match('/(.*?)\.svg$/i',$file, $match)){ + $exts = []; + if ($dh = opendir(DOKU_INC . 'lib/images/fileicons/svg')) { + while (false !== ($file = readdir($dh))) { + if (preg_match('/(.*?)\.svg$/i', $file, $match)) { $exts[] = strtolower($match[1]); } } closedir($dh); } - foreach($exts as $ext){ - $class = preg_replace('/[^_\-a-z0-9]+/','_',$ext); + foreach ($exts as $ext) { + $class = preg_replace('/[^_\-a-z0-9]+/', '_', $ext); echo ".mf_$class {"; - echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/svg/'.$ext.'.svg)'; + echo ' background-image: url(' . DOKU_BASE . 'lib/images/fileicons/svg/' . $ext . '.svg)'; echo '}'; } } @@ -391,23 +408,25 @@ function css_filetypes(){ * @param string $location * @return string */ -function css_loadfile($file,$location=''){ +function css_loadfile($file, $location = '') +{ $css_file = new DokuCssFile($file); return $css_file->load($location); } /** - * Helper class to abstract loading of css/less files + * Helper class to abstract loading of css/less files * - * @author Chris Smith <chris@jalakai.co.uk> + * @author Chris Smith <chris@jalakai.co.uk> */ -class DokuCssFile { - +class DokuCssFile +{ protected $filepath; // file system path to the CSS/Less file protected $location; // base url location of the CSS/Less file - protected $relative_path = null; + protected $relative_path; - public function __construct($file) { + public function __construct($file) + { $this->filepath = $file; } @@ -416,10 +435,11 @@ class DokuCssFile { * relative to the dokuwiki root: the web root (DOKU_BASE) for most files; the file system root (DOKU_INC) * for less files. * - * @param string $location base url for this file - * @return string the CSS/Less contents of the file + * @param string $location base url for this file + * @return string the CSS/Less contents of the file */ - public function load($location='') { + public function load($location = '') + { if (!file_exists($this->filepath)) return ''; $css = io_readFile($this->filepath); @@ -427,8 +447,8 @@ class DokuCssFile { $this->location = $location; - $css = preg_replace_callback('#(url\( *)([\'"]?)(.*?)(\2)( *\))#',array($this,'replacements'),$css); - $css = preg_replace_callback('#(@import\s+)([\'"])(.*?)(\2)#',array($this,'replacements'),$css); + $css = preg_replace_callback('#(url\( *)([\'"]?)(.*?)(\2)( *\))#', [$this, 'replacements'], $css); + $css = preg_replace_callback('#(@import\s+)([\'"])(.*?)(\2)#', [$this, 'replacements'], $css); return $css; } @@ -438,10 +458,11 @@ class DokuCssFile { * * @return string relative file system path */ - protected function getRelativePath(){ + protected function getRelativePath() + { if (is_null($this->relative_path)) { - $basedir = array(DOKU_INC); + $basedir = [DOKU_INC]; // during testing, files may be found relative to a second base dir, TMP_DIR if (defined('DOKU_UNITTEST')) { @@ -449,7 +470,7 @@ class DokuCssFile { } $basedir = array_map('preg_quote_cb', $basedir); - $regex = '/^('.join('|',$basedir).')/'; + $regex = '/^(' . implode('|', $basedir) . ')/'; $this->relative_path = preg_replace($regex, '', dirname($this->filepath)); } @@ -460,10 +481,11 @@ class DokuCssFile { * preg_replace callback to adjust relative urls from relative to this file to relative * to the appropriate dokuwiki root location as described in the code * - * @param array see http://php.net/preg_replace_callback + * @param array $match see http://php.net/preg_replace_callback * @return string see http://php.net/preg_replace_callback */ - public function replacements($match) { + public function replacements($match) + { if (preg_match('#^(/|data:|https?://)#', $match[3])) { // not a relative url? - no adjustment required return $match[0]; @@ -475,7 +497,7 @@ class DokuCssFile { $match[3] = $this->location . $match[3]; } - return join('',array_slice($match,1)); + return implode('', array_slice($match, 1)); } } @@ -487,46 +509,48 @@ class DokuCssFile { * @param array $match * @return string */ -function css_datauri($match){ +function css_datauri($match) +{ global $conf; - $pre = unslash($match[1]); - $base = unslash($match[2]); - $url = unslash($match[3]); - $ext = unslash($match[4]); + $pre = unslash($match[1]); + $base = unslash($match[2]); + $url = unslash($match[3]); + $ext = unslash($match[4]); - $local = DOKU_INC.$url; - $size = @filesize($local); - if($size && $size < $conf['cssdatauri']){ + $local = DOKU_INC . $url; + $size = @filesize($local); + if ($size && $size < $conf['cssdatauri']) { $data = base64_encode(file_get_contents($local)); } - if (!empty($data)){ - $url = 'data:image/'.$ext.';base64,'.$data; - }else{ - $url = $base.$url; + if (!empty($data)) { + $url = 'data:image/' . $ext . ';base64,' . $data; + } else { + $url = $base . $url; } - return $pre.$url; + return $pre . $url; } /** * Returns a list of possible Plugin Styles (no existance check here) * - * @author Andreas Gohr <andi@splitbrain.org> - * * @param string $mediatype * @return array + * @author Andreas Gohr <andi@splitbrain.org> + * */ -function css_pluginstyles($mediatype='screen'){ - $list = array(); +function css_pluginstyles($mediatype = 'screen') +{ + $list = []; $plugins = plugin_list(); - foreach ($plugins as $p){ - $list[DOKU_PLUGIN."$p/$mediatype.css"] = DOKU_BASE."lib/plugins/$p/"; - $list[DOKU_PLUGIN."$p/$mediatype.less"] = DOKU_BASE."lib/plugins/$p/"; + foreach ($plugins as $p) { + $list[DOKU_PLUGIN . "$p/$mediatype.css"] = DOKU_BASE . "lib/plugins/$p/"; + $list[DOKU_PLUGIN . "$p/$mediatype.less"] = DOKU_BASE . "lib/plugins/$p/"; // alternative for screen.css - if ($mediatype=='screen') { - $list[DOKU_PLUGIN."$p/style.css"] = DOKU_BASE."lib/plugins/$p/"; - $list[DOKU_PLUGIN."$p/style.less"] = DOKU_BASE."lib/plugins/$p/"; + if ($mediatype == 'screen') { + $list[DOKU_PLUGIN . "$p/style.css"] = DOKU_BASE . "lib/plugins/$p/"; + $list[DOKU_PLUGIN . "$p/style.less"] = DOKU_BASE . "lib/plugins/$p/"; } } return $list; @@ -535,32 +559,33 @@ function css_pluginstyles($mediatype='screen'){ /** * Very simple CSS optimizer * - * @author Andreas Gohr <andi@splitbrain.org> - * * @param string $css * @return string + * @author Andreas Gohr <andi@splitbrain.org> + * */ -function css_compress($css){ +function css_compress($css) +{ // replace quoted strings with placeholder $quote_storage = []; $quote_cb = function ($match) use (&$quote_storage) { $quote_storage[] = $match[0]; - return '"STR'.(count($quote_storage)-1).'"'; + return '"STR' . (count($quote_storage) - 1) . '"'; }; $css = preg_replace_callback('/(([\'"]).*?(?<!\\\\)\2)/', $quote_cb, $css); // strip comments through a callback - $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); + $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s', 'css_comment_cb', $css); // strip (incorrect but common) one line comments - $css = preg_replace_callback('/^.*\/\/.*$/m','css_onelinecomment_cb',$css); + $css = preg_replace_callback('/^.*\/\/.*$/m', 'css_onelinecomment_cb', $css); // strip whitespaces - $css = preg_replace('![\r\n\t ]+!',' ',$css); - $css = preg_replace('/ ?([;,{}\/]) ?/','\\1',$css); - $css = preg_replace('/ ?: /',':',$css); + $css = preg_replace('![\r\n\t ]+!', ' ', $css); + $css = preg_replace('/ ?([;,{}\/]) ?/', '\\1', $css); + $css = preg_replace('/ ?: /', ':', $css); // number compression $css = preg_replace( @@ -624,13 +649,15 @@ 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 + * + * @author Andreas Gohr <andi@splitbrain.org> + * */ -function css_comment_cb($matches){ - if(strlen($matches[2]) > 4) return ''; +function css_comment_cb($matches) +{ + if (strlen($matches[2]) > 4) return ''; return $matches[0]; } @@ -642,23 +669,24 @@ function css_comment_cb($matches){ * @param array $matches * @return string */ -function css_onelinecomment_cb($matches) { +function css_onelinecomment_cb($matches) +{ $line = $matches[0]; $i = 0; $len = strlen($line); - while ($i< $len){ + while ($i < $len) { $nextcom = strpos($line, '//', $i); $nexturl = stripos($line, 'url(', $i); - if($nextcom === false) { + if ($nextcom === false) { // no more comments, we're done $i = $len; break; } - if($nexturl === false || $nextcom < $nexturl) { + if ($nexturl === false || $nextcom < $nexturl) { // no url anymore, strip comment and be done $i = $nextcom; break; diff --git a/lib/exe/detail.php b/lib/exe/detail.php index 4df11fed6..96dcf9323 100644 --- a/lib/exe/detail.php +++ b/lib/exe/detail.php @@ -2,23 +2,23 @@ use dokuwiki\Extension\Event; -if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); -if(!defined('DOKU_MEDIADETAIL')) define('DOKU_MEDIADETAIL',1); +if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../'); +if (!defined('DOKU_MEDIADETAIL')) define('DOKU_MEDIADETAIL', 1); // define all DokuWiki globals here (needed within test requests but also helps to keep track) global $INPUT, $IMG, $ID, $REV, $SRC, $ERROR, $AUTH; -require_once(DOKU_INC.'inc/init.php'); +require_once(DOKU_INC . 'inc/init.php'); -$IMG = getID('media'); -$ID = cleanID($INPUT->str('id')); -$REV = $INPUT->int('rev'); +$IMG = getID('media'); +$ID = cleanID($INPUT->str('id')); +$REV = $INPUT->int('rev'); // this makes some general info available as well as the info about the // "parent" page -$INFO = array_merge(pageinfo(),mediainfo()); +$INFO = array_merge(pageinfo(), mediainfo()); -$tmp = array(); +$tmp = []; Event::createAndTrigger('DETAIL_STARTED', $tmp); //close session @@ -27,15 +27,15 @@ session_write_close(); $ERROR = false; // check image permissions $AUTH = auth_quickaclcheck($IMG); -if($AUTH >= AUTH_READ){ +if ($AUTH >= AUTH_READ) { // check if image exists - $SRC = mediaFN($IMG,$REV); - if(!file_exists($SRC)){ + $SRC = mediaFN($IMG, $REV); + if (!file_exists($SRC)) { //doesn't exist! http_status(404); $ERROR = 'File not found'; } -}else{ +} else { // no auth $ERROR = p_locale_xhtml('denied'); } @@ -44,4 +44,3 @@ if($AUTH >= AUTH_READ){ header('Content-Type: text/html; charset=utf-8'); include(template('detail.php')); tpl_img_close(); - diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php index 1b987ec10..845edc69e 100644 --- a/lib/exe/fetch.php +++ b/lib/exe/fetch.php @@ -1,4 +1,5 @@ <?php + /** * DokuWiki media passthrough file * @@ -6,122 +7,121 @@ * @author Andreas Gohr <andi@splitbrain.org> */ +use dokuwiki\Input\Input; use dokuwiki\Extension\Event; -if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../'); +if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../'); if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); -require_once(DOKU_INC.'inc/init.php'); +require_once(DOKU_INC . 'inc/init.php'); session_write_close(); //close session -require_once(DOKU_INC.'inc/fetch.functions.php'); +require_once(DOKU_INC . 'inc/fetch.functions.php'); if (defined('SIMPLE_TEST')) { - $INPUT = new \dokuwiki\Input\Input(); + $INPUT = new Input(); } // BEGIN main - $mimetypes = getMimeTypes(); +$mimetypes = getMimeTypes(); - //get input - $MEDIA = stripctl(getID('media', false)); // no cleaning except control chars - maybe external - $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); +//get input +$MEDIA = stripctl(getID('media', false)); // no cleaning except control chars - maybe external +$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); - list($EXT, $MIME, $DL) = mimetype($MEDIA, false); - if($EXT === false) { - $EXT = 'unknown'; - $MIME = 'application/octet-stream'; - $DL = true; - } +[$EXT, $MIME, $DL] = mimetype($MEDIA, false); +if ($EXT === false) { + $EXT = 'unknown'; + $MIME = 'application/octet-stream'; + $DL = true; +} - // check for permissions, preconditions and cache external files - list($STATUS, $STATUSMESSAGE) = checkFileStatus($MEDIA, $FILE, $REV, $WIDTH, $HEIGHT); +// check for permissions, preconditions and cache external files +[$STATUS, $STATUSMESSAGE] = checkFileStatus($MEDIA, $FILE, $REV, $WIDTH, $HEIGHT); - // prepare data for plugin events - $data = array( - 'media' => $MEDIA, - 'file' => $FILE, - 'orig' => $FILE, - 'mime' => $MIME, - 'download' => $DL, - 'cache' => $CACHE, - 'ext' => $EXT, - 'width' => $WIDTH, - 'height' => $HEIGHT, - 'status' => $STATUS, - 'statusmessage' => $STATUSMESSAGE, - 'ispublic' => media_ispublic($MEDIA), - 'csp' => [ - 'default-src' => "'none'", - 'style-src' => "'unsafe-inline'", - 'media-src' => "'self'", - 'object-src' => "'self'", - 'font-src' => "'self' data:", - 'form-action' => "'none'", - 'frame-ancestors' => "'self'", - ], - ); +// prepare data for plugin events +$data = [ + 'media' => $MEDIA, + 'file' => $FILE, + 'orig' => $FILE, + 'mime' => $MIME, + 'download' => $DL, + 'cache' => $CACHE, + 'ext' => $EXT, + 'width' => $WIDTH, + 'height' => $HEIGHT, + 'status' => $STATUS, + 'statusmessage' => $STATUSMESSAGE, + 'ispublic' => media_ispublic($MEDIA), + 'csp' => [ + 'default-src' => "'none'", + 'style-src' => "'unsafe-inline'", + 'media-src' => "'self'", + 'object-src' => "'self'", + 'font-src' => "'self' data:", + 'form-action' => "'none'", + 'frame-ancestors' => "'self'", + ] +]; - // handle the file status - $evt = new Event('FETCH_MEDIA_STATUS', $data); - if($evt->advise_before()) { - // redirects - if($data['status'] > 300 && $data['status'] <= 304) { - if (defined('SIMPLE_TEST')) return; //TestResponse doesn't recognize redirects - send_redirect($data['statusmessage']); - } - // send any non 200 status - if($data['status'] != 200) { - http_status($data['status'], $data['statusmessage']); - } - // die on errors - if($data['status'] > 203) { - print $data['statusmessage']; - if (defined('SIMPLE_TEST')) return; - exit; - } +// handle the file status +$evt = new Event('FETCH_MEDIA_STATUS', $data); +if ($evt->advise_before()) { + // redirects + if ($data['status'] > 300 && $data['status'] <= 304) { + if (defined('SIMPLE_TEST')) return; //TestResponse doesn't recognize redirects + send_redirect($data['statusmessage']); + } + // send any non 200 status + if ($data['status'] != 200) { + http_status($data['status'], $data['statusmessage']); } - $evt->advise_after(); - unset($evt); + // die on errors + if ($data['status'] > 203) { + echo $data['statusmessage']; + if (defined('SIMPLE_TEST')) return; + exit; + } +} +$evt->advise_after(); +unset($evt); - //handle image resizing/cropping - $evt = new Event('MEDIA_RESIZE', $data); - if($evt->advise_before()) { - if( - $MIME != 'image/svg+xml' && - (substr($MIME, 0, 5) == 'image') && - ($WIDTH || $HEIGHT) - ) { - if($HEIGHT && $WIDTH) { - $data['file'] = $FILE = media_crop_image($data['file'], $EXT, $WIDTH, $HEIGHT); - } else { - $data['file'] = $FILE = media_resize_image($data['file'], $EXT, $WIDTH, $HEIGHT); - } +//handle image resizing/cropping +$evt = new Event('MEDIA_RESIZE', $data); +if ($evt->advise_before()) { + if ( + $MIME != 'image/svg+xml' && + (substr($MIME, 0, 5) == 'image') && + ($WIDTH || $HEIGHT) + ) { + if ($HEIGHT && $WIDTH) { + $data['file'] = $FILE = media_crop_image($data['file'], $EXT, $WIDTH, $HEIGHT); + } else { + $data['file'] = $FILE = media_resize_image($data['file'], $EXT, $WIDTH, $HEIGHT); } } - $evt->advise_after(); - unset($evt); +} +$evt->advise_after(); +unset($evt); - // finally send the file to the client - $evt = new Event('MEDIA_SENDFILE', $data); - if($evt->advise_before()) { - sendFile( - $data['file'], - $data['mime'], - $data['download'], - $data['cache'], - $data['ispublic'], - $data['orig'], - $data['csp'] - ); - } - // Do something after the download finished. - $evt->advise_after(); // will not be emitted on 304 or x-sendfile +// finally send the file to the client +$evt = new Event('MEDIA_SENDFILE', $data); +if ($evt->advise_before()) { + sendFile( + $data['file'], + $data['mime'], + $data['download'], + $data['cache'], + $data['ispublic'], + $data['orig'], + $data['csp'] + ); +} +// Do something after the download finished. +$evt->advise_after(); // will not be emitted on 304 or x-sendfile // END DO main - -//Setup VIM: ex: et ts=2 : diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index c5f6e4081..944c31dcf 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -1,5 +1,7 @@ <?php + /** * @deprecated 2020-06-04 use taskrunner instead */ + include __DIR__ . '/taskrunner.php'; diff --git a/lib/exe/jquery.php b/lib/exe/jquery.php index b8638ecc0..7b0fceb72 100644 --- a/lib/exe/jquery.php +++ b/lib/exe/jquery.php @@ -2,10 +2,10 @@ use dokuwiki\Cache\Cache; -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('NL')) define('NL', "\n"); -if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here +if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../'); +if (!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching) +if (!defined('NL')) define('NL', "\n"); +if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here require_once(DOKU_INC . 'inc/init.php'); // MAIN @@ -20,23 +20,24 @@ jquery_out(); * * uses cache or fills it */ -function jquery_out() { +function jquery_out() +{ $cache = new Cache('jquery', '.js'); - $files = array( + $files = [ DOKU_INC . 'lib/scripts/jquery/jquery.min.js', - DOKU_INC . 'lib/scripts/jquery/jquery-ui.min.js', - ); + DOKU_INC . 'lib/scripts/jquery/jquery-ui.min.js' + ]; $cache_files = $files; $cache_files[] = __FILE__; // check cache age & handle conditional request // This may exit if a cache can be used - $cache_ok = $cache->useCache(array('files' => $cache_files)); + $cache_ok = $cache->useCache(['files' => $cache_files]); http_cached($cache->cache, $cache_ok); $js = ''; - foreach($files as $file) { - $js .= file_get_contents($file)."\n"; + foreach ($files as $file) { + $js .= file_get_contents($file) . "\n"; } stripsourcemaps($js); diff --git a/lib/exe/js.php b/lib/exe/js.php index 1d87fb6e5..36e1814f6 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -1,4 +1,5 @@ <?php + /** * DokuWiki JavaScript creator * @@ -6,19 +7,20 @@ * @author Andreas Gohr <andi@splitbrain.org> */ +use dokuwiki\Utf8\PhpString; use dokuwiki\Cache\Cache; use dokuwiki\Extension\Event; use splitbrain\JSStrip\Exception as JSStripException; use splitbrain\JSStrip\JSStrip; -if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__ .'/../../'); -if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching) -if(!defined('NL')) define('NL',"\n"); -if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT',1); // we gzip ourself here -require_once(DOKU_INC.'inc/init.php'); +if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../'); +if (!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching) +if (!defined('NL')) define('NL', "\n"); +if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here +require_once(DOKU_INC . 'inc/init.php'); // Main (don't run when UNIT test) -if(!defined('SIMPLE_TEST')){ +if (!defined('SIMPLE_TEST')) { header('Content-Type: application/javascript; charset=utf-8'); js_out(); } @@ -31,48 +33,49 @@ if(!defined('SIMPLE_TEST')){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function js_out(){ +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']; + $tpl = trim(preg_replace('/[^\w-]+/', '', $INPUT->str('t'))); + if (!$tpl) $tpl = $conf['template']; // array of core files - $files = array( - DOKU_INC.'lib/scripts/jquery/jquery.cookie.js', - DOKU_INC.'inc/lang/'.$conf['lang'].'/jquery.ui.datepicker.js', - DOKU_INC."lib/scripts/fileuploader.js", - DOKU_INC."lib/scripts/fileuploaderextended.js", - DOKU_INC.'lib/scripts/helpers.js', - DOKU_INC.'lib/scripts/delay.js', - DOKU_INC.'lib/scripts/cookie.js', - DOKU_INC.'lib/scripts/script.js', - DOKU_INC.'lib/scripts/qsearch.js', - DOKU_INC.'lib/scripts/search.js', - DOKU_INC.'lib/scripts/tree.js', - DOKU_INC.'lib/scripts/index.js', - DOKU_INC.'lib/scripts/textselection.js', - DOKU_INC.'lib/scripts/toolbar.js', - DOKU_INC.'lib/scripts/edit.js', - DOKU_INC.'lib/scripts/editor.js', - DOKU_INC.'lib/scripts/locktimer.js', - DOKU_INC.'lib/scripts/linkwiz.js', - DOKU_INC.'lib/scripts/media.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($tpl).'script.js', - ); + $files = [ + DOKU_INC . 'lib/scripts/jquery/jquery.cookie.js', + DOKU_INC . 'inc/lang/' . $conf['lang'] . '/jquery.ui.datepicker.js', + DOKU_INC . "lib/scripts/fileuploader.js", + DOKU_INC . "lib/scripts/fileuploaderextended.js", + DOKU_INC . 'lib/scripts/helpers.js', + DOKU_INC . 'lib/scripts/delay.js', + DOKU_INC . 'lib/scripts/cookie.js', + DOKU_INC . 'lib/scripts/script.js', + DOKU_INC . 'lib/scripts/qsearch.js', + DOKU_INC . 'lib/scripts/search.js', + DOKU_INC . 'lib/scripts/tree.js', + DOKU_INC . 'lib/scripts/index.js', + DOKU_INC . 'lib/scripts/textselection.js', + DOKU_INC . 'lib/scripts/toolbar.js', + DOKU_INC . 'lib/scripts/edit.js', + DOKU_INC . 'lib/scripts/editor.js', + DOKU_INC . 'lib/scripts/locktimer.js', + DOKU_INC . 'lib/scripts/linkwiz.js', + DOKU_INC . 'lib/scripts/media.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($tpl) . 'script.js', + ]; // add possible plugin scripts and userscript - $files = array_merge($files,js_pluginscripts()); - if(is_array($config_cascade['userscript']['default'])) { - foreach($config_cascade['userscript']['default'] as $userscript) { + $files = array_merge($files, js_pluginscripts()); + if (is_array($config_cascade['userscript']['default'])) { + foreach ($config_cascade['userscript']['default'] as $userscript) { $files[] = $userscript; } } @@ -81,7 +84,7 @@ function js_out(){ Event::createAndTrigger('JS_SCRIPT_LIST', $files); // The generated script depends on some dynamic options - $cache = new Cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].md5(serialize($files)),'.js'); + $cache = new Cache('scripts' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . md5(serialize($files)), '.js'); $cache->setEvent('JS_CACHE_USE'); $cache_files = array_merge($files, getConfigFiles('main')); @@ -89,60 +92,59 @@ function js_out(){ // check cache age & handle conditional request // This may exit if a cache can be used - $cache_ok = $cache->useCache(array('files' => $cache_files)); + $cache_ok = $cache->useCache(['files' => $cache_files]); http_cached($cache->cache, $cache_ok); // start output buffering and build the script ob_start(); // add some global variables - print "var DOKU_BASE = '".DOKU_BASE."';"; - print "var DOKU_TPL = '".tpl_basedir($tpl)."';"; - print "var DOKU_COOKIE_PARAM = " . json_encode( - array( - 'path' => empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'], - 'secure' => $conf['securecookie'] && is_ssl() - )).";"; + echo "var DOKU_BASE = '" . DOKU_BASE . "';"; + echo "var DOKU_TPL = '" . tpl_basedir($tpl) . "';"; + echo "var DOKU_COOKIE_PARAM = " . json_encode([ + 'path' => empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'], + 'secure' => $conf['securecookie'] && is_ssl() + ], JSON_THROW_ON_ERROR) . ";"; // FIXME: Move those to JSINFO - print "Object.defineProperty(window, 'DOKU_UHN', { get: function() {". - "console.warn('Using DOKU_UHN is deprecated. Please use JSINFO.useHeadingNavigation instead');". - "return JSINFO.useHeadingNavigation; } });"; - print "Object.defineProperty(window, 'DOKU_UHC', { get: function() {". - "console.warn('Using DOKU_UHC is deprecated. Please use JSINFO.useHeadingContent instead');". - "return JSINFO.useHeadingContent; } });"; + echo "Object.defineProperty(window, 'DOKU_UHN', { get: function() {" . + "console.warn('Using DOKU_UHN is deprecated. Please use JSINFO.useHeadingNavigation instead');" . + "return JSINFO.useHeadingNavigation; } });"; + echo "Object.defineProperty(window, 'DOKU_UHC', { get: function() {" . + "console.warn('Using DOKU_UHC is deprecated. Please use JSINFO.useHeadingContent instead');" . + "return JSINFO.useHeadingContent; } });"; // load JS specific translations $lang['js']['plugins'] = js_pluginstrings(); $templatestrings = js_templatestrings($tpl); - if(!empty($templatestrings)) { + if (!empty($templatestrings)) { $lang['js']['template'] = $templatestrings; } - echo 'LANG = '.json_encode($lang['js']).";\n"; + echo 'LANG = ' . json_encode($lang['js'], JSON_THROW_ON_ERROR) . ";\n"; // load toolbar toolbar_JSdefines('toolbar'); // load files - foreach($files as $file){ - if(!file_exists($file)) continue; - $ismin = (substr($file,-7) == '.min.js'); - $debugjs = ($conf['allowdebug'] && strpos($file, DOKU_INC.'lib/scripts/') !== 0); + foreach ($files as $file) { + if (!file_exists($file)) continue; + $ismin = (substr($file, -7) == '.min.js'); + $debugjs = ($conf['allowdebug'] && strpos($file, DOKU_INC . 'lib/scripts/') !== 0); - echo "\n\n/* XXXXXXXXXX begin of ".str_replace(DOKU_INC, '', $file) ." XXXXXXXXXX */\n\n"; - if($ismin) echo "\n/* BEGIN NOCOMPRESS */\n"; + echo "\n\n/* XXXXXXXXXX begin of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; + if ($ismin) echo "\n/* BEGIN NOCOMPRESS */\n"; if ($debugjs) echo "\ntry {\n"; js_load($file); - if ($debugjs) echo "\n} catch (e) {\n logError(e, '".str_replace(DOKU_INC, '', $file)."');\n}\n"; - if($ismin) echo "\n/* END NOCOMPRESS */\n"; + if ($debugjs) echo "\n} catch (e) {\n logError(e, '" . str_replace(DOKU_INC, '', $file) . "');\n}\n"; + if ($ismin) echo "\n/* END NOCOMPRESS */\n"; echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; } // init stuff - if($conf['locktime'] != 0){ - js_runonstart("dw_locktimer.init(".($conf['locktime'] - 60).",".$conf['usedraft'].")"); + if ($conf['locktime'] != 0) { + js_runonstart("dw_locktimer.init(" . ($conf['locktime'] - 60) . "," . $conf['usedraft'] . ")"); } // init hotkeys - must have been done after init of toolbar -# disabled for FS#1958 js_runonstart('initializeHotkeys()'); + # disabled for FS#1958 js_runonstart('initializeHotkeys()'); // end output buffering and get contents $js = ob_get_contents(); @@ -152,11 +154,11 @@ function js_out(){ stripsourcemaps($js); // compress whitespace and comments - if($conf['compress']){ + if ($conf['compress']) { try { $js = (new JSStrip())->compress($js); } catch (JSStripException $e) { - $js .= "\nconsole.error(".json_encode($e->getMessage()).");\n"; + $js .= "\nconsole.error(" . json_encode($e->getMessage(), JSON_THROW_ON_ERROR) . ");\n"; } } @@ -168,38 +170,39 @@ 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 + * + * @author Andreas Gohr <andi@splitbrain.org> */ -function js_load($file){ - if(!file_exists($file)) return; - static $loaded = array(); +function js_load($file) +{ + if (!file_exists($file)) return; + static $loaded = []; $data = io_readFile($file); - while(preg_match('#/\*\s*DOKUWIKI:include(_once)?\s+([\w\.\-_/]+)\s*\*/#',$data,$match)){ + while (preg_match('#/\*\s*DOKUWIKI:include(_once)?\s+([\w\.\-_/]+)\s*\*/#', $data, $match)) { $ifile = $match[2]; // is it a include_once? - if($match[1]){ - $base = \dokuwiki\Utf8\PhpString::basename($ifile); - if(array_key_exists($base, $loaded) && $loaded[$base] === true){ - $data = str_replace($match[0], '' ,$data); + if ($match[1]) { + $base = PhpString::basename($ifile); + if (array_key_exists($base, $loaded) && $loaded[$base] === true) { + $data = str_replace($match[0], '', $data); continue; } $loaded[$base] = true; } - if($ifile[0] != '/') $ifile = dirname($file).'/'.$ifile; + if ($ifile[0] != '/') $ifile = dirname($file) . '/' . $ifile; $idata = ''; if (file_exists($ifile)) { - $ismin = (substr($ifile, -7) == '.min.js');; + $ismin = (substr($ifile, -7) == '.min.js'); if ($ismin) $idata .= "\n/* BEGIN NOCOMPRESS */\n"; $idata .= io_readFile($ifile); if ($ismin) $idata .= "\n/* END NOCOMPRESS */\n"; } - $data = str_replace($match[0],$idata,$data); + $data = str_replace($match[0], $idata, $data); } echo "$data\n"; } @@ -207,15 +210,16 @@ function js_load($file){ /** * Returns a list of possible Plugin Scripts (no existance check here) * - * @author Andreas Gohr <andi@splitbrain.org> - * * @return array + * + * @author Andreas Gohr <andi@splitbrain.org> */ -function js_pluginscripts(){ - $list = array(); +function js_pluginscripts() +{ + $list = []; $plugins = plugin_list(); - foreach ($plugins as $p){ - $list[] = DOKU_PLUGIN."$p/script.js"; + foreach ($plugins as $p) { + $list[] = DOKU_PLUGIN . "$p/script.js"; } return $list; } @@ -226,38 +230,39 @@ function js_pluginscripts(){ * - $lang['js'] must be an array. * - Nothing is returned for plugins without an entry for $lang['js'] * + * @return array * @author Gabriel Birke <birke@d-scribe.de> * - * @return array */ -function js_pluginstrings() { +function js_pluginstrings() +{ global $conf, $config_cascade; - $pluginstrings = array(); + $pluginstrings = []; $plugins = plugin_list(); - foreach($plugins as $p) { + foreach ($plugins as $p) { $path = DOKU_PLUGIN . $p . '/lang/'; - if(isset($lang)) unset($lang); - if(file_exists($path . "en/lang.php")) { + if (isset($lang)) unset($lang); + if (file_exists($path . "en/lang.php")) { include $path . "en/lang.php"; } - foreach($config_cascade['lang']['plugin'] as $config_file) { - if(file_exists($config_file . $p . '/en/lang.php')) { + foreach ($config_cascade['lang']['plugin'] as $config_file) { + if (file_exists($config_file . $p . '/en/lang.php')) { include($config_file . $p . '/en/lang.php'); } } - if(isset($conf['lang']) && $conf['lang'] != 'en') { - if(file_exists($path . $conf['lang'] . "/lang.php")) { + if (isset($conf['lang']) && $conf['lang'] != 'en') { + if (file_exists($path . $conf['lang'] . "/lang.php")) { include($path . $conf['lang'] . '/lang.php'); } - foreach($config_cascade['lang']['plugin'] as $config_file) { - if(file_exists($config_file . $p . '/' . $conf['lang'] . '/lang.php')) { + foreach ($config_cascade['lang']['plugin'] as $config_file) { + if (file_exists($config_file . $p . '/' . $conf['lang'] . '/lang.php')) { include($config_file . $p . '/' . $conf['lang'] . '/lang.php'); } } } - if(isset($lang['js'])) { + if (isset($lang['js'])) { $pluginstrings[$p] = $lang['js']; } } @@ -273,35 +278,36 @@ function js_pluginstrings() { * @param string $tpl * @return array */ -function js_templatestrings($tpl) { +function js_templatestrings($tpl) +{ global $conf, $config_cascade; $path = tpl_incdir() . 'lang/'; - $templatestrings = array(); - if(file_exists($path . "en/lang.php")) { + $templatestrings = []; + if (file_exists($path . "en/lang.php")) { include $path . "en/lang.php"; } - foreach($config_cascade['lang']['template'] as $config_file) { - if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { + foreach ($config_cascade['lang']['template'] as $config_file) { + if (file_exists($config_file . $conf['template'] . '/en/lang.php')) { include($config_file . $conf['template'] . '/en/lang.php'); } } - if(isset($conf['lang']) && $conf['lang'] != 'en' && file_exists($path . $conf['lang'] . "/lang.php")) { + if (isset($conf['lang']) && $conf['lang'] != 'en' && file_exists($path . $conf['lang'] . "/lang.php")) { include $path . $conf['lang'] . "/lang.php"; } - if(isset($conf['lang']) && $conf['lang'] != 'en') { - if(file_exists($path . $conf['lang'] . "/lang.php")) { + if (isset($conf['lang']) && $conf['lang'] != 'en') { + if (file_exists($path . $conf['lang'] . "/lang.php")) { include $path . $conf['lang'] . "/lang.php"; } - foreach($config_cascade['lang']['template'] as $config_file) { - if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { + foreach ($config_cascade['lang']['template'] as $config_file) { + if (file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); } } } - if(isset($lang['js'])) { + if (isset($lang['js'])) { $templatestrings[$tpl] = $lang['js']; } return $templatestrings; @@ -311,22 +317,24 @@ function js_templatestrings($tpl) { * Escapes a String to be embedded in a JavaScript call, keeps \n * as newline * - * @author Andreas Gohr <andi@splitbrain.org> - * * @param string $string * @return string + * + * @author Andreas Gohr <andi@splitbrain.org> */ -function js_escape($string){ - return str_replace('\\\\n','\\n',addslashes($string)); +function js_escape($string) +{ + return str_replace('\\\\n', '\\n', addslashes($string)); } /** * Adds the given JavaScript code to the window.onload() event * - * @author Andreas Gohr <andi@splitbrain.org> - * * @param string $func + * + * @author Andreas Gohr <andi@splitbrain.org> */ -function js_runonstart($func){ - echo "jQuery(function(){ $func; });".NL; +function js_runonstart($func) +{ + echo "jQuery(function(){ $func; });" . NL; } diff --git a/lib/exe/manifest.php b/lib/exe/manifest.php index 687c1937c..b3ccfb7e8 100644 --- a/lib/exe/manifest.php +++ b/lib/exe/manifest.php @@ -1,9 +1,11 @@ <?php +use dokuwiki\Manifest; + if (!defined('DOKU_INC')) { define('DOKU_INC', __DIR__ . '/../../'); } -if(!defined('NOSESSION')) define('NOSESSION',true); // no session or auth required here +if (!defined('NOSESSION')) define('NOSESSION', true); // no session or auth required here require_once(DOKU_INC . 'inc/init.php'); if (!actionOK('manifest')) { @@ -11,5 +13,5 @@ if (!actionOK('manifest')) { exit(); } -$manifest = new \dokuwiki\Manifest(); +$manifest = new Manifest(); $manifest->sendManifest(); diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php index 3d8f865b0..54c6b81c1 100644 --- a/lib/exe/mediamanager.php +++ b/lib/exe/mediamanager.php @@ -2,130 +2,130 @@ use dokuwiki\Extension\Event; - if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); - define('DOKU_MEDIAMANAGER',1); - - // for multi uploader: - @ini_set('session.use_only_cookies',0); - - require_once(DOKU_INC.'inc/init.php'); - - global $INPUT; - global $lang; - global $conf; - // handle passed message - if($INPUT->str('msg1')) msg(hsc($INPUT->str('msg1')),1); - if($INPUT->str('err')) msg(hsc($INPUT->str('err')),-1); - - global $DEL; - // get namespace to display (either direct or from deletion order) - if($INPUT->str('delete')){ - $DEL = cleanID($INPUT->str('delete')); - $IMG = $DEL; - $NS = getNS($DEL); - }elseif($INPUT->str('edit')){ - $IMG = cleanID($INPUT->str('edit')); - $NS = getNS($IMG); - }elseif($INPUT->str('img')){ - $IMG = cleanID($INPUT->str('img')); - $NS = getNS($IMG); - }else{ - $NS = cleanID($INPUT->str('ns')); - $IMG = null; +if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../'); +define('DOKU_MEDIAMANAGER', 1); + +// for multi uploader: +@ini_set('session.use_only_cookies', 0); + +require_once(DOKU_INC . 'inc/init.php'); + +global $INPUT; +global $lang; +global $conf; +// handle passed message +if ($INPUT->str('msg1')) msg(hsc($INPUT->str('msg1')), 1); +if ($INPUT->str('err')) msg(hsc($INPUT->str('err')), -1); + +global $DEL; +// get namespace to display (either direct or from deletion order) +if ($INPUT->str('delete')) { + $DEL = cleanID($INPUT->str('delete')); + $IMG = $DEL; + $NS = getNS($DEL); +} elseif ($INPUT->str('edit')) { + $IMG = cleanID($INPUT->str('edit')); + $NS = getNS($IMG); +} elseif ($INPUT->str('img')) { + $IMG = cleanID($INPUT->str('img')); + $NS = getNS($IMG); +} else { + $NS = cleanID($INPUT->str('ns')); + $IMG = null; +} + +global $INFO, $JSINFO; +$INFO = empty($INFO) ? mediainfo() : array_merge($INFO, mediainfo()); +$JSINFO['id'] = ''; +$JSINFO['namespace'] = ''; +$AUTH = $INFO['perm']; // shortcut for historical reasons + +// If this page is directly opened it means we are in popup mode not fullscreen +// $fullscreen isn't defined by default it might lead to some PHP warnings +$fullscreen ??= false; + +$tmp = []; +Event::createAndTrigger('MEDIAMANAGER_STARTED', $tmp); +session_write_close(); //close session + +// do not display the manager if user does not have read access +if ($AUTH < AUTH_READ && !$fullscreen) { + http_status(403); + die($lang['accessdenied']); +} + +// handle flash upload +if (isset($_FILES['Filedata'])) { + $_FILES['upload'] =& $_FILES['Filedata']; + $JUMPTO = media_upload($NS, $AUTH); + if ($JUMPTO == false) { + http_status(400); + echo 'Upload failed'; } - - global $INFO, $JSINFO; - $INFO = !empty($INFO) ? array_merge($INFO, mediainfo()) : mediainfo(); - $JSINFO['id'] = ''; - $JSINFO['namespace'] = ''; - $AUTH = $INFO['perm']; // shortcut for historical reasons - - // If this page is directly opened it means we are in popup mode not fullscreen - // $fullscreen isn't defined by default it might lead to some PHP warnings - $fullscreen = isset($fullscreen) ? $fullscreen : false; - - $tmp = array(); - Event::createAndTrigger('MEDIAMANAGER_STARTED', $tmp); - session_write_close(); //close session - - // do not display the manager if user does not have read access - if($AUTH < AUTH_READ && !$fullscreen) { - http_status(403); - die($lang['accessdenied']); - } - - // handle flash upload - if(isset($_FILES['Filedata'])){ - $_FILES['upload'] =& $_FILES['Filedata']; - $JUMPTO = media_upload($NS,$AUTH); - if($JUMPTO == false){ - http_status(400); - echo 'Upload failed'; - } - echo 'ok'; - exit; - } - - // give info on PHP caught upload errors - if(!empty($_FILES['upload']['error'])){ - switch($_FILES['upload']['error']){ - case 1: - case 2: - msg(sprintf($lang['uploadsize'], - filesize_h(php_to_byte(ini_get('upload_max_filesize')))),-1); - break; - default: - msg($lang['uploadfail'].' ('.$_FILES['upload']['error'].')',-1); - } - unset($_FILES['upload']); - } - - // handle upload - if(!empty($_FILES['upload']['tmp_name'])){ - $JUMPTO = media_upload($NS,$AUTH); - if($JUMPTO) $NS = getNS($JUMPTO); - } - - // handle meta saving - if($IMG && @array_key_exists('save', $INPUT->arr('do'))){ - $JUMPTO = media_metasave($IMG,$AUTH,$INPUT->arr('meta')); + echo 'ok'; + exit; +} + +// give info on PHP caught upload errors +if (!empty($_FILES['upload']['error'])) { + switch ($_FILES['upload']['error']) { + case 1: + case 2: + msg(sprintf( + $lang['uploadsize'], + filesize_h(php_to_byte(ini_get('upload_max_filesize'))) + ), -1); + break; + default: + msg($lang['uploadfail'] . ' (' . $_FILES['upload']['error'] . ')', -1); } - - if($IMG && ($INPUT->str('mediado') == 'save' || @array_key_exists('save', $INPUT->arr('mediado')))) { - $JUMPTO = media_metasave($IMG,$AUTH,$INPUT->arr('meta')); + unset($_FILES['upload']); +} + +// handle upload +if (!empty($_FILES['upload']['tmp_name'])) { + $JUMPTO = media_upload($NS, $AUTH); + if ($JUMPTO) $NS = getNS($JUMPTO); +} + +// handle meta saving +if ($IMG && @array_key_exists('save', $INPUT->arr('do'))) { + $JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta')); +} + +if ($IMG && ($INPUT->str('mediado') == 'save' || @array_key_exists('save', $INPUT->arr('mediado')))) { + $JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta')); +} + +if ($INPUT->int('rev') && $conf['mediarevisions']) $REV = $INPUT->int('rev'); + +if ($INPUT->str('mediado') == 'restore' && $conf['mediarevisions']) { + $JUMPTO = media_restore($INPUT->str('image'), $REV, $AUTH); +} + +// handle deletion +if ($DEL) { + $res = 0; + if (checkSecurityToken()) { + $res = media_delete($DEL, $AUTH); } - - if ($INPUT->int('rev') && $conf['mediarevisions']) $REV = $INPUT->int('rev'); - - if($INPUT->str('mediado') == 'restore' && $conf['mediarevisions']){ - $JUMPTO = media_restore($INPUT->str('image'), $REV, $AUTH); - } - - // handle deletion - if($DEL) { - $res = 0; - if(checkSecurityToken()) { - $res = media_delete($DEL,$AUTH); - } - if ($res & DOKU_MEDIA_DELETED) { - $msg = sprintf($lang['deletesucc'], noNS($DEL)); - 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='.$INPUT->str('edid')); - } - msg($msg,1); - } elseif ($res & DOKU_MEDIA_INUSE) { - msg(sprintf($lang['mediainuse'],noNS($DEL)),0); - } else { - msg(sprintf($lang['deletefail'],noNS($DEL)),-1); + if ($res & DOKU_MEDIA_DELETED) { + $msg = sprintf($lang['deletesucc'], noNS($DEL)); + 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=' . $INPUT->str('edid')); } + msg($msg, 1); + } elseif ($res & DOKU_MEDIA_INUSE) { + msg(sprintf($lang['mediainuse'], noNS($DEL)), 0); + } else { + msg(sprintf($lang['deletefail'], noNS($DEL)), -1); } - // finished - start output - - if (!$fullscreen) { - header('Content-Type: text/html; charset=utf-8'); - include(template('mediamanager.php')); - } +} +// finished - start output -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +if (!$fullscreen) { + header('Content-Type: text/html; charset=utf-8'); + include(template('mediamanager.php')); +} diff --git a/lib/exe/opensearch.php b/lib/exe/opensearch.php index b00b2b771..766bdb2e6 100644 --- a/lib/exe/opensearch.php +++ b/lib/exe/opensearch.php @@ -1,4 +1,5 @@ <?php + /** * DokuWiki OpenSearch creator * @@ -8,31 +9,29 @@ * @author Andreas Gohr <andi@splitbrain.org> */ -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('NL')) define('NL',"\n"); -require_once(DOKU_INC.'inc/init.php'); +if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../'); +if (!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching) +if (!defined('NL')) define('NL', "\n"); +require_once(DOKU_INC . 'inc/init.php'); // try to be clever about the favicon location -if(file_exists(DOKU_INC.'favicon.ico')){ - $ico = DOKU_URL.'favicon.ico'; -}elseif(file_exists(tpl_incdir().'images/favicon.ico')){ - $ico = DOKU_URL.'lib/tpl/'.$conf['template'].'/images/favicon.ico'; -}elseif(file_exists(tpl_incdir().'favicon.ico')){ - $ico = DOKU_URL.'lib/tpl/'.$conf['template'].'/favicon.ico'; -}else{ - $ico = DOKU_URL.'lib/tpl/dokuwiki/images/favicon.ico'; +if (file_exists(DOKU_INC . 'favicon.ico')) { + $ico = DOKU_URL . 'favicon.ico'; +} elseif (file_exists(tpl_incdir() . 'images/favicon.ico')) { + $ico = DOKU_URL . 'lib/tpl/' . $conf['template'] . '/images/favicon.ico'; +} elseif (file_exists(tpl_incdir() . 'favicon.ico')) { + $ico = DOKU_URL . 'lib/tpl/' . $conf['template'] . '/favicon.ico'; +} else { + $ico = DOKU_URL . 'lib/tpl/dokuwiki/images/favicon.ico'; } // output header('Content-Type: application/opensearchdescription+xml; charset=utf-8'); -echo '<?xml version="1.0"?>'.NL; -echo '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">'.NL; -echo ' <ShortName>'.hsc($conf['title']).'</ShortName>'.NL; -echo ' <Image width="16" height="16" type="image/x-icon">'.$ico.'</Image>'.NL; -echo ' <Url type="text/html" template="'.DOKU_URL.DOKU_SCRIPT.'?do=search&id={searchTerms}" />'.NL; -echo ' <Url type="application/x-suggestions+json" template="'. - DOKU_URL.'lib/exe/ajax.php?call=suggestions&q={searchTerms}" />'.NL; -echo '</OpenSearchDescription>'.NL; - -//Setup VIM: ex: et ts=4 : +echo '<?xml version="1.0"?>' . NL; +echo '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">' . NL; +echo ' <ShortName>' . hsc($conf['title']) . '</ShortName>' . NL; +echo ' <Image width="16" height="16" type="image/x-icon">' . $ico . '</Image>' . NL; +echo ' <Url type="text/html" template="' . DOKU_URL . DOKU_SCRIPT . '?do=search&id={searchTerms}" />' . NL; +echo ' <Url type="application/x-suggestions+json" template="' . + DOKU_URL . 'lib/exe/ajax.php?call=suggestions&q={searchTerms}" />' . NL; +echo '</OpenSearchDescription>' . NL; diff --git a/lib/exe/taskrunner.php b/lib/exe/taskrunner.php index 69ab4451a..0a62bf623 100644 --- a/lib/exe/taskrunner.php +++ b/lib/exe/taskrunner.php @@ -1,16 +1,20 @@ <?php + /** * DokuWiki indexer * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> */ + +use dokuwiki\TaskRunner; + if (!defined('DOKU_INC')) { define('DOKU_INC', __DIR__ . '/../../'); } -define('DOKU_DISABLE_GZIP_OUTPUT',1); -require_once DOKU_INC.'inc/init.php'; +define('DOKU_DISABLE_GZIP_OUTPUT', 1); +require_once DOKU_INC . 'inc/init.php'; session_write_close(); //close session -$taskRunner = new \dokuwiki\TaskRunner(); +$taskRunner = new TaskRunner(); $taskRunner->run(); diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php index e90fb9eba..9fad90136 100644 --- a/lib/exe/xmlrpc.php +++ b/lib/exe/xmlrpc.php @@ -1,4 +1,5 @@ <?php + /** * XMLRPC API backend */ |