Apply rector fixes to bin and toplevel

This commit is contained in:
Andreas Gohr 2023-08-30 14:48:22 +02:00
parent bf9be0e394
commit b1f206e1d4
12 changed files with 88 additions and 85 deletions

View File

@ -39,8 +39,10 @@ use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/../inc',
__DIR__ . '/../lib',
__DIR__ . '/../inc/',
__DIR__ . '/../lib/',
__DIR__ . '/../bin/',
__DIR__ . '/../*.php',
]);
$rectorConfig->bootstrapFiles([

View File

@ -3,8 +3,9 @@
use splitbrain\phpcli\CLI;
use splitbrain\phpcli\Options;
use dokuwiki\Utf8\PhpString;
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/');
define('NOSESSION', 1);
require_once(DOKU_INC . 'inc/init.php');
@ -210,14 +211,14 @@ class PageCLI extends CLI {
}
if(empty($localfile)) {
$localfile = getcwd() . '/' . \dokuwiki\Utf8\PhpString::basename($wiki_fn);
$localfile = getcwd() . '/' . PhpString::basename($wiki_fn);
}
if(!file_exists(dirname($localfile))) {
$this->fatal("Directory " . dirname($localfile) . " does not exist");
}
if(stristr(realpath(dirname($localfile)), realpath($conf['datadir'])) !== false) {
if(stristr(realpath(dirname($localfile)), (string) realpath($conf['datadir'])) !== false) {
$this->fatal("Attempt to check out file into data directory - not allowed");
}

View File

@ -4,7 +4,7 @@
use splitbrain\phpcli\CLI;
use splitbrain\phpcli\Options;
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/');
define('NOSESSION', 1);
require_once(DOKU_INC . 'inc/init.php');
@ -109,27 +109,25 @@ class GitToolCLI extends CLI {
* @param array $extensions
*/
public function cmdClone($extensions) {
$errors = array();
$succeeded = array();
$errors = [];
$succeeded = [];
foreach($extensions as $ext) {
$repo = $this->getSourceRepo($ext);
if(!$repo) {
if (!$repo) {
$this->error("could not find a repository for $ext");
$errors[] = $ext;
} elseif ($this->cloneExtension($ext, $repo)) {
$succeeded[] = $ext;
} else {
if($this->cloneExtension($ext, $repo)) {
$succeeded[] = $ext;
} else {
$errors[] = $ext;
}
$errors[] = $ext;
}
}
echo "\n";
if($succeeded) $this->success('successfully cloned the following extensions: ' . join(', ', $succeeded));
if($errors) $this->error('failed to clone the following extensions: ' . join(', ', $errors));
if($succeeded) $this->success('successfully cloned the following extensions: ' . implode(', ', $succeeded));
if($errors) $this->error('failed to clone the following extensions: ' . implode(', ', $errors));
}
/**
@ -138,31 +136,29 @@ class GitToolCLI extends CLI {
* @param array $extensions
*/
public function cmdInstall($extensions) {
$errors = array();
$succeeded = array();
$errors = [];
$succeeded = [];
foreach($extensions as $ext) {
$repo = $this->getSourceRepo($ext);
if(!$repo) {
if (!$repo) {
$this->info("could not find a repository for $ext");
if($this->downloadExtension($ext)) {
$succeeded[] = $ext;
} else {
$errors[] = $ext;
}
} elseif ($this->cloneExtension($ext, $repo)) {
$succeeded[] = $ext;
} else {
if($this->cloneExtension($ext, $repo)) {
$succeeded[] = $ext;
} else {
$errors[] = $ext;
}
$errors[] = $ext;
}
}
echo "\n";
if($succeeded) $this->success('successfully installed the following extensions: ' . join(', ', $succeeded));
if($errors) $this->error('failed to install the following extensions: ' . join(', ', $errors));
if($succeeded) $this->success('successfully installed the following extensions: ' . implode(', ', $succeeded));
if($errors) $this->error('failed to install the following extensions: ' . implode(', ', $errors));
}
/**
@ -174,9 +170,9 @@ class GitToolCLI extends CLI {
public function cmdGit($cmd, $arg) {
$repos = $this->findRepos();
$shell = array_merge(array('git', $cmd), $arg);
$shell = array_merge(['git', $cmd], $arg);
$shell = array_map('escapeshellarg', $shell);
$shell = join(' ', $shell);
$shell = implode(' ', $shell);
foreach($repos as $repo) {
if(!@chdir($repo)) {

View File

@ -4,7 +4,7 @@
use splitbrain\phpcli\CLI;
use splitbrain\phpcli\Options;
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/');
define('NOSESSION', 1);
require_once(DOKU_INC . 'inc/init.php');
@ -62,9 +62,9 @@ class IndexerCLI extends CLI {
*/
protected function update() {
global $conf;
$data = array();
$data = [];
$this->quietecho("Searching pages... ");
search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
search($data, $conf['datadir'], 'search_allpages', ['skipacl' => true]);
$this->quietecho(count($data) . " pages found.\n");
foreach($data as $val) {

View File

@ -5,8 +5,10 @@ use dokuwiki\Extension\PluginController;
use splitbrain\phpcli\CLI;
use splitbrain\phpcli\Colors;
use splitbrain\phpcli\Options;
use dokuwiki\Extension\CLIPlugin;
use splitbrain\phpcli\TableFormatter;
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/');
define('NOSESSION', 1);
require_once(DOKU_INC . 'inc/init.php');
@ -37,7 +39,7 @@ class PluginCLI extends CLI {
if($argv) {
$plugin = $this->loadPlugin($argv[0]);
if($plugin !== null) {
if($plugin instanceof CLIPlugin) {
$plugin->run();
} else {
$this->fatal('Command {cmd} not found.', ['cmd' => $argv[0]]);
@ -62,14 +64,14 @@ class PluginCLI extends CLI {
$list = $plugin_controller->getList('cli');
sort($list);
if(!count($list)) {
if($list === []) {
echo $this->colors->wrap(" No plugins providing CLI components available\n", Colors::C_RED);
} else {
$tf = new \splitbrain\phpcli\TableFormatter($this->colors);
$tf = new TableFormatter($this->colors);
foreach($list as $name) {
$plugin = $this->loadPlugin($name);
if($plugin === null) continue;
if(!$plugin instanceof CLIPlugin) continue;
$info = $plugin->getInfo();
echo $tf->format(
@ -86,7 +88,7 @@ class PluginCLI extends CLI {
* Instantiate a CLI plugin
*
* @param string $name
* @return \dokuwiki\Extension\CLIPlugin|null
* @return CLIPlugin|null
*/
protected function loadPlugin($name) {
if(plugin_isdisabled($name)) return null;

View File

@ -4,7 +4,7 @@
use splitbrain\phpcli\CLI;
use splitbrain\phpcli\Options;
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/');
define('NOSESSION', 1);
require_once(DOKU_INC . 'inc/init.php');
@ -52,7 +52,7 @@ class RenderCLI extends CLI {
// do the action
$source = stream_get_contents(STDIN);
$info = array();
$info = [];
$result = p_render($renderer, p_get_instructions($source), $info);
if(is_null($result)) throw new DokuCLI_Exception("No such renderer $renderer");
echo $result;

View File

@ -4,7 +4,7 @@
use splitbrain\phpcli\CLI;
use splitbrain\phpcli\Options;
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/');
define('NOSESSION', 1);
require_once(DOKU_INC . 'inc/init.php');
@ -52,16 +52,16 @@ class StripLangsCLI extends CLI {
$keep = explode(',', $options->getOpt('keep'));
if(!in_array('en', $keep)) $keep[] = 'en';
} elseif($options->getOpt('english-only')) {
$keep = array('en');
$keep = ['en'];
} else {
echo $options->help();
exit(0);
}
// Kill all language directories in /inc/lang and /lib/plugins besides those in $langs array
$this->stripDirLangs(realpath(dirname(__FILE__) . '/../inc/lang'), $keep);
$this->processExtensions(realpath(dirname(__FILE__) . '/../lib/plugins'), $keep);
$this->processExtensions(realpath(dirname(__FILE__) . '/../lib/tpl'), $keep);
$this->stripDirLangs(realpath(__DIR__ . '/../inc/lang'), $keep);
$this->processExtensions(realpath(__DIR__ . '/../lib/plugins'), $keep);
$this->processExtensions(realpath(__DIR__ . '/../lib/tpl'), $keep);
}
/**
@ -99,7 +99,7 @@ class StripLangsCLI extends CLI {
$dir = dir($path);
while(($cur_dir = $dir->read()) !== false) {
if($cur_dir != '.' and $cur_dir != '..' and is_dir($path . '/' . $cur_dir)) {
if($cur_dir != '.' && $cur_dir != '..' && is_dir($path . '/' . $cur_dir)) {
if(!in_array($cur_dir, $keep_langs, true)) {
io_rmdir($path . '/' . $cur_dir, true);

View File

@ -6,7 +6,7 @@ use dokuwiki\File\PageResolver;
use splitbrain\phpcli\CLI;
use splitbrain\phpcli\Options;
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/');
define('NOSESSION', 1);
require_once(DOKU_INC . 'inc/init.php');
@ -15,14 +15,14 @@ require_once(DOKU_INC . 'inc/init.php');
*/
class WantedPagesCLI extends CLI {
const DIR_CONTINUE = 1;
const DIR_NS = 2;
const DIR_PAGE = 3;
protected const DIR_CONTINUE = 1;
protected const DIR_NS = 2;
protected const DIR_PAGE = 3;
private $skip = false;
private $sort = 'wanted';
private $result = array();
private $result = [];
/**
* Register options and arguments on the given $options object
@ -134,19 +134,16 @@ class WantedPagesCLI extends CLI {
throw new DokuCLI_Exception("Unable to read directory $dir");
}
$pages = array();
$pages = [];
$dh = opendir($dir);
while(false !== ($entry = readdir($dh))) {
$status = $this->dirFilter($entry, $dir);
if($status == WantedPagesCLI::DIR_CONTINUE) {
if ($status == WantedPagesCLI::DIR_CONTINUE) {
continue;
} else if($status == WantedPagesCLI::DIR_NS) {
} elseif ($status == WantedPagesCLI::DIR_NS) {
$pages = array_merge($pages, $this->getPages($dir . '/' . $entry));
} else {
$page = array(
'id' => pathID(substr($dir . '/' . $entry, $trunclen)),
'file' => $dir . '/' . $entry,
);
$page = ['id' => pathID(substr($dir . '/' . $entry, $trunclen)), 'file' => $dir . '/' . $entry];
$pages[] = $page;
}
}
@ -168,7 +165,7 @@ class WantedPagesCLI extends CLI {
if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink')) {
$mid = $resolver->resolveId($ins[1][0]);
if(!page_exists($mid)) {
list($mid) = explode('#', $mid); //record pages without hashes
[$mid] = explode('#', $mid); //record pages without hashes
if($this->sort == 'origin') {
$this->result[$pid][] = $mid;

View File

@ -8,14 +8,15 @@
* @global Input $INPUT
*/
// update message version - always use a string to avoid localized floats!
use dokuwiki\ChangeLog\PageChangeLog;
use dokuwiki\Extension\Event;
// update message version - always use a string to avoid localized floats!
$updateVersion = "55";
// xdebug_start_profiling();
if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/');
if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__.'/');
// define all DokuWiki globals here (needed within test requests but also helps to keep track)
global $ACT, $INPUT, $QUERY, $ID, $REV, $DATE_AT, $IDX,
@ -72,18 +73,20 @@ if($DATE_AT) {
//check for existing $REV related to $DATE_AT
if($DATE_AT) {
$pagelog = new \dokuwiki\ChangeLog\PageChangeLog($ID);
$pagelog = new PageChangeLog($ID);
$rev_t = $pagelog->getLastRevisionAt($DATE_AT);
if($rev_t === '') { //current revision
if ($rev_t === '') {
//current revision
$REV = null;
$DATE_AT = null;
} else if ($rev_t === false) { //page did not exist
} elseif ($rev_t === false) {
//page did not exist
$rev_n = $pagelog->getRelativeRevision($DATE_AT,+1);
msg(
sprintf(
$lang['page_nonexist_rev'],
dformat($DATE_AT),
wl($ID, array('rev' => $rev_n)),
wl($ID, ['rev' => $rev_n]),
dformat($rev_n)
)
);
@ -116,7 +119,7 @@ if($conf['breadcrumbs']) breadcrumbs();
// check upstream
checkUpdateMessages();
$tmp = array(); // No event data
$tmp = []; // No event data
Event::createAndTrigger('DOKUWIKI_STARTED', $tmp);
//close session
@ -125,7 +128,7 @@ session_write_close();
//do the work (picks up what to do from global env)
act_dispatch();
$tmp = array(); // No event data
$tmp = []; // No event data
Event::createAndTrigger('DOKUWIKI_DONE', $tmp);
// xdebug_dump_function_profile(1);

View File

@ -16,7 +16,7 @@ use dokuwiki\ChangeLog\PageChangeLog;
use dokuwiki\Extension\AuthPlugin;
use dokuwiki\Extension\Event;
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
@ -34,7 +34,7 @@ $opt = rss_parseOptions();
// the feed is dynamic - we need a cache for each combo
// (but most people just use the default feed so it's still effective)
$key = join('', array_values($opt)) . '$' . $INPUT->server->str('REMOTE_USER')
$key = implode('', array_values($opt)) . '$' . $INPUT->server->str('REMOTE_USER')
. '$' . $INPUT->server->str('HTTP_HOST') . $INPUT->server->str('SERVER_PORT');
$cache = new Cache($key, '.feed');

View File

@ -13,8 +13,8 @@
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
if (php_sapi_name() != 'cli-server') {
if (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/');
if (PHP_SAPI != 'cli-server') {
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
require_once(DOKU_INC . 'inc/init.php');
send_redirect(wl($conf['start']));
@ -49,7 +49,8 @@ if (preg_match('/^\/_media\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
// existing files
// access limitiations
if (preg_match('/\/([._]ht|README$|VERSION$|COPYING$)/', $_SERVER['SCRIPT_NAME']) or
if (
preg_match('/\/([._]ht|README$|VERSION$|COPYING$)/', $_SERVER['SCRIPT_NAME']) ||
preg_match('/^\/(data|conf|bin|inc)\//', $_SERVER['SCRIPT_NAME'])
) {
header('HTTP/1.1 403 Forbidden');

View File

@ -1,5 +1,6 @@
<?php
use dokuwiki\PassHash;
/*><div style="width:60%; margin: auto; background-color: #fcc;
border: 1px solid #faa; padding: 0.5em 1em;">
<h1 style="font-size: 120%">No PHP Support</h1>
@ -15,7 +16,7 @@
* @author Chris Smith <chris@jalakai.co.uk>
*/
if (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/');
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
if (!defined('DOKU_CONF')) define('DOKU_CONF', DOKU_INC . 'conf/');
if (!defined('DOKU_LOCAL')) define('DOKU_LOCAL', DOKU_INC . 'conf/');
@ -41,7 +42,7 @@ if ($LC && $LC != 'en') {
}
// initialise variables ...
$error = array();
$error = [];
// begin output
header('Content-Type: text/html; charset=utf-8');
@ -158,7 +159,7 @@ function print_form($d)
include(DOKU_CONF . 'license.php');
if (!is_array($d)) $d = array();
if (!is_array($d)) $d = [];
$d = array_map('hsc', $d);
if (!isset($d['acl'])) $d['acl'] = 1;
@ -216,7 +217,7 @@ function print_form($d)
<fieldset>
<p><?php echo $lang['i_license']?></p>
<?php
array_push($license, array('name' => $lang['i_license_none'], 'url' => ''));
$license[] = ['name' => $lang['i_license_none'], 'url' => ''];
if (empty($d['license'])) $d['license'] = 'cc-by-sa';
foreach ($license as $key => $lic) {
echo '<label for="lic_' . $key . '">';
@ -271,7 +272,7 @@ function print_retry()
*/
function check_data(&$d)
{
static $form_default = array(
static $form_default = [
'title' => '',
'acl' => '1',
'superuser' => '',
@ -282,11 +283,11 @@ function check_data(&$d)
'policy' => '0',
'allowreg' => '0',
'license' => 'cc-by-sa'
);
];
global $lang;
global $error;
if (!is_array($d)) $d = array();
if (!is_array($d)) $d = [];
foreach ($d as $k => $v) {
if (is_array($v))
unset($d[$k]);
@ -384,7 +385,7 @@ EOT;
if ($d['acl']) {
// hash the password
$phash = new \dokuwiki\PassHash();
$phash = new PassHash();
$pass = $phash->hash_bcrypt($d['password']);
// create users.auth.php
@ -403,7 +404,7 @@ EOT;
EOT;
// --- user:bcryptpasswordhash:Real Name:email:groups,comma,seperated
$output = $output . "\n" . join(':', [
$output = $output . "\n" . implode(':', [
$d['superuser'],
$pass,
$d['fullname'],
@ -505,11 +506,11 @@ function check_configs()
$ok = true;
$config_files = array(
$config_files = [
'local' => DOKU_LOCAL . 'local.php',
'users' => DOKU_LOCAL . 'users.auth.php',
'auth' => DOKU_LOCAL . 'acl.auth.php'
);
];
// configs shouldn't exist
foreach ($config_files as $file) {
@ -535,7 +536,7 @@ function check_permissions()
global $error;
global $lang;
$dirs = array(
$dirs = [
'conf' => DOKU_LOCAL,
'data' => DOKU_INC . 'data',
'pages' => DOKU_INC . 'data/pages',
@ -548,7 +549,7 @@ function check_permissions()
'locks' => DOKU_INC . 'data/locks',
'index' => DOKU_INC . 'data/index',
'tmp' => DOKU_INC . 'data/tmp'
);
];
$ok = true;
foreach ($dirs as $dir) {
@ -642,7 +643,7 @@ function langsel()
$dh = opendir($dir);
if (!$dh) return;
$langs = array();
$langs = [];
while (($file = readdir($dh)) !== false) {
if (preg_match('/^[\._]/', $file)) continue;
if (is_dir($dir . '/' . $file) && file_exists($dir . '/' . $file . '/lang.php')) {