102 lines
3.3 KiB
PHP
102 lines
3.3 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace LIT\MCP\Admin;
|
||
|
||
use LIT\MCP\Limits;
|
||
|
||
/**
|
||
* Tab "Limits": upload/download size, log retention, snapshot count (spec §8.4).
|
||
* Changes apply immediately – Limits::all() always reads the current option.
|
||
*/
|
||
final class LimitsTab implements AdminTab
|
||
{
|
||
public const GROUP = 'lit_mcp_limits';
|
||
|
||
public function slug(): string
|
||
{
|
||
return 'limits';
|
||
}
|
||
|
||
public function label(): string
|
||
{
|
||
return __('Limits', 'wp-lit-mcp');
|
||
}
|
||
|
||
public function registerSettings(): void
|
||
{
|
||
register_setting(self::GROUP, Limits::OPTION, [
|
||
'type' => 'array',
|
||
'sanitize_callback' => [Limits::class, 'sanitize'],
|
||
'default' => Limits::DEFAULTS,
|
||
]);
|
||
}
|
||
|
||
public function registerActions(): void
|
||
{
|
||
}
|
||
|
||
public function render(): void
|
||
{
|
||
$values = (new Limits())->all();
|
||
$bounds = Limits::bounds();
|
||
$labels = [
|
||
'upload_mb' => sprintf(
|
||
/* translators: 1: maximum value in MB, 2: cap for Base64 transfers in MB */
|
||
__(
|
||
'Maximale Upload-/Download-Größe (MB, höchstens %1$d; Base64-Upload/Download höchstens %2$d MB)',
|
||
'wp-lit-mcp'
|
||
),
|
||
$bounds['upload_mb'][1],
|
||
Limits::INLINE_MAX_MB
|
||
),
|
||
'log_retention_days' => __('Protokoll aufbewahren (Tage)', 'wp-lit-mcp'),
|
||
'snapshot_count' => __('Anzahl Designsystem-Snapshots (ab Etappe 4)', 'wp-lit-mcp'),
|
||
];
|
||
|
||
echo '<form method="post" action="options.php">';
|
||
settings_fields(self::GROUP);
|
||
echo '<table class="form-table"><tbody>';
|
||
foreach ($labels as $key => $label) {
|
||
[$min, $max] = $bounds[$key];
|
||
printf(
|
||
'<tr><th scope="row"><label for="lit-mcp-%1$s">%2$s</label></th><td>'
|
||
. '<input id="lit-mcp-%1$s" type="number" min="%3$d" max="%4$d" name="%5$s[%1$s]" value="%6$d">'
|
||
. '</td></tr>',
|
||
esc_attr($key),
|
||
esc_html($label),
|
||
esc_attr((string) $min),
|
||
esc_attr((string) $max),
|
||
esc_attr(Limits::OPTION),
|
||
esc_attr((string) $values[$key])
|
||
);
|
||
}
|
||
echo '</tbody></table>';
|
||
$this->maybeRenderUploadSizeNotice($values['upload_mb']);
|
||
submit_button();
|
||
echo '</form>';
|
||
}
|
||
|
||
/**
|
||
* PHP's own upload_max_filesize/post_max_size (via wp_max_upload_size()) can be lower than
|
||
* what is configured here – WordPress itself would then refuse a large upload/download before
|
||
* this limit ever applies. A warning only, since the two are independent knobs.
|
||
*/
|
||
private function maybeRenderUploadSizeNotice(int $uploadMb): void
|
||
{
|
||
$serverMaxMb = (int) floor(wp_max_upload_size() / (1024 * 1024));
|
||
if ($serverMaxMb <= 0 || $uploadMb <= $serverMaxMb) {
|
||
return;
|
||
}
|
||
|
||
$message = sprintf(
|
||
/* translators: 1: configured limit in MB, 2: server limit in MB */
|
||
__('%1$d MB übersteigt das Server-Limit von %2$d MB (upload_max_filesize/post_max_size).', 'wp-lit-mcp'),
|
||
$uploadMb,
|
||
$serverMaxMb
|
||
);
|
||
printf('<p class="description">%s</p>', esc_html($message));
|
||
}
|
||
}
|