aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/plugins
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2023-08-30 11:45:19 +0200
committerAndreas Gohr <andi@splitbrain.org>2023-08-30 11:45:19 +0200
commit54cc7aa41e0f453bd6887b0e79242a139d84a47a (patch)
tree6f13746d09ac261552de8ab3db1bc1ff13c7a1f0 /lib/plugins
parentfe2dcfd59ce1d20fda206fc686ee7860088d80a2 (diff)
downloaddokuwiki-54cc7aa41e0f453bd6887b0e79242a139d84a47a.tar.gz
dokuwiki-54cc7aa41e0f453bd6887b0e79242a139d84a47a.zip
Apply rector fixes to the rest of lib/plugin
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/action.php4
-rw-r--r--lib/plugins/admin.php4
-rw-r--r--lib/plugins/auth.php4
-rw-r--r--lib/plugins/cli.php4
-rw-r--r--lib/plugins/extension/cli.php1
-rw-r--r--lib/plugins/info/syntax.php29
-rw-r--r--lib/plugins/logviewer/admin.php11
-rw-r--r--lib/plugins/popularity/action.php2
-rw-r--r--lib/plugins/popularity/admin.php22
-rw-r--r--lib/plugins/popularity/helper.php20
-rw-r--r--lib/plugins/remote.php4
-rw-r--r--lib/plugins/revert/admin.php10
-rw-r--r--lib/plugins/styling/admin.php5
-rw-r--r--lib/plugins/styling/popup.php4
-rw-r--r--lib/plugins/syntax.php4
-rw-r--r--lib/plugins/testing/action.php2
-rw-r--r--lib/plugins/usermanager/admin.php138
-rw-r--r--lib/plugins/usermanager/cli.php42
18 files changed, 154 insertions, 156 deletions
diff --git a/lib/plugins/action.php b/lib/plugins/action.php
index 5bf8da91e..0dff900ad 100644
--- a/lib/plugins/action.php
+++ b/lib/plugins/action.php
@@ -1,4 +1,6 @@
<?php
-\dokuwiki\Debug\DebugHelper::dbgDeprecatedFunction(
+
+use dokuwiki\Debug\DebugHelper;
+DebugHelper::dbgDeprecatedFunction(
'Autoloading', 1, 'require(' . basename(__FILE__) . ')'
);
diff --git a/lib/plugins/admin.php b/lib/plugins/admin.php
index 5bf8da91e..0dff900ad 100644
--- a/lib/plugins/admin.php
+++ b/lib/plugins/admin.php
@@ -1,4 +1,6 @@
<?php
-\dokuwiki\Debug\DebugHelper::dbgDeprecatedFunction(
+
+use dokuwiki\Debug\DebugHelper;
+DebugHelper::dbgDeprecatedFunction(
'Autoloading', 1, 'require(' . basename(__FILE__) . ')'
);
diff --git a/lib/plugins/auth.php b/lib/plugins/auth.php
index 5bf8da91e..0dff900ad 100644
--- a/lib/plugins/auth.php
+++ b/lib/plugins/auth.php
@@ -1,4 +1,6 @@
<?php
-\dokuwiki\Debug\DebugHelper::dbgDeprecatedFunction(
+
+use dokuwiki\Debug\DebugHelper;
+DebugHelper::dbgDeprecatedFunction(
'Autoloading', 1, 'require(' . basename(__FILE__) . ')'
);
diff --git a/lib/plugins/cli.php b/lib/plugins/cli.php
index 5bf8da91e..0dff900ad 100644
--- a/lib/plugins/cli.php
+++ b/lib/plugins/cli.php
@@ -1,4 +1,6 @@
<?php
-\dokuwiki\Debug\DebugHelper::dbgDeprecatedFunction(
+
+use dokuwiki\Debug\DebugHelper;
+DebugHelper::dbgDeprecatedFunction(
'Autoloading', 1, 'require(' . basename(__FILE__) . ')'
);
diff --git a/lib/plugins/extension/cli.php b/lib/plugins/extension/cli.php
index fed54e6bd..9861b1ca3 100644
--- a/lib/plugins/extension/cli.php
+++ b/lib/plugins/extension/cli.php
@@ -304,6 +304,7 @@ class cli_plugin_extension extends DokuWiki_CLI_Plugin
$pluginlist = $plugin_controller->getList('', true);
$tpllist = glob(DOKU_INC . 'lib/tpl/*', GLOB_ONLYDIR);
$tpllist = array_map(static fn($path) => 'template:' . basename($path), $tpllist);
+
$list = array_merge($pluginlist, $tpllist);
sort($list);
return $list;
diff --git a/lib/plugins/info/syntax.php b/lib/plugins/info/syntax.php
index 8d86c220a..4e8633b0f 100644
--- a/lib/plugins/info/syntax.php
+++ b/lib/plugins/info/syntax.php
@@ -1,5 +1,6 @@
<?php
+use dokuwiki\Extension\PluginInterface;
/**
* Info Plugin: Displays information about various DokuWiki internals
*
@@ -54,7 +55,7 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin
public function handle($match, $state, $pos, Doku_Handler $handler)
{
$match = substr($match, 7, -2); //strip ~~INFO: from start and ~~ from end
- return array(strtolower($match));
+ return [strtolower($match)];
}
/**
@@ -127,12 +128,13 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin
{
global $lang;
$plugins = plugin_list($type);
- $plginfo = array();
+ $plginfo = [];
// remove subparts
foreach ($plugins as $p) {
- if (!$po = plugin_load($type, $p)) continue;
- list($name,/* $part */) = explode('_', $p, 2);
+ $po = plugin_load($type, $p);
+ if (! $po instanceof PluginInterface) continue;
+ [$name, ] = explode('_', $p, 2);
$plginfo[$name] = $po->getInfo();
}
@@ -167,7 +169,8 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin
{
$plugins = plugin_list('helper');
foreach ($plugins as $p) {
- if (!$po = plugin_load('helper', $p)) continue;
+ $po = plugin_load('helper', $p);
+ if (!$po instanceof PluginInterface) continue;
if (!method_exists($po, 'getMethods')) continue;
$methods = $po->getMethods();
@@ -176,7 +179,7 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin
$hid = $this->addToToc($info['name'], 2, $renderer);
$doc = '<h2><a name="' . $hid . '" id="' . $hid . '">' . hsc($info['name']) . '</a></h2>';
$doc .= '<div class="level2">';
- $doc .= '<p>' . strtr(hsc($info['desc']), array("\n" => "<br />")) . '</p>';
+ $doc .= '<p>' . strtr(hsc($info['desc']), ["\n" => "<br />"]) . '</p>';
$doc .= '<pre class="code">$' . $p . " = plugin_load('helper', '" . $p . "');</pre>";
$doc .= '</div>';
foreach ($methods as $method) {
@@ -190,11 +193,11 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin
if ($method['params']) {
$c = count($method['params']);
$doc .= '<tr><th rowspan="' . $c . '">Parameters</th><td>';
- $params = array();
+ $params = [];
foreach ($method['params'] as $desc => $type) {
$params[] = hsc($desc) . '</td><td>' . hsc($type);
}
- $doc .= join('</td></tr><tr><td>', $params) . '</td></tr>';
+ $doc .= implode('</td></tr><tr><td>', $params) . '</td></tr>';
}
if ($method['return']) {
$doc .= '<tr><th>Return value</th><td>' . hsc(key($method['return'])) .
@@ -226,7 +229,7 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin
$doc .= $mode;
$doc .= '</td>';
$doc .= '<td class="leftalign">';
- $doc .= join(', ', $modes);
+ $doc .= implode(', ', $modes);
$doc .= '</td>';
$doc .= '</tr>';
}
@@ -243,7 +246,7 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin
{
$modes = p_get_parsermodes();
- $compactmodes = array();
+ $compactmodes = [];
foreach ($modes as $mode) {
$compactmodes[$mode['sort']][] = $mode['mode'];
}
@@ -325,12 +328,12 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin
$hid = '';
if (($level >= $conf['toptoclevel']) && ($level <= $conf['maxtoclevel'])) {
$hid = $renderer->_headerToLink($text, true);
- $renderer->toc[] = array(
+ $renderer->toc[] = [
'hid' => $hid,
'title' => $text,
'type' => 'ul',
- 'level' => $level - $conf['toptoclevel'] + 1,
- );
+ 'level' => $level - $conf['toptoclevel'] + 1
+ ];
}
return $hid;
}
diff --git a/lib/plugins/logviewer/admin.php b/lib/plugins/logviewer/admin.php
index 335af4c78..4246e3d61 100644
--- a/lib/plugins/logviewer/admin.php
+++ b/lib/plugins/logviewer/admin.php
@@ -1,5 +1,6 @@
<?php
+use dokuwiki\Form\Form;
use dokuwiki\Logger;
/**
@@ -10,7 +11,7 @@ use dokuwiki\Logger;
*/
class admin_plugin_logviewer extends DokuWiki_Admin_Plugin
{
- const MAX_READ_SIZE = 1048576; // 1 MB
+ const MAX_READ_SIZE = 1_048_576; // 1 MB
protected $facilities;
protected $facility;
@@ -56,7 +57,7 @@ class admin_plugin_logviewer extends DokuWiki_Admin_Plugin
{
global $ID;
- $form = new dokuwiki\Form\Form(['method' => 'GET']);
+ $form = new Form(['method' => 'GET']);
$form->setHiddenField('do', 'admin');
$form->setHiddenField('page', 'logviewer');
$form->setHiddenField('facility', $this->facility);
@@ -156,7 +157,7 @@ class admin_plugin_logviewer extends DokuWiki_Admin_Plugin
if ($size >= self::MAX_READ_SIZE) {
array_shift($lines); // Discard the first line
- while (!empty($lines) && (substr($lines[0], 0, 2) === ' ')) {
+ while ($lines !== [] && (substr($lines[0], 0, 2) === ' ')) {
array_shift($lines); // Discard indented lines
}
@@ -191,10 +192,10 @@ class admin_plugin_logviewer extends DokuWiki_Admin_Plugin
$line = $lines[$i] ?? '';
}
echo '</dd>';
- $i -= 1; // rewind the counter
+ --$i; // rewind the counter
} else {
// other lines are actual log lines in three parts
- list($dt, $file, $msg) = sexplode("\t", $line, 3, '');
+ [$dt, $file, $msg] = sexplode("\t", $line, 3, '');
echo '<dt>';
echo '<span class="datetime">' . hsc($dt) . '</span>';
echo '<span class="log">';
diff --git a/lib/plugins/popularity/action.php b/lib/plugins/popularity/action.php
index fac610735..a511a5e9e 100644
--- a/lib/plugins/popularity/action.php
+++ b/lib/plugins/popularity/action.php
@@ -21,7 +21,7 @@ class action_plugin_popularity extends DokuWiki_Action_Plugin
/** @inheritdoc */
public function register(Doku_Event_Handler $controller)
{
- $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, 'autosubmit', array());
+ $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, 'autosubmit', []);
}
/**
diff --git a/lib/plugins/popularity/admin.php b/lib/plugins/popularity/admin.php
index 61d8cc3bf..81e35b77e 100644
--- a/lib/plugins/popularity/admin.php
+++ b/lib/plugins/popularity/admin.php
@@ -10,7 +10,7 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin
/** @var helper_plugin_popularity */
protected $helper;
- protected $sentStatus = null;
+ protected $sentStatus;
/**
* admin_plugin_popularity constructor.
@@ -88,7 +88,6 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin
if (! $INPUT->has('data')) {
echo $this->locale_xhtml('intro');
-
//If there was an error the last time we tried to autosubmit, warn the user
if ($this->helper->isAutoSubmitEnabled()) {
if (file_exists($this->helper->autosubmitErrorFile)) {
@@ -96,26 +95,21 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin
echo io_readFile($this->helper->autosubmitErrorFile);
}
}
-
flush();
echo $this->buildForm('server');
-
//Print the last time the data was sent
$lastSent = $this->helper->lastSentTime();
if ($lastSent !== 0) {
echo $this->getLang('lastSent') . ' ' . datetime_h($lastSent);
}
+ } elseif ($this->sentStatus === '') {
+ //If we successfully send the data
+ echo $this->locale_xhtml('submitted');
} else {
- //If we just submitted the form
- if ($this->sentStatus === '') {
- //If we successfully sent the data
- echo $this->locale_xhtml('submitted');
- } else {
- //If we failed to submit the data, try directly with the browser
- echo $this->getLang('submissionFailed') . $this->sentStatus . '<br />';
- echo $this->getLang('submitDirectly');
- echo $this->buildForm('browser', $INPUT->str('data'));
- }
+ //If we failed to submit the data, try directly with the browser
+ echo $this->getLang('submissionFailed') . $this->sentStatus . '<br />';
+ echo $this->getLang('submitDirectly');
+ echo $this->buildForm('browser', $INPUT->str('data'));
}
}
diff --git a/lib/plugins/popularity/helper.php b/lib/plugins/popularity/helper.php
index 506126a35..62fc905fc 100644
--- a/lib/plugins/popularity/helper.php
+++ b/lib/plugins/popularity/helper.php
@@ -64,7 +64,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
{
$error = '';
$httpClient = new DokuHTTPClient();
- $status = $httpClient->sendRequest($this->submitUrl, array('data' => $data), 'POST');
+ $status = $httpClient->sendRequest($this->submitUrl, ['data' => $data], 'POST');
if (! $status) {
$error = $httpClient->error;
}
@@ -132,7 +132,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
global $conf;
/** @var $auth DokuWiki_Auth_Plugin */
global $auth;
- $data = array();
+ $data = [];
$phptime = ini_get('max_execution_time');
@set_time_limit(0);
$pluginInfo = $this->getInfo();
@@ -152,7 +152,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
// number and size of pages
$list = $this->initEmptySearchList();
- search($list, $conf['datadir'], array($this, 'searchCountCallback'), array('all'=>false), '');
+ search($list, $conf['datadir'], [$this, 'searchCountCallback'], ['all'=>false], '');
$data['page_count'] = $list['file_count'];
$data['page_size'] = $list['file_size'];
$data['page_biggest'] = $list['file_max'];
@@ -165,7 +165,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
// number and size of media
$list = $this->initEmptySearchList();
- search($list, $conf['mediadir'], array($this, 'searchCountCallback'), array('all'=>true));
+ search($list, $conf['mediadir'], [$this, 'searchCountCallback'], ['all'=>true]);
$data['media_count'] = $list['file_count'];
$data['media_size'] = $list['file_size'];
$data['media_biggest'] = $list['file_max'];
@@ -177,7 +177,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
// number and size of cache
$list = $this->initEmptySearchList();
- search($list, $conf['cachedir'], array($this, 'searchCountCallback'), array('all'=>true));
+ search($list, $conf['cachedir'], [$this, 'searchCountCallback'], ['all'=>true]);
$data['cache_count'] = $list['file_count'];
$data['cache_size'] = $list['file_size'];
$data['cache_biggest'] = $list['file_max'];
@@ -187,7 +187,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
// number and size of index
$list = $this->initEmptySearchList();
- search($list, $conf['indexdir'], array($this, 'searchCountCallback'), array('all'=>true));
+ search($list, $conf['indexdir'], [$this, 'searchCountCallback'], ['all'=>true]);
$data['index_count'] = $list['file_count'];
$data['index_size'] = $list['file_size'];
$data['index_biggest'] = $list['file_max'];
@@ -197,7 +197,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
// number and size of meta
$list = $this->initEmptySearchList();
- search($list, $conf['metadir'], array($this, 'searchCountCallback'), array('all'=>true));
+ search($list, $conf['metadir'], [$this, 'searchCountCallback'], ['all'=>true]);
$data['meta_count'] = $list['file_count'];
$data['meta_size'] = $list['file_size'];
$data['meta_biggest'] = $list['file_max'];
@@ -207,7 +207,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
// number and size of attic
$list = $this->initEmptySearchList();
- search($list, $conf['olddir'], array($this, 'searchCountCallback'), array('all'=>true));
+ search($list, $conf['olddir'], [$this, 'searchCountCallback'], ['all'=>true]);
$data['attic_count'] = $list['file_count'];
$data['attic_size'] = $list['file_size'];
$data['attic_biggest'] = $list['file_max'];
@@ -244,7 +244,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
$data['os'] = PHP_OS;
$data['webserver'] = $_SERVER['SERVER_SOFTWARE'];
$data['php_version'] = phpversion();
- $data['php_sapi'] = php_sapi_name();
+ $data['php_sapi'] = PHP_SAPI;
$data['php_memory'] = php_to_byte(ini_get('memory_limit'));
$data['php_exectime'] = $phptime;
$data['php_extension'] = get_loaded_extensions();
@@ -262,7 +262,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
*/
protected function addPluginUsageData(&$data)
{
- $pluginsData = array();
+ $pluginsData = [];
Event::createAndTrigger('PLUGIN_POPULARITY_DATA_SETUP', $pluginsData);
foreach ($pluginsData as $plugin => $d) {
if (is_array($d)) {
diff --git a/lib/plugins/remote.php b/lib/plugins/remote.php
index 5bf8da91e..0dff900ad 100644
--- a/lib/plugins/remote.php
+++ b/lib/plugins/remote.php
@@ -1,4 +1,6 @@
<?php
-\dokuwiki\Debug\DebugHelper::dbgDeprecatedFunction(
+
+use dokuwiki\Debug\DebugHelper;
+DebugHelper::dbgDeprecatedFunction(
'Autoloading', 1, 'require(' . basename(__FILE__) . ')'
);
diff --git a/lib/plugins/revert/admin.php b/lib/plugins/revert/admin.php
index 2d11dc05a..ad681b393 100644
--- a/lib/plugins/revert/admin.php
+++ b/lib/plugins/revert/admin.php
@@ -93,10 +93,10 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin
$data = '';
$pagelog = new PageChangeLog($id);
$old = $pagelog->getRevisions(0, $this->max_revs);
- if (count($old)) {
+ if ($old !== []) {
foreach ($old as $REV) {
$data = rawWiki($id, $REV);
- if (strpos($data, $filter) === false) break;
+ if (strpos($data, (string) $filter) === false) break;
}
}
@@ -133,7 +133,7 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin
$cnt = 0;
foreach ($recents as $recent) {
if ($filter) {
- if (strpos(rawWiki($recent['id']), $filter) === false) continue;
+ if (strpos(rawWiki($recent['id']), (string) $filter) === false) continue;
}
$cnt++;
@@ -146,7 +146,7 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin
echo ' <label for="revert__'.$cnt.'">'.$date.'</label> ';
echo '<a href="'.wl($recent['id'], "do=diff").'">';
- $p = array();
+ $p = [];
$p['src'] = DOKU_BASE.'lib/images/diff.png';
$p['width'] = 15;
$p['height'] = 11;
@@ -157,7 +157,7 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin
echo '</a> ';
echo '<a href="'.wl($recent['id'], "do=revisions").'">';
- $p = array();
+ $p = [];
$p['src'] = DOKU_BASE.'lib/images/history.png';
$p['width'] = 12;
$p['height'] = 14;
diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php
index 08c9afdc2..2e938b291 100644
--- a/lib/plugins/styling/admin.php
+++ b/lib/plugins/styling/admin.php
@@ -1,4 +1,5 @@
<?php
+use dokuwiki\StyleUtils;
/**
* DokuWiki Plugin styling (Admin Component)
*
@@ -61,14 +62,14 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin
global $conf;
global $ID;
- $styleUtil = new \dokuwiki\StyleUtils($conf['template'], true, true);
+ $styleUtil = new StyleUtils($conf['template'], true, true);
$styleini = $styleUtil->cssStyleini();
$replacements = $styleini['replacements'];
if ($this->ispopup) {
$target = DOKU_BASE.'lib/plugins/styling/popup.php';
} else {
- $target = wl($ID, array('do' => 'admin', 'page' => 'styling'));
+ $target = wl($ID, ['do' => 'admin', 'page' => 'styling']);
}
if (empty($replacements)) {
diff --git a/lib/plugins/styling/popup.php b/lib/plugins/styling/popup.php
index 079062e43..0fef79ce3 100644
--- a/lib/plugins/styling/popup.php
+++ b/lib/plugins/styling/popup.php
@@ -1,6 +1,6 @@
<?php
// phpcs:disable PSR1.Files.SideEffects
-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
session_write_close();
@@ -23,7 +23,7 @@ $plugin->handle();
<title><?php echo $plugin->getLang('menu') ?></title>
<?php tpl_metaheaders(false) ?>
<meta name="viewport" content="width=device-width,initial-scale=1" />
- <?php echo tpl_favicon(array('favicon')) ?>
+ <?php echo tpl_favicon(['favicon']) ?>
</head>
<body class="dokuwiki">
<?php $plugin->html() ?>
diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php
index 5bf8da91e..0dff900ad 100644
--- a/lib/plugins/syntax.php
+++ b/lib/plugins/syntax.php
@@ -1,4 +1,6 @@
<?php
-\dokuwiki\Debug\DebugHelper::dbgDeprecatedFunction(
+
+use dokuwiki\Debug\DebugHelper;
+DebugHelper::dbgDeprecatedFunction(
'Autoloading', 1, 'require(' . basename(__FILE__) . ')'
);
diff --git a/lib/plugins/testing/action.php b/lib/plugins/testing/action.php
index 09b84262e..965b55e3c 100644
--- a/lib/plugins/testing/action.php
+++ b/lib/plugins/testing/action.php
@@ -17,7 +17,7 @@ class action_plugin_testing extends DokuWiki_Action_Plugin {
}
public function dokuwikiStarted() {
- $param = array();
+ $param = [];
Event::createAndTrigger('TESTING_PLUGIN_INSTALLED', $param);
msg('The testing plugin is enabled and should be disabled.',-1);
}
diff --git a/lib/plugins/usermanager/admin.php b/lib/plugins/usermanager/admin.php
index 423467133..d4562b0ea 100644
--- a/lib/plugins/usermanager/admin.php
+++ b/lib/plugins/usermanager/admin.php
@@ -1,4 +1,6 @@
<?php
+
+use dokuwiki\Utf8\Clean;
/*
* User Manager
*
@@ -10,7 +12,6 @@
* @author neolao <neolao@neolao.com>
* @author Chris Smith <chris@jalakai.co.uk>
*/
-
/**
* All DokuWiki plugins to extend the admin function
* need to inherit from this class
@@ -19,16 +20,16 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
{
const IMAGE_DIR = DOKU_BASE.'lib/plugins/usermanager/images/';
- protected $auth = null; // auth object
+ protected $auth; // auth object
protected $users_total = 0; // number of registered users
- protected $filter = array(); // user selection filter(s)
+ protected $filter = []; // user selection filter(s)
protected $start = 0; // index of first user to be displayed
protected $last = 0; // index of the last user to be displayed
protected $pagesize = 20; // number of users to list on one page
protected $edit_user = ''; // set to user selected for editing
- protected $edit_userdata = array();
+ protected $edit_userdata = [];
protected $disabled = ''; // if disabled set to explanatory string
- protected $import_failures = array();
+ protected $import_failures = [];
protected $lastdisabled = false; // set to true if last user is unknown and last button is hence buggy
/**
@@ -265,15 +266,15 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
* @var string $mail
* @var array $grps
*/
- $groups = join(', ', $grps);
+ $groups = implode(', ', $grps);
ptln(" <tr class=\"user_info\">");
ptln(" <td class=\"centeralign\"><input type=\"checkbox\" name=\"delete[".hsc($user).
"]\" ".$delete_disable." /></td>");
if ($editable) {
- ptln(" <td><a href=\"".wl($ID, array('fn[edit]['.$user.']' => 1,
- 'do' => 'admin',
- 'page' => 'usermanager',
- 'sectok' => getSecurityToken())).
+ ptln(" <td><a href=\"".wl($ID, ['fn[edit]['.$user.']' => 1,
+ 'do' => 'admin',
+ 'page' => 'usermanager',
+ 'sectok' => getSecurityToken()]).
"\" title=\"".$this->lang['edit_prompt']."\">".hsc($user)."</a></td>");
} else {
ptln(" <td>".hsc($user)."</td>");
@@ -324,7 +325,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
print $this->locale_xhtml('add');
ptln(" <div class=\"level2\">");
- $this->htmlUserForm('add', null, array(), 4);
+ $this->htmlUserForm('add', null, [], 4);
ptln(" </div>");
ptln("</div>");
@@ -374,18 +375,19 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
* @param array $userdata array with name, mail, pass and grps
* @param int $indent
*/
- protected function htmlUserForm($cmd, $user = '', $userdata = array(), $indent = 0)
+ protected function htmlUserForm($cmd, $user = '', $userdata = [], $indent = 0)
{
global $conf;
global $ID;
global $lang;
-
- $name = $mail = $groups = '';
- $notes = array();
+ $name = '';
+ $mail = '';
+ $groups = '';
+ $notes = [];
if ($user) {
extract($userdata);
- if (!empty($grps)) $groups = join(',', $grps);
+ if (!empty($grps)) $groups = implode(',', $grps);
} else {
$notes[] = sprintf($this->lang['note_group'], $conf['defaultgroup']);
}
@@ -579,7 +581,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
{
global $ID;
- $failure_download_link = wl($ID, array('do'=>'admin','page'=>'usermanager','fn[importfails]'=>1));
+ $failure_download_link = wl($ID, ['do'=>'admin', 'page'=>'usermanager', 'fn[importfails]'=>1]);
ptln('<div class="level2 import_users">', $indent);
print $this->locale_xhtml('import');
@@ -639,7 +641,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
if (!checkSecurityToken()) return false;
if (!$this->auth->canDo('addUser')) return false;
- list($user,$pass,$name,$mail,$grps,$passconfirm) = $this->retrieveUser();
+ [$user, $pass, $name, $mail, $grps, $passconfirm] = $this->retrieveUser();
if (empty($user)) return false;
if ($this->auth->canDo('modPass')) {
@@ -651,19 +653,15 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
msg($this->lang['addUser_error_missing_pass'], -1);
return false;
}
- } else {
- if (!$this->verifyPassword($pass, $passconfirm)) {
- msg($this->lang['add_fail'], -1);
- msg($this->lang['addUser_error_pass_not_identical'], -1);
- return false;
- }
- }
- } else {
- if (!empty($pass)) {
+ } elseif (!$this->verifyPassword($pass, $passconfirm)) {
msg($this->lang['add_fail'], -1);
- msg($this->lang['addUser_error_modPass_disabled'], -1);
+ msg($this->lang['addUser_error_pass_not_identical'], -1);
return false;
}
+ } elseif (!empty($pass)) {
+ msg($this->lang['add_fail'], -1);
+ msg($this->lang['addUser_error_modPass_disabled'], -1);
+ return false;
}
if ($this->auth->canDo('modName')) {
@@ -672,12 +670,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
msg($this->lang['addUser_error_name_missing'], -1);
return false;
}
- } else {
- if (!empty($name)) {
- msg($this->lang['add_fail'], -1);
- msg($this->lang['addUser_error_modName_disabled'], -1);
- return false;
- }
+ } elseif (!empty($name)) {
+ msg($this->lang['add_fail'], -1);
+ msg($this->lang['addUser_error_modName_disabled'], -1);
+ return false;
}
if ($this->auth->canDo('modMail')) {
@@ -686,15 +682,13 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
msg($this->lang['addUser_error_mail_missing'], -1);
return false;
}
- } else {
- if (!empty($mail)) {
- msg($this->lang['add_fail'], -1);
- msg($this->lang['addUser_error_modMail_disabled'], -1);
- return false;
- }
+ } elseif (!empty($mail)) {
+ msg($this->lang['add_fail'], -1);
+ msg($this->lang['addUser_error_modMail_disabled'], -1);
+ return false;
}
- if ($ok = $this->auth->triggerUserMod('create', array($user, $pass, $name, $mail, $grps))) {
+ if ($ok = $this->auth->triggerUserMod('create', [$user, $pass, $name, $mail, $grps])) {
msg($this->lang['add_ok'], 1);
if ($INPUT->has('usernotify') && $pass) {
@@ -729,7 +723,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
return false;
}
- $count = $this->auth->triggerUserMod('delete', array($selected));
+ $count = $this->auth->triggerUserMod('delete', [$selected]);
if ($count == count($selected)) {
$text = str_replace('%d', $count, $this->lang['delete_ok']);
msg("$text.", 1);
@@ -787,10 +781,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
$oldinfo = $this->auth->getUserData($olduser);
// get new user data subject to change
- list($newuser,$newpass,$newname,$newmail,$newgrps,$passconfirm) = $this->retrieveUser();
+ [$newuser, $newpass, $newname, $newmail, $newgrps, $passconfirm] = $this->retrieveUser();
if (empty($newuser)) return false;
- $changes = array();
+ $changes = [];
if ($newuser != $olduser) {
if (!$this->auth->canDo('modLogin')) { // sanity check, shouldn't be possible
msg($this->lang['update_fail'], -1);
@@ -812,11 +806,9 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
} else {
return false;
}
- } else {
+ } elseif ($INPUT->has('usernotify')) {
// no new password supplied, check if we need to generate one (or it stays unchanged)
- if ($INPUT->has('usernotify')) {
- $changes['pass'] = auth_pwgen($olduser);
- }
+ $changes['pass'] = auth_pwgen($olduser);
}
}
@@ -830,7 +822,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
$changes['grps'] = $newgrps;
}
- if ($ok = $this->auth->triggerUserMod('modify', array($olduser, $changes))) {
+ if ($ok = $this->auth->triggerUserMod('modify', [$olduser, $changes])) {
msg($this->lang['update_ok'], 1);
if ($INPUT->has('usernotify') && !empty($changes['pass'])) {
@@ -866,10 +858,8 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
if ($status_alert) {
msg($this->lang['notify_ok'], 1);
}
- } else {
- if ($status_alert) {
- msg($this->lang['notify_fail'], -1);
- }
+ } elseif ($status_alert) {
+ msg($this->lang['notify_fail'], -1);
}
return $sent;
@@ -914,7 +904,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
global $auth;
global $INPUT;
- $user = array();
+ $user = [];
$user[0] = ($clean) ? $auth->cleanUser($INPUT->str('userid')) : $INPUT->str('userid');
$user[1] = $INPUT->str('userpass');
$user[2] = $INPUT->str('username');
@@ -923,10 +913,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
$user[5] = $INPUT->str('userpass2'); // repeated password for confirmation
$user[4] = array_map('trim', $user[4]);
- if ($clean) $user[4] = array_map(array($auth,'cleanGroup'), $user[4]);
+ if ($clean) $user[4] = array_map([$auth, 'cleanGroup'], $user[4]);
$user[4] = array_filter($user[4]);
$user[4] = array_unique($user[4]);
- if (!count($user[4])) $user[4] = null;
+ if ($user[4] === []) $user[4] = null;
return $user;
}
@@ -939,15 +929,15 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
protected function setFilter($op)
{
- $this->filter = array();
+ $this->filter = [];
if ($op == 'new') {
- list($user,/* $pass */,$name,$mail,$grps) = $this->retrieveUser(false);
+ [$user, , $name, $mail, $grps] = $this->retrieveUser(false);
if (!empty($user)) $this->filter['user'] = $user;
if (!empty($name)) $this->filter['name'] = $name;
if (!empty($mail)) $this->filter['mail'] = $mail;
- if (!empty($grps)) $this->filter['grps'] = join('|', $grps);
+ if (!empty($grps)) $this->filter['grps'] = implode('|', $grps);
}
}
@@ -963,7 +953,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
$t_filter = $INPUT->arr('filter');
// messy, but this way we ensure we aren't getting any additional crap from malicious users
- $filter = array();
+ $filter = [];
if (isset($t_filter['user'])) $filter['user'] = $t_filter['user'];
if (isset($t_filter['name'])) $filter['name'] = $t_filter['name'];
@@ -997,7 +987,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
$disabled = 'disabled="disabled"';
- $buttons = array();
+ $buttons = [];
$buttons['start'] = $buttons['prev'] = ($this->start == 0) ? $disabled : '';
if ($this->users_total == -1) {
@@ -1022,12 +1012,12 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
{
// list of users for export - based on current filter criteria
$user_list = $this->auth->retrieveUsers(0, 0, $this->filter);
- $column_headings = array(
+ $column_headings = [
$this->lang["user_id"],
$this->lang["user_name"],
$this->lang["user_mail"],
$this->lang["user_groups"]
- );
+ ];
// ==============================================================================================
// GENERATE OUTPUT
@@ -1041,7 +1031,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
$fd = fopen('php://output', 'w');
fputcsv($fd, $column_headings);
foreach ($user_list as $user => $info) {
- $line = array($user, $info['name'], $info['mail'], join(',', $info['grps']));
+ $line = [$user, $info['name'], $info['mail'], implode(',', $info['grps'])];
fputcsv($fd, $line);
}
fclose($fd);
@@ -1073,14 +1063,14 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
return false;
}
// retrieve users from the file
- $this->import_failures = array();
+ $this->import_failures = [];
$import_success_count = 0;
$import_fail_count = 0;
$line = 0;
$fd = fopen($_FILES['import']['tmp_name'], 'r');
if ($fd) {
while ($csv = fgets($fd)) {
- if (!\dokuwiki\Utf8\Clean::isUtf8($csv)) {
+ if (!Clean::isUtf8($csv)) {
$csv = utf8_encode($csv);
}
$raw = str_getcsv($csv);
@@ -1092,7 +1082,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
if (count($raw) < 4) { // need at least four fields
$import_fail_count++;
$error = sprintf($this->lang['import_error_fields'], count($raw));
- $this->import_failures[$line] = array('error' => $error, 'user' => $raw, 'orig' => $csv);
+ $this->import_failures[$line] = ['error' => $error, 'user' => $raw, 'orig' => $csv];
continue;
}
array_splice($raw, 1, 0, auth_pwgen()); // splice in a generated password
@@ -1106,7 +1096,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
} else {
$import_fail_count++;
array_splice($raw, 1, 1); // remove the spliced in password
- $this->import_failures[$line] = array('error' => $error, 'user' => $raw, 'orig' => $csv);
+ $this->import_failures[$line] = ['error' => $error, 'user' => $raw, 'orig' => $csv];
}
}
msg(
@@ -1152,7 +1142,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
$INPUT->set('usergroups', $candidate[4]);
$cleaned = $this->retrieveUser();
- list($user,/* $pass */,$name,$mail,/* $grps */) = $cleaned;
+ [$user, /* pass */ , $name, $mail, /* grps */ ] = $cleaned;
if (empty($user)) {
$error = $this->lang['import_error_baduserid'];
return false;
@@ -1170,11 +1160,9 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
$error = $this->lang['import_error_badmail'];
return false;
}
- } else {
- if (!empty($mail)) {
- $error = $this->lang['import_error_badmail'];
- return false;
- }
+ } elseif (!empty($mail)) {
+ $error = $this->lang['import_error_badmail'];
+ return false;
}
return $cleaned;
@@ -1216,7 +1204,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin
// output the csv
$fd = fopen('php://output', 'w');
foreach ($this->import_failures as $fail) {
- fputs($fd, $fail['orig']);
+ fwrite($fd, $fail['orig']);
}
fclose($fd);
die;
diff --git a/lib/plugins/usermanager/cli.php b/lib/plugins/usermanager/cli.php
index 0efd9ec0d..152e26ca0 100644
--- a/lib/plugins/usermanager/cli.php
+++ b/lib/plugins/usermanager/cli.php
@@ -127,9 +127,9 @@ class cli_plugin_usermanager extends DokuWiki_CLI_Plugin
foreach ($list as $username => $user) {
$content = [$username];
if ($details) {
- array_push($content, $user['name']);
- array_push($content, $user['mail']);
- array_push($content, implode(", ", $user['grps']));
+ $content[] = $user['name'];
+ $content[] = $user['mail'];
+ $content[] = implode(", ", $user['grps']);
}
echo $tr->format(
[15, 25, 25, 15],
@@ -155,7 +155,7 @@ class cli_plugin_usermanager extends DokuWiki_CLI_Plugin
return 1;
}
- list($login, $mail, $name, $grps, $pass) = $args;
+ [$login, $mail, $name, $grps, $pass] = $args;
$grps = array_filter(array_map('trim', explode(',', $grps)));
if ($auth->canDo('modPass')) {
@@ -168,15 +168,13 @@ class cli_plugin_usermanager extends DokuWiki_CLI_Plugin
return 1;
}
}
- } else {
- if (!empty($pass)) {
- $this->error($this->getLang('add_fail'));
- $this->error($this->getLang('addUser_error_modPass_disabled'));
- return 1;
- }
+ } elseif (!empty($pass)) {
+ $this->error($this->getLang('add_fail'));
+ $this->error($this->getLang('addUser_error_modPass_disabled'));
+ return 1;
}
- if ($auth->triggerUserMod('create', array($login, $pass, $name, $mail, $grps))) {
+ if ($auth->triggerUserMod('create', [$login, $pass, $name, $mail, $grps])) {
$this->success($this->getLang('add_ok'));
} else {
$this->printErrorMessages();
@@ -204,9 +202,9 @@ class cli_plugin_usermanager extends DokuWiki_CLI_Plugin
}
$users = explode(',', $args[0]);
- $count = $auth->triggerUserMod('delete', array($users));
+ $count = $auth->triggerUserMod('delete', [$users]);
- if (!($count == count($users))) {
+ if ($count != count($users)) {
$this->printErrorMessages();
$part1 = str_replace('%d', $count, $this->getLang('delete_ok'));
$part2 = str_replace('%d', (count($users) - $count), $this->getLang('delete_fail'));
@@ -228,22 +226,22 @@ class cli_plugin_usermanager extends DokuWiki_CLI_Plugin
/** @var AuthPlugin $auth */
global $auth;
- list($name, $newgrps) = $args;
+ [$name, $newgrps] = $args;
$newgrps = array_filter(array_map('trim', explode(',', $newgrps)));
$oldinfo = $auth->getUserData($name);
- $changes = array();
+ $changes = [];
- if (!empty($newgrps) && $auth->canDo('modGroups')) {
+ if ($newgrps !== [] && $auth->canDo('modGroups')) {
$changes['grps'] = $oldinfo['grps'];
foreach ($newgrps as $group) {
if (!in_array($group, $oldinfo['grps'])) {
- array_push($changes['grps'], $group);
+ $changes['grps'][] = $group;
}
}
}
if (!empty(array_diff($changes['grps'], $oldinfo['grps']))) {
- if ($auth->triggerUserMod('modify', array($name, $changes))) {
+ if ($auth->triggerUserMod('modify', [$name, $changes])) {
$this->success($this->getLang('update_ok'));
} else {
$this->printErrorMessages();
@@ -266,12 +264,12 @@ class cli_plugin_usermanager extends DokuWiki_CLI_Plugin
/** @var AuthPlugin $auth */
global $auth;
- list($name, $grps) = $args;
+ [$name, $grps] = $args;
$grps = array_filter(array_map('trim', explode(',', $grps)));
$oldinfo = $auth->getUserData($name);
- $changes = array();
+ $changes = [];
- if (!empty($grps) && $auth->canDo('modGroups')) {
+ if ($grps !== [] && $auth->canDo('modGroups')) {
$changes['grps'] = $oldinfo['grps'];
foreach ($grps as $group) {
if (($pos = array_search($group, $changes['grps'])) == !false) {
@@ -281,7 +279,7 @@ class cli_plugin_usermanager extends DokuWiki_CLI_Plugin
}
if (!empty(array_diff($oldinfo['grps'], $changes['grps']))) {
- if ($auth->triggerUserMod('modify', array($name, $changes))) {
+ if ($auth->triggerUserMod('modify', [$name, $changes])) {
$this->success($this->getLang('update_ok'));
} else {
$this->printErrorMessages();