diff options
author | Andreas Gohr <andi@splitbrain.org> | 2023-08-29 20:13:06 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2023-08-29 20:13:06 +0200 |
commit | e3c3abf1ebade68a06abb03d098d58afda87b317 (patch) | |
tree | 7115e576aacb832c22131b946aeb0107bf781254 | |
parent | c24231d19cb0bc42a3657a921953408566fcde1c (diff) | |
download | dokuwiki-e3c3abf1ebade68a06abb03d098d58afda87b317.tar.gz dokuwiki-e3c3abf1ebade68a06abb03d098d58afda87b317.zip |
Apply rector fixes to lib/exe
-rw-r--r-- | lib/exe/ajax.php | 8 | ||||
-rw-r--r-- | lib/exe/css.php | 50 | ||||
-rw-r--r-- | lib/exe/detail.php | 4 | ||||
-rw-r--r-- | lib/exe/fetch.php | 16 | ||||
-rw-r--r-- | lib/exe/jquery.php | 10 | ||||
-rw-r--r-- | lib/exe/js.php | 81 | ||||
-rw-r--r-- | lib/exe/manifest.php | 3 | ||||
-rw-r--r-- | lib/exe/mediamanager.php | 8 | ||||
-rw-r--r-- | lib/exe/opensearch.php | 2 | ||||
-rw-r--r-- | lib/exe/taskrunner.php | 3 |
10 files changed, 94 insertions, 91 deletions
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index 5f49e5135..534fe013c 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -1,4 +1,6 @@ <?php +use dokuwiki\Utf8\Clean; +use dokuwiki\Ajax; /** * DokuWiki AJAX call handler * @@ -6,7 +8,7 @@ * @author Andreas Gohr <andi@splitbrain.org> */ -if (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/../../'); +if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../'); require_once(DOKU_INC . 'inc/init.php'); //close session @@ -18,8 +20,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..68aa07bb0 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -5,7 +5,7 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> */ - +use dokuwiki\StyleUtils; use dokuwiki\Cache\Cache; use dokuwiki\Extension\Event; @@ -36,10 +36,10 @@ function css_out(){ 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 = ''; } @@ -48,7 +48,7 @@ function css_out(){ 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 @@ -61,9 +61,9 @@ function css_out(){ // Array of needed files and their web locations, the latter ones // are needed to fix relative paths in the stylesheets - $media_files = array(); + $media_files = []; foreach($mediatypes as $mediatype) { - $files = array(); + $files = []; // load core styles $files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; @@ -80,7 +80,7 @@ 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])) { + if(isset($config_cascade['userstyle'][$mediatype]) && is_array($config_cascade['userstyle'][$mediatype])) { foreach($config_cascade['userstyle'][$mediatype] as $userstyle) { $files[$userstyle] = DOKU_BASE; } @@ -117,7 +117,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 @@ -197,7 +197,7 @@ 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')){ @@ -208,7 +208,7 @@ function css_parseless($css) { return $less->compile($css); } 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)){ @@ -287,13 +287,13 @@ function css_applystyle($css, $replacements) { * @param array $files set of files that define the current mediatype * @return array */ -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 + ]; } /** @@ -366,7 +366,7 @@ function css_filetypes(){ // additional styles when icon available // scan directory for all icons - $exts = array(); + $exts = []; if($dh = opendir(DOKU_INC.'lib/images/fileicons/svg')){ while(false !== ($file = readdir($dh))){ if(preg_match('/(.*?)\.svg$/i',$file, $match)){ @@ -405,7 +405,7 @@ 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) { $this->filepath = $file; @@ -427,8 +427,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; } @@ -441,7 +441,7 @@ class DokuCssFile { 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 +449,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)); } @@ -475,7 +475,7 @@ class DokuCssFile { $match[3] = $this->location . $match[3]; } - return join('',array_slice($match,1)); + return implode('',array_slice($match,1)); } } @@ -518,7 +518,7 @@ function css_datauri($match){ * @return array */ function css_pluginstyles($mediatype='screen'){ - $list = array(); + $list = []; $plugins = plugin_list(); foreach ($plugins as $p){ $list[DOKU_PLUGIN."$p/$mediatype.css"] = DOKU_BASE."lib/plugins/$p/"; diff --git a/lib/exe/detail.php b/lib/exe/detail.php index 4df11fed6..dbe94de64 100644 --- a/lib/exe/detail.php +++ b/lib/exe/detail.php @@ -2,7 +2,7 @@ use dokuwiki\Extension\Event; -if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); +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) @@ -18,7 +18,7 @@ $REV = $INPUT->int('rev'); // "parent" page $INFO = array_merge(pageinfo(),mediainfo()); -$tmp = array(); +$tmp = []; Event::createAndTrigger('DETAIL_STARTED', $tmp); //close session diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php index 1b987ec10..9ce74fc2f 100644 --- a/lib/exe/fetch.php +++ b/lib/exe/fetch.php @@ -5,10 +5,10 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @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'); session_write_close(); //close session @@ -16,7 +16,7 @@ session_write_close(); //close session require_once(DOKU_INC.'inc/fetch.functions.php'); if (defined('SIMPLE_TEST')) { - $INPUT = new \dokuwiki\Input\Input(); + $INPUT = new Input(); } // BEGIN main @@ -31,7 +31,7 @@ if (defined('SIMPLE_TEST')) { //sanitize revision $REV = preg_replace('/[^0-9]/', '', $REV); - list($EXT, $MIME, $DL) = mimetype($MEDIA, false); + [$EXT, $MIME, $DL] = mimetype($MEDIA, false); if($EXT === false) { $EXT = 'unknown'; $MIME = 'application/octet-stream'; @@ -39,10 +39,10 @@ if (defined('SIMPLE_TEST')) { } // check for permissions, preconditions and cache external files - list($STATUS, $STATUSMESSAGE) = checkFileStatus($MEDIA, $FILE, $REV, $WIDTH, $HEIGHT); + [$STATUS, $STATUSMESSAGE] = checkFileStatus($MEDIA, $FILE, $REV, $WIDTH, $HEIGHT); // prepare data for plugin events - $data = array( + $data = [ 'media' => $MEDIA, 'file' => $FILE, 'orig' => $FILE, @@ -63,8 +63,8 @@ if (defined('SIMPLE_TEST')) { 'font-src' => "'self' data:", 'form-action' => "'none'", 'frame-ancestors' => "'self'", - ], - ); + ] + ]; // handle the file status $evt = new Event('FETCH_MEDIA_STATUS', $data); diff --git a/lib/exe/jquery.php b/lib/exe/jquery.php index b8638ecc0..b62fc01fd 100644 --- a/lib/exe/jquery.php +++ b/lib/exe/jquery.php @@ -2,7 +2,7 @@ use dokuwiki\Cache\Cache; -if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/../../'); +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 @@ -22,16 +22,16 @@ 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 = ''; diff --git a/lib/exe/js.php b/lib/exe/js.php index 1d87fb6e5..391432aea 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -5,7 +5,7 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> */ - +use dokuwiki\Utf8\PhpString; use dokuwiki\Cache\Cache; use dokuwiki\Extension\Event; use splitbrain\JSStrip\Exception as JSStripException; @@ -42,32 +42,32 @@ function js_out(){ 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()); @@ -89,7 +89,7 @@ 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 @@ -98,11 +98,10 @@ function js_out(){ // 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() - )).";"; + print "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');". @@ -117,7 +116,7 @@ function js_out(){ 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'); @@ -142,7 +141,7 @@ function js_out(){ 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(); @@ -156,7 +155,7 @@ function js_out(){ 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"; } } @@ -174,7 +173,7 @@ function js_out(){ */ function js_load($file){ if(!file_exists($file)) return; - static $loaded = array(); + static $loaded = []; $data = io_readFile($file); while(preg_match('#/\*\s*DOKUWIKI:include(_once)?\s+([\w\.\-_/]+)\s*\*/#',$data,$match)){ @@ -182,7 +181,7 @@ function js_load($file){ // is it a include_once? if($match[1]){ - $base = \dokuwiki\Utf8\PhpString::basename($ifile); + $base = PhpString::basename($ifile); if(array_key_exists($base, $loaded) && $loaded[$base] === true){ $data = str_replace($match[0], '' ,$data); continue; @@ -212,7 +211,7 @@ function js_load($file){ * @return array */ function js_pluginscripts(){ - $list = array(); + $list = []; $plugins = plugin_list(); foreach ($plugins as $p){ $list[] = DOKU_PLUGIN."$p/script.js"; @@ -232,7 +231,7 @@ function js_pluginscripts(){ */ function js_pluginstrings() { global $conf, $config_cascade; - $pluginstrings = array(); + $pluginstrings = []; $plugins = plugin_list(); foreach($plugins as $p) { $path = DOKU_PLUGIN . $p . '/lang/'; @@ -278,7 +277,7 @@ function js_templatestrings($tpl) { $path = tpl_incdir() . 'lang/'; - $templatestrings = array(); + $templatestrings = []; if(file_exists($path . "en/lang.php")) { include $path . "en/lang.php"; } diff --git a/lib/exe/manifest.php b/lib/exe/manifest.php index 687c1937c..47a8da131 100644 --- a/lib/exe/manifest.php +++ b/lib/exe/manifest.php @@ -1,5 +1,6 @@ <?php +use dokuwiki\Manifest; if (!defined('DOKU_INC')) { define('DOKU_INC', __DIR__ . '/../../'); } @@ -11,5 +12,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..bfcab20c8 100644 --- a/lib/exe/mediamanager.php +++ b/lib/exe/mediamanager.php @@ -2,7 +2,7 @@ use dokuwiki\Extension\Event; - if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); + if(!defined('DOKU_INC')) define('DOKU_INC',__DIR__.'/../../'); define('DOKU_MEDIAMANAGER',1); // for multi uploader: @@ -35,16 +35,16 @@ use dokuwiki\Extension\Event; } global $INFO, $JSINFO; - $INFO = !empty($INFO) ? array_merge($INFO, mediainfo()) : mediainfo(); + $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 = isset($fullscreen) ? $fullscreen : false; + $fullscreen ??= false; - $tmp = array(); + $tmp = []; Event::createAndTrigger('MEDIAMANAGER_STARTED', $tmp); session_write_close(); //close session diff --git a/lib/exe/opensearch.php b/lib/exe/opensearch.php index b00b2b771..d335ae779 100644 --- a/lib/exe/opensearch.php +++ b/lib/exe/opensearch.php @@ -8,7 +8,7 @@ * @author Andreas Gohr <andi@splitbrain.org> */ -if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); +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'); diff --git a/lib/exe/taskrunner.php b/lib/exe/taskrunner.php index 69ab4451a..00898d25b 100644 --- a/lib/exe/taskrunner.php +++ b/lib/exe/taskrunner.php @@ -1,4 +1,5 @@ <?php +use dokuwiki\TaskRunner; /** * DokuWiki indexer * @@ -12,5 +13,5 @@ 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(); |