# toprealm/mediawiki-extensions-addimgtag architecture

> Architecture diagram of the GitHub repository toprealm/mediawiki-extensions-addimgtag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/toprealm/mediawiki-extensions-addimgtag
- Repository: https://github.com/toprealm/mediawiki-extensions-addimgtag

## Overview

AddImgTag is a MediaWiki extension that turns `<img>` markup and `{{#img:...}}` into HTML images. Its main workflow parses attributes, applies optional domain allow/deny rules, and emits either an image or a notice. A separate, opt-in parser hook normalizes image tags to self-closing form. The README documents the supported capabilities; edges for MediaWiki lifecycle dispatch are dashed where the excerpts do not show extension registration or invocation.

Main entry points: [`includes/Hooks/AddImgTagHook.php`](https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgTagHook.php) (img tag handler), [`includes/Hooks/AddImgParserFunHook.php`](https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgParserFunHook.php) (img parser function), [`includes/Hooks/AddImgSelfClosingTag.php`](https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgSelfClosingTag.php) (Self-closing normalizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_parse["Image parsing"]
  node_tag_handler["img tag handler<br/>[AddImgTagHook.php]"]
  node_parser_function["img parser function"]
end

subgraph group_policy["Validation and output"]
  node_attribute_builder["Attribute builder<br/>[AddImgTagHook.php]"]
  node_domain_policy["Domain policy<br/>[AddImgTagHook.php]"]
  node_html_output["HTML image or notice<br/>[AddImgTagHook.php]"]
end

subgraph group_preprocess["Content preprocessing"]
  node_self_closing["Self-closing normalizer"]
end

node_wiki_content(("Wiki content"))
node_mediawiki_parser["MediaWiki parser"]

node_wiki_content -.->|"provides markup"| node_mediawiki_parser
node_tag_handler -->|"registers tag"| node_mediawiki_parser
node_parser_function -->|"registers function"| node_mediawiki_parser
node_mediawiki_parser -.->|"dispatches tag"| node_tag_handler
node_mediawiki_parser -.->|"dispatches function"| node_parser_function
node_tag_handler -->|"builds attributes"| node_attribute_builder
node_tag_handler -->|"checks domain"| node_domain_policy
node_tag_handler -->|"emits result"| node_html_output
node_parser_function -->|"builds attributes"| node_attribute_builder
node_parser_function -->|"checks domain"| node_domain_policy
node_parser_function -->|"emits result"| node_html_output
node_self_closing -.->|"registers preprocessing"| node_mediawiki_parser
node_mediawiki_parser -.->|"preprocesses content"| node_self_closing

click node_tag_handler "https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgTagHook.php"
click node_parser_function "https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgParserFunHook.php"
click node_attribute_builder "https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgTagHook.php"
click node_domain_policy "https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgTagHook.php"
click node_html_output "https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgTagHook.php"
click node_self_closing "https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgSelfClosingTag.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_tag_handler,node_parser_function toneBlue
class node_attribute_builder,node_domain_policy,node_html_output toneAmber
class node_self_closing toneMint
class node_wiki_content,node_mediawiki_parser toneIndigo
```

## Components

### Image parsing

- [img tag handler](https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgTagHook.php): `includes/Hooks/AddImgTagHook.php`
- [img parser function](https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgParserFunHook.php): `includes/Hooks/AddImgParserFunHook.php`

### Validation and output

- [Attribute builder](https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgTagHook.php): `includes/Hooks/AddImgTagHook.php`
- [Domain policy](https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgTagHook.php): `includes/Hooks/AddImgTagHook.php`
- [HTML image or notice](https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgTagHook.php): `includes/Hooks/AddImgTagHook.php`

### Content preprocessing

- [Self-closing normalizer](https://github.com/toprealm/mediawiki-extensions-addimgtag/blob/main/includes/Hooks/AddImgSelfClosingTag.php): `includes/Hooks/AddImgSelfClosingTag.php`

### Other components

- **Wiki content**
- **MediaWiki parser**

## Connections

- Wiki content → MediaWiki parser: provides markup (evidence: `README.md`)
- img tag handler → MediaWiki parser: registers tag (evidence: `includes/Hooks/AddImgTagHook.php`)
- img parser function → MediaWiki parser: registers function (evidence: `includes/Hooks/AddImgParserFunHook.php`)
- MediaWiki parser → img tag handler: dispatches tag
- MediaWiki parser → img parser function: dispatches function
- img tag handler → Attribute builder: builds attributes (evidence: `includes/Hooks/AddImgTagHook.php`)
- img tag handler → Domain policy: checks domain (evidence: `includes/Hooks/AddImgTagHook.php`)
- img tag handler → HTML image or notice: emits result (evidence: `includes/Hooks/AddImgTagHook.php`)
- img parser function → Attribute builder: builds attributes (evidence: `includes/Hooks/AddImgParserFunHook.php`)
- img parser function → Domain policy: checks domain (evidence: `includes/Hooks/AddImgParserFunHook.php`)
- img parser function → HTML image or notice: emits result (evidence: `includes/Hooks/AddImgParserFunHook.php`)
- Self-closing normalizer → MediaWiki parser: registers preprocessing
- MediaWiki parser → Self-closing normalizer: preprocesses content (evidence: `README.md`)
