diff --git a/actions/AdminBackupsAction.php b/actions/AdminBackupsAction.php index 7c5b03ba2..c420bf0fc 100644 --- a/actions/AdminBackupsAction.php +++ b/actions/AdminBackupsAction.php @@ -1,9 +1,9 @@ wiki->UserIsAdmin()) { return $this->render('@templates/alert-message.twig', [ 'type' => 'danger', - 'message' => get_class($this)." : " . _t('BAZ_NEED_ADMIN_RIGHTS') - ]) ; + 'message' => get_class($this) . ' : ' . _t('BAZ_NEED_ADMIN_RIGHTS'), + ]); } $status = $this->getService(ArchiveService::class)->getArchivingStatus(); if (!$status['canArchive']) { @@ -32,12 +32,13 @@ public function run() } elseif ($status['dB'] == false) { $message = _t('ADMIN_BACKUPS_MESSAGE_DB_NOT_ARCHIVABLE'); } + return $this->render('@templates/alert-message.twig', [ 'type' => 'warning', - 'message' => _t('ADMIN_BACKUPS_MESSAGE_ARCHIVE_CANNOT_BE_DONE').' '.$message.'
'._t('ADMIN_BACKUPS_MESSAGE_SEE_DOC').'.' + 'message' => _t('ADMIN_BACKUPS_MESSAGE_ARCHIVE_CANNOT_BE_DONE') . ' ' . $message . '
' . _t('ADMIN_BACKUPS_MESSAGE_SEE_DOC') . '.', ]); - } + return $this->render('@core/actions/admin-backups.twig', [ ]); } diff --git a/actions/AdminReactionsAction.php b/actions/AdminReactionsAction.php index 151bb2719..9d2ee26f2 100644 --- a/actions/AdminReactionsAction.php +++ b/actions/AdminReactionsAction.php @@ -1,9 +1,9 @@ wiki->UserIsAdmin()) { $allReactions = $this->wiki->services->get(ReactionManager::class)->getReactions(); foreach ($allReactions as $k => $reactions) { - usort($reactions["reactions"], function ($a, $b) { // sort by user + usort($reactions['reactions'], function ($a, $b) { // sort by user return strnatcasecmp($a['user'], $b['user']); }); } + return $this->render('@core/admin-reactions-table.twig', [ - 'reactions' => $allReactions + 'reactions' => $allReactions, ]); } else { return $this->render('@templates/alert-message.twig', [ 'type' => 'info', - 'message' => _t('REACTION_CONNECT_AS_ADMIN') + 'message' => _t('REACTION_CONNECT_AS_ADMIN'), ]); } } diff --git a/actions/CommentsAction.php b/actions/CommentsAction.php index a59558287..5f3669045 100644 --- a/actions/CommentsAction.php +++ b/actions/CommentsAction.php @@ -1,7 +1,7 @@ commentsService = $this->getService(CommentService::class); - $coms = $this->commentsService->loadComments(''); # get all comments + $this->commentsService = $this->getService(CommentService::class); + $coms = $this->commentsService->loadComments(''); // get all comments + return $this->render('@core/comment-table.twig', [ 'comments' => $coms, - ]) ; + ]); } } diff --git a/actions/EditActionsAclsAction.php b/actions/EditActionsAclsAction.php index c71033605..9db3d33ec 100755 --- a/actions/EditActionsAclsAction.php +++ b/actions/EditActionsAclsAction.php @@ -1,7 +1,7 @@ wiki->UserIsAdmin()) { return $this->render('@templates/alert-message.twig', [ 'type' => 'danger', - 'message' => "EditActionsAclsAction : " . _t('BAZ_NEED_ADMIN_RIGHTS') - ]) ; + 'message' => 'EditActionsAclsAction : ' . _t('BAZ_NEED_ADMIN_RIGHTS'), + ]); } $wiki = &$this->wiki; $list = $wiki->services->get(Performer::class)->list('action'); sort($list); $res = $wiki->FormOpen('', '', 'get'); - $res .= _t('ACTION_RIGHTS').' '; foreach ($list as $action) { $res .= ''; } - $res .= ' ' . $wiki->FormClose(); + $res .= ' ' . $wiki->FormClose(); if ($_POST && !empty($_POST['actionname'])) { // save ACL's $result = $wiki->SetModuleACL($name = $_POST['actionname'], 'action', @$_POST['acl']); if ($result) { - return $res . _t('ERROR_WHILE_SAVING_ACL') .' ' . ucfirst($name) . ' ('._t('ERROR_CODE').' ' . $result . ')
'; + return $res . _t('ERROR_WHILE_SAVING_ACL') . ' ' . ucfirst($name) . ' (' . _t('ERROR_CODE') . ' ' . $result . ')
'; } else { - $wiki->LogAdministrativeAction($wiki->GetUserName(), _t('NEW_ACL_FOR_ACTION')." " . ucfirst($name) . ' : ' . @$_POST['acl'] . "\n"); - return $res . _t('NEW_ACL_SUCCESSFULLY_SAVED_FOR_ACTION').' ' . ucfirst($name) . '.
'; + $wiki->LogAdministrativeAction($wiki->GetUserName(), _t('NEW_ACL_FOR_ACTION') . ' ' . ucfirst($name) . ' : ' . @$_POST['acl'] . "\n"); + + return $res . _t('NEW_ACL_SUCCESSFULLY_SAVED_FOR_ACTION') . ' ' . ucfirst($name) . '.
'; } } elseif (!empty($_GET['actionname']) && in_array($name = $_GET['actionname'], $list)) { $res .= $wiki->FormOpen(); - $res .= '
'._t('EDIT_RIGHTS_FOR_ACTION').' ' . ucfirst($name) . ':'; - $res .= ''; + $res .= '
' . _t('EDIT_RIGHTS_FOR_ACTION') . ' ' . ucfirst($name) . ':'; + $res .= ''; $res .= '
'; - $res .= ''; + $res .= ''; + return $res . $wiki->FormClose(); } + return $res; } } diff --git a/actions/EditConfigAction.php b/actions/EditConfigAction.php index d347ac603..05528b636 100644 --- a/actions/EditConfigAction.php +++ b/actions/EditConfigAction.php @@ -1,7 +1,7 @@ wiki->UserIsAdmin()) { return $this->render('@templates/alert-message.twig', [ 'type' => 'danger', - 'message' => get_class($this) . " : " . _t('BAZ_NEED_ADMIN_RIGHTS') + 'message' => get_class($this) . ' : ' . _t('BAZ_NEED_ADMIN_RIGHTS'), ]); } if (!is_writable('wakka.config.php')) { return $this->render('@templates/alert-message.twig', [ 'type' => 'danger', - 'message' => _t('ERROR_NO_ACCESS') . ' ' . _t('FILE_WRITE_PROTECTED') + 'message' => _t('ERROR_NO_ACCESS') . ' ' . _t('FILE_WRITE_PROTECTED'), ]); } @@ -73,11 +73,11 @@ public function run() $output = ''; if ($this->arguments['saving']) { $this->save(); - $this->wiki->Redirect($this->wiki->Href('', '', [self::SAVED_NAME => "1"], false)); + $this->wiki->Redirect($this->wiki->Href('', '', [self::SAVED_NAME => '1'], false)); } elseif ($this->arguments['saved']) { $output .= $this->render('@templates/alert-message.twig', [ 'type' => 'info', - 'message' => _t('EDIT_CONFIG_SAVE') + 'message' => _t('EDIT_CONFIG_SAVE'), ]); } @@ -91,6 +91,7 @@ public function run() $keysList[''] = array_merge($keysList[''] ?? [], [$key => $value]); } } + return $output . $this->render('@core/edit-config.twig', [ 'SAVE_NAME' => self::SAVE_NAME, 'keysList' => $keysList, @@ -101,7 +102,7 @@ public function run() /** * get AUTHORIZED_KEYS - * return array [$keys,$associatedExtensions] + * return array [$keys,$associatedExtensions]. */ private function getAuthorizedKeys(): array { @@ -152,30 +153,32 @@ private function getAuthorizedKeys(): array $this->keys = $scannedKeys; $this->associatedExtensions = $associatedExtensions; } + return [$this->keys, $this->associatedExtensions]; } /** * prepare array of $keyNames from $keys - * recursive + * recursive. * * @param array|string $keys - * @param bool $firstLevel + * * @return array [$keyName1,$keyName2] */ private function prepareKeyNames($keys, bool $firstLevel = false): array { if (is_string($keys)) { - return ($firstLevel ? [$keys] : ["[{$keys}]"]); + return $firstLevel ? [$keys] : ["[{$keys}]"]; } elseif (is_array($keys)) { $result = []; $isList = $this->arrayIsList($keys); foreach ($keys as $key => $value) { $subLevelKeyNames = $this->prepareKeyNames($value, $firstLevel && $isList); foreach ($subLevelKeyNames as $subLevelKeyName) { - $result[] = ($isList ? "" : ($firstLevel ? $key : "[{$key}]")) . $subLevelKeyName; + $result[] = ($isList ? '' : ($firstLevel ? $key : "[{$key}]")) . $subLevelKeyName; } } + return $result; } else { return []; @@ -183,7 +186,7 @@ private function prepareKeyNames($keys, bool $firstLevel = false): array } /** - * could be replace by array_is_list since php 8.1 + * could be replace by array_is_list since php 8.1. */ private function arrayIsList(array $array): bool { @@ -193,12 +196,14 @@ private function arrayIsList(array $array): bool return false; } } + return true; } /** - * save data to wakka.config.php - * @return boolean true if successfull + * save data to wakka.config.php. + * + * @return bool true if successfull */ private function save(): bool { @@ -278,16 +283,16 @@ private function save(): bool $config->$firstLevelKey, [ $keyAsArray[1] => [ - $keyAsArray[2] => $this->strtoarray($new_value) - ] + $keyAsArray[2] => $this->strtoarray($new_value), + ], ] ); } } else { $config->$firstLevelKey = [ $keyAsArray[1] => [ - $keyAsArray[2] => $this->strtoarray($new_value) - ] + $keyAsArray[2] => $this->strtoarray($new_value), + ], ]; } } @@ -303,7 +308,8 @@ private function save(): bool } /** - * get data from config file + * get data from config file. + * * @return array [$data,$placeholders,$associatedExtensions] format ['name' => string $value,'name2'=> "['ee'=>'yy',...]"] */ private function getDataFromConfigFile(): array @@ -318,13 +324,13 @@ private function getDataFromConfigFile(): array if (!empty($keyAsArray)) { $length = count($keyAsArray); $firstLevelKey = $keyAsArray[0]; - $keyName = $firstLevelKey . ($length > 1 ? "[" . implode("][", array_slice($keyAsArray, 1)) . "]" : ""); + $keyName = $firstLevelKey . ($length > 1 ? '[' . implode('][', array_slice($keyAsArray, 1)) . ']' : ''); switch ($length) { case 1: if (isset($config->$firstLevelKey)) { $data[$keyName] = $this->array2Str($config->$firstLevelKey); } else { - $data[$keyName] = ""; + $data[$keyName] = ''; } if ($this->params->has($firstLevelKey)) { $placeholders[$keyName] = $this->array2Str($this->params->get($firstLevelKey)); @@ -337,7 +343,7 @@ private function getDataFromConfigFile(): array ) { $data[$keyName] = $this->array2Str($config->$firstLevelKey[$keyAsArray[1]]); } else { - $data[$keyName] = ""; + $data[$keyName] = ''; } if ( $this->params->has($firstLevelKey) @@ -354,7 +360,7 @@ private function getDataFromConfigFile(): array ) { $data[$keyName] = $this->array2Str($config->$firstLevelKey[$keyAsArray[1]][$keyAsArray[2]]); } else { - $data[$keyName] = ""; + $data[$keyName] = ''; } if ( $this->params->has($firstLevelKey) @@ -366,17 +372,18 @@ private function getDataFromConfigFile(): array break; default: - $data[$keyName] = ""; + $data[$keyName] = ''; break; } } } + return [$data, $placeholders, $associatedExtensions]; } /** - * convert $keys to array of arrays - * @param array $keys + * convert $keys to array of arrays. + * * @return array $conertedKeys */ private function convertKeysAsArray(array $keys): array @@ -399,19 +406,21 @@ private function convertKeysAsArray(array $keys): array } } } + return $convertedKeys; } /** - * extract associated values from config second level + * extract associated values from config second level. + * * @param Configuration $config - * @param string $firstLevelKey + * @param string $firstLevelKey */ /** - * array to string + * array to string. + * * @param mixed $value - * @return string */ private function array2Str($value): string { @@ -421,7 +430,7 @@ private function array2Str($value): string . implode( ',', array_map(function ($k, $v) { - return (($v === false) ? "false" : (($v === true) ? "true" : "'" . $v . "'")); + return ($v === false) ? 'false' : (($v === true) ? 'true' : "'" . $v . "'"); }, array_keys($value), array_values($value)) ) . ']'; @@ -430,24 +439,25 @@ private function array2Str($value): string . implode( ',', array_map(function ($k, $v) { - return "'" . $k . "' => " . (($v === false) ? "false" : (($v === true) ? "true" : "'" . $v . "'")); + return "'" . $k . "' => " . (($v === false) ? 'false' : (($v === true) ? 'true' : "'" . $v . "'")); }, array_keys($value), array_values($value)) ) . ']'; } } elseif (!is_string($value)) { try { - $value = (($value === false) ? "false" : (($value === true) ? "true" : strval($value))); + $value = (($value === false) ? 'false' : (($value === true) ? 'true' : strval($value))); } catch (\Throwable $th) { $value = ''; } } + return $value; } /** - * string to array if needed - * @param string $value + * string to array if needed. + * * @return mixed */ private function strtoarray(string $value) @@ -487,12 +497,12 @@ private function strtoarray(string $value) } else { $value = ($value == 'true') ? true : (($value == 'false') ? false : $value); } + return $value; } /** - * get help from translation - * @return array + * get help from translation. */ private function getHelp(): array { @@ -500,7 +510,7 @@ private function getHelp(): array foreach ($this->convertKeysAsArray($this->getAuthorizedKeys()[0]) as $keyAsArray) { $length = count($keyAsArray); $firstLevelKey = $keyAsArray[0]; - $keyName = $firstLevelKey . ($length > 1 ? "[" . implode("][", array_slice($keyAsArray, 1)) . "]" : ""); + $keyName = $firstLevelKey . ($length > 1 ? '[' . implode('][', array_slice($keyAsArray, 1)) . ']' : ''); if (isset($GLOBALS['translations']['EDIT_CONFIG_HINT_' . $keyName])) { $help[$keyName] = _t('EDIT_CONFIG_HINT_' . $keyName); } elseif (isset($GLOBALS['translations']['EDIT_CONFIG_HINT_' . strtoupper($keyName)])) { diff --git a/actions/EditGroupsAction.php b/actions/EditGroupsAction.php index 7740da7d5..9e5adf837 100755 --- a/actions/EditGroupsAction.php +++ b/actions/EditGroupsAction.php @@ -1,6 +1,5 @@ wiki->UserIsAdmin()) { return $this->render('@templates/alert-message.twig', [ 'type' => 'danger', - 'message' => "EditGroupsAction : " . _t('BAZ_NEED_ADMIN_RIGHTS') - ]) ; + 'message' => 'EditGroupsAction : ' . _t('BAZ_NEED_ADMIN_RIGHTS'), + ]); } $message = ''; @@ -44,7 +43,7 @@ public function run() list('message' => $message, 'type' => $type) = $this->deleteGroup($selectedGroupName); } } catch (TokenNotFoundException $th) { - $message = _t('ERROR_WHILE_SAVING_GROUP') .':
'. $th->getMessage(); + $message = _t('ERROR_WHILE_SAVING_GROUP') . ':
' . $th->getMessage(); } } } @@ -59,7 +58,7 @@ public function run() return $this->render( '@core/actions/edit-group-action.twig', - compact(['list','message','type','currentGroupAcl','selectedGroupName','action']) + compact(['list', 'message', 'type', 'currentGroupAcl', 'selectedGroupName', 'action']) ); } @@ -81,23 +80,21 @@ protected function saveAcl(string $selectedGroupName): array if ($result) { if ($result == 1000) { - $message = _t('ERROR_RECURSIVE_GROUP').' !'; + $message = _t('ERROR_RECURSIVE_GROUP') . ' !'; } else { - $message = _t('ERROR_WHILE_SAVING_GROUP') . ' ' . ucfirst($selectedGroupName) . ' ('._t('ERROR_CODE').' ' . $result . ')'; + $message = _t('ERROR_WHILE_SAVING_GROUP') . ' ' . ucfirst($selectedGroupName) . ' (' . _t('ERROR_CODE') . ' ' . $result . ')'; } } else { - // - $this->wiki->LogAdministrativeAction($this->wiki->GetUserName(), _t('NEW_ACL_FOR_GROUP')." " . ucfirst($selectedGroupName) . ' : ' . $newacl . "\n"); - $message = _t('NEW_ACL_SUCCESSFULLY_SAVED_FOR_THE_GROUP').' ' . ucfirst($selectedGroupName); + $this->wiki->LogAdministrativeAction($this->wiki->GetUserName(), _t('NEW_ACL_FOR_GROUP') . ' ' . ucfirst($selectedGroupName) . ' : ' . $newacl . "\n"); + $message = _t('NEW_ACL_SUCCESSFULLY_SAVED_FOR_THE_GROUP') . ' ' . ucfirst($selectedGroupName); $type = 'success'; } } } - return compact(['message','type']); + return compact(['message', 'type']); } - protected function deleteGroup(string &$selectedGroupName): array { $message = ''; @@ -116,7 +113,7 @@ protected function deleteGroup(string &$selectedGroupName): array $ownedPages = $dbService->loadAll($sql); // if group owns no pages, then empty if (!empty($ownedPages)) { // Array is not empty because the query returns at least one page - $message = _t('ONLY_NO_PAGES_GROUP_FOR_DELETION').'
'; + $message = _t('ONLY_NO_PAGES_GROUP_FOR_DELETION') . '
'; $message .= implode('
', array_map(function ($acl) { return "wiki->Href('', $acl['page_tag'])}\">{$acl['page_tag']}"; }, $ownedPages)); @@ -131,7 +128,7 @@ protected function deleteGroup(string &$selectedGroupName): array $dbService->query($sql); $tripleStore = $this->getService(TripleStore::class); - $previous = $tripleStore->getMatching(GROUP_PREFIX.$selectedGroupName, WIKINI_VOC_PREFIX.WIKINI_VOC_ACLS, '', '='); + $previous = $tripleStore->getMatching(GROUP_PREFIX . $selectedGroupName, WIKINI_VOC_PREFIX . WIKINI_VOC_ACLS, '', '='); $deletionOk = false; if (!empty($previous)) { $deletionOk = true; @@ -153,7 +150,7 @@ protected function deleteGroup(string &$selectedGroupName): array } } - return compact(['message','type']); + return compact(['message', 'type']); } protected function confirmToken() diff --git a/actions/EditHandlersAclsAction.php b/actions/EditHandlersAclsAction.php index 146720d3a..7ee29e026 100755 --- a/actions/EditHandlersAclsAction.php +++ b/actions/EditHandlersAclsAction.php @@ -1,7 +1,7 @@ wiki->UserIsAdmin()) { return $this->render('@templates/alert-message.twig', [ 'type' => 'danger', - 'message' => "EditHandlersAclsAction : " . _t('BAZ_NEED_ADMIN_RIGHTS') - ]) ; + 'message' => 'EditHandlersAclsAction : ' . _t('BAZ_NEED_ADMIN_RIGHTS'), + ]); } $wiki = &$this->wiki; $list = $wiki->services->get(Performer::class)->list('handler'); sort($list); $res = $wiki->FormOpen('', '', 'get'); - $res .= _t('HANDLER_RIGHTS').' '; foreach ($list as $handler) { $res .= ''; } - $res .= ' ' . $wiki->FormClose(); + $res .= ' ' . $wiki->FormClose(); if ($_POST && !empty($_POST['handlername'])) { // save ACL's $result = $wiki->SetModuleACL($name = $_POST['handlername'], 'handler', @$_POST['acl']); if ($result) { - return $res . _t('ERROR_WHILE_SAVING_HANDLER_ACL').' ' . ucfirst($name) . ' ('._t('ERROR_CODE').' ' . $result . ')
'; + return $res . _t('ERROR_WHILE_SAVING_HANDLER_ACL') . ' ' . ucfirst($name) . ' (' . _t('ERROR_CODE') . ' ' . $result . ')
'; } else { - $wiki->LogAdministrativeAction($wiki->GetUserName(), _t('NEW_ACL_FOR_HANDLER')." " . ucfirst($name) . ' : ' . @$_POST['acl'] . "\n"); - return $res . _t('NEW_ACL_SUCCESSFULLY_SAVED_FOR_HANDLER').' ' . ucfirst($name) . '.
'; + $wiki->LogAdministrativeAction($wiki->GetUserName(), _t('NEW_ACL_FOR_HANDLER') . ' ' . ucfirst($name) . ' : ' . @$_POST['acl'] . "\n"); + + return $res . _t('NEW_ACL_SUCCESSFULLY_SAVED_FOR_HANDLER') . ' ' . ucfirst($name) . '.
'; } } elseif (!empty($_GET['handlername']) && in_array($name = $_GET['handlername'], $list)) { $res .= $wiki->FormOpen(); - $res .= '
'._t('EDIT_RIGHTS_FOR_HANDLER').' ' . ucfirst($name) . ':
'; - $res .= ''; + $res .= '
' . _t('EDIT_RIGHTS_FOR_HANDLER') . ' ' . ucfirst($name) . ':
'; + $res .= ''; $res .= '
'; - $res .= ''; + $res .= ''; + return $res . $wiki->FormClose(); } + return $res; } } diff --git a/actions/EraseSpamedCommentsAction.php b/actions/EraseSpamedCommentsAction.php index 674f68444..ff2807d6e 100755 --- a/actions/EraseSpamedCommentsAction.php +++ b/actions/EraseSpamedCommentsAction.php @@ -1,7 +1,7 @@ wiki; ob_start(); - echo "\n\n"; + echo "\n\n"; // -- 2. Affichage du formulaire --- if (!isset($_POST['clean'])) { - $limit = isset($this->arguments['max']) && $this->arguments["max"] > 0 ? (int) $this->arguments["max"] : 0; + $limit = isset($this->arguments['max']) && $this->arguments['max'] > 0 ? (int)$this->arguments['max'] : 0; if ($comments = $wiki->LoadRecentComments($limit)) { // Formulaire listant les commentaires - echo "
Href() . "\" name=\"selection\">\n"; + echo '\n"; $curday = ''; foreach ($comments as $comment) { // day header - list($day, $time) = explode(" ", $comment["time"]); + list($day, $time) = explode(' ', $comment['time']); if ($day != $curday) { if ($curday) { - echo "\n" ; + echo "\n"; } $erase_id = 'erasecommday_' . str_replace('-', '', $day); - echo "$day: ".htmlspecialchars(strtolower(_t('INVERT')))."
\n" ; - echo "