# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project overview

GPLX is a local-first MediaWiki 1.43 installation on Windows, purpose-built for an accessibility-focused content workflow. The Node/npm layer wraps PowerShell scripts for setup and tooling; the actual MediaWiki application lives in `./mediawiki/`.

## Commands

| Task | Command |
|---|---|
| Clone MediaWiki core | `npm run mw:init` |
| Install PHP (Composer) deps | `npm run mw:deps` |
| First-time setup (both above) | `npm run mw:setup` |
| Start dev server (PHP built-in, port 8080) | `npm run dev` |
| Run Pa11y accessibility checks | `npm run a11y:pa11y` |
| Run Lighthouse accessibility checks | `npm run a11y:lighthouse` |
| Run all accessibility checks | `npm run a11y:all` |

**Prerequisites:** Node.js 20+, PHP 8.1+ (XAMPP or WampServer, or PHP in PATH).

After first setup, open `http://127.0.0.1:8080/mw-config/index.php` to finish the MediaWiki installer.

## Architecture

```
gplx/
├── mediawiki/          # MediaWiki 1.43 core (cloned from Gerrit, branch REL1_43)
│   ├── LocalSettings.php   # All site config and custom hooks live here
│   ├── extensions/         # 35 bundled extensions + SemanticMediaWiki 6.0.1 via Composer
│   └── skins/              # Cavendish (default), Vector, MonoBook, Timeless, MinervaNeue
├── scripts/            # PowerShell scripts (dev.ps1, mw-init.ps1, mw-deps.ps1)
│   └── templates/      # Wiki page source files (.wiki) — pushed via maintenance/run.php edit
├── tests/accessibility/    # Pa11y (pa11y.config.json) + Lighthouse (lighthouserc.json) configs
├── docs/               # Project docs (ACCESSIBILITY_WORKFLOW.md, INSTALLATION_WINDOWS.md)
└── package.json        # npm entry point — all commands delegate to scripts/
```

### Key architectural decisions

**LocalSettings.php is the customization layer.** All MediaWiki configuration, hook registrations, and inline CSS lives in `mediawiki/LocalSettings.php`. There is no separate plugin or theme source tree — customizations are PHP hooks injected at startup.

**Approval workflow via ApprovedRevs.** Pages require explicit admin/reviewer approval before public visibility. A `BeforePageDisplay` hook enforces this: unapproved pages are hidden from non-creators and from the public; creators see a pending-review notice. Roles: `sysop`, `bureaucrat`, `reviewer` (the last is assignable by bureaucrats).

**Anonymous editing is disabled.** `$wgGroupPermissions["*"]["edit"] = false` — only registered users can edit.

**Default skin is Cavendish.** Loaded with `wfLoadSkin('Cavendish')`.

**PHP built-in server for local dev.** `dev.ps1` uses `php -S 127.0.0.1:8080 -t ./mediawiki`. It probes XAMPP/WampServer paths if `php` is not in PATH.

**composer.phar lives at the project root**, not inside `mediawiki/`. The `mw-deps.ps1` script downloads it on first run if absent.

**Semantic MediaWiki (SMW) 6.0.1 is installed.** Enabled via `enableSemantics('127.0.0.1:8080')` in `LocalSettings.php`. SMW adds 39 database tables (`smw_*`) and enables structured property annotations and `{{#ask:}}` queries across all wiki pages.

**Template:RegDocument annotates SMW properties.** Every page using `{{RegDocument}}` writes nine structured properties (Scope, Status, Area of validity, etc.) via `{{#set:}}`. These power the automatic queries on `Document_Index` and the category pages.

**Wiki page sources live in `scripts/templates/`.** All template and infrastructure page content is maintained as `.wiki` files and pushed via `php mediawiki/maintenance/run.php edit`. To update a wiki page, edit the `.wiki` file and re-run the push command:

```powershell
Get-Content scripts/templates/<file>.wiki -Raw | D:\xampp\php\php.exe mediawiki/maintenance/run.php edit --user "Gxplex admin" --summary "..." "<Page title>"
```

**Navigation is two-layered.** The sidebar (MediaWiki:Sidebar) links to `Document_Index` and `Special:Ask`. Category pages (e.g. `Category:Medical Devices`) embed `{{#ask:}}` queries showing all pages in that category with their metadata.

## SMW maintenance commands

| Task | Command |
|---|---|
| Initial SMW DB setup | `php mediawiki/extensions/SemanticMediaWiki/maintenance/setupStore.php --nochecks` |
| Rebuild SMW data index | `php mediawiki/extensions/SemanticMediaWiki/maintenance/rebuildData.php` |
| Rebuild property statistics | `php mediawiki/extensions/SemanticMediaWiki/maintenance/rebuildPropertyStatistics.php` |

Run `rebuildData.php` after bulk-importing pages via the maintenance script, or after updating a template that contains `{{#set:}}`.

## Accessibility baseline

- Required: WCAG 2.1 AA
- Stretch target: WCAG 2.1 AAA where practical
- Checks must pass after any template, style, or interaction change: `npm run a11y:all`
- Pa11y targets `http://127.0.0.1:8080/` and `/index.php/Main_Page` (WCAG2AA profile)
- Lighthouse asserts minimum accessibility score of 0.9 (warns, does not fail hard)
