feat: deferred 1a items - menu_rev lock, lit_mcp_guides filter, warnings, schedule guard precision

Task 14 (rulings P17/P18, Q10):
- lit/menu-get returns menu_rev (Rev::ofMenu over id, parent, position,
  title, url, object, object_id); lit/menu-set-items requires it, refuses
  a stale one with rev_mismatch (hint: lit/menu-get) and returns the new
  menu_rev. Errors::revMismatch takes an optional message/hint.
- GuideRepository: filter lit_mcp_guides adds/overrides topics; invalid
  topic names and non-string content are ignored, files stay the default.
- lit/post-trash names front page, posts page and linking menus in the
  confirmation and as warnings; lit/menu-assign-location needs confirm
  to remove an assigned menu and names it; lit/post-schedule warns that
  a private entry becomes public; Divi hints no longer point to
  non-existing lit-divi-* tools.
- PostGuard::missedSchedule: 60 s publish window, zero GMT date falls
  back to get_gmt_from_date(post_date); post-schedule refuses dates
  within that window.
- write_failed after a clean rollback that keeps a revision/backup says
  "Die Aenderung wurde nicht gespeichert (... bleibt erhalten)" via the
  new state parameter (Errors::writeFailed / WriteFailed rolledBackState).
- wp-basis-smoke: menu_rev flow, unassign confirm, trash/menu and
  private-schedule warnings.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-26 04:33:15 +02:00
co-authored by Claude Opus 5.5
parent 7035448f7d
commit 251934ce53
32 changed files with 700 additions and 98 deletions
+56 -11
View File
@@ -5,19 +5,55 @@ declare(strict_types=1);
namespace LIT\MCP\Guides;
/**
* Reads guide markdown files from one directory. Topic names are restricted to
* lowercase slugs, so no path outside the directory can ever be read.
* Guide topics: markdown files from one directory (the default), extended or overridden
* by the site via the filter `lit_mcp_guides` (spec §9.2), which returns
* array<string topic, string markdown>. Topic names are restricted to lowercase slugs,
* so no path outside the directory can ever be read; filter entries with another name or
* a non-string content are ignored. Filtered content is site-owned and returned as-is.
*/
final class GuideRepository
{
private const TOPIC_PATTERN = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/';
/** @var array<string, string>|null Filtered topics, read once per instance (= request). */
private ?array $filtered = null;
public function __construct(private string $directory)
{
}
/** @return list<string> */
public function topics(): array
{
$topics = array_unique(array_merge($this->fileTopics(), array_keys($this->filtered())));
sort($topics);
return array_values($topics);
}
public function get(string $topic): ?string
{
if (! self::isTopic($topic)) {
return null;
}
$filtered = $this->filtered();
if (array_key_exists($topic, $filtered)) {
return $filtered[$topic];
}
if (! in_array($topic, $this->fileTopics(), true)) {
return null;
}
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$content = file_get_contents($this->directory . '/' . $topic . '.md');
return $content === false ? null : $content;
}
/** @return list<string> */
private function fileTopics(): array
{
$files = glob($this->directory . '/*.md');
if ($files === false) {
@@ -27,25 +63,34 @@ final class GuideRepository
$topics = [];
foreach ($files as $file) {
$topic = basename($file, '.md');
if (preg_match(self::TOPIC_PATTERN, $topic) === 1) {
if (self::isTopic($topic)) {
$topics[] = $topic;
}
}
sort($topics);
return $topics;
}
public function get(string $topic): ?string
/** @return array<string, string> */
private function filtered(): array
{
if (preg_match(self::TOPIC_PATTERN, $topic) !== 1 || ! in_array($topic, $this->topics(), true)) {
return null;
if ($this->filtered !== null) {
return $this->filtered;
}
$path = $this->directory . '/' . $topic . '.md';
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$content = file_get_contents($path);
$guides = apply_filters('lit_mcp_guides', []);
$this->filtered = [];
foreach (is_array($guides) ? $guides : [] as $topic => $markdown) {
if (is_string($topic) && self::isTopic($topic) && is_string($markdown)) {
$this->filtered[$topic] = $markdown;
}
}
return $content === false ? null : $content;
return $this->filtered;
}
private static function isTopic(string $topic): bool
{
return preg_match(self::TOPIC_PATTERN, $topic) === 1;
}
}