==== Context
For {T430131} the communities can define "autoname-templates" for each citation type where they can then set custom patterns that allow building the names for newly added references. The code needs to get the names of these templates to be able to apply them when generating new names on save.
Communities need to edit a JSON page in the MediaWiki namespace to map templates to their autoname template. Similar to [[ https://en.wikipedia.org/wiki/MediaWiki:Citoid-template-type-map.json | Citoid-template-type-map.json ]]
==== Location and format of autoname-template map
- The JSON page for the configuration should be at `MediaWiki:Cite-autoname-template-map.json`
- The JSON should follow this structure:
```
{
"autonameTemplate": [ "*" ],
"autonameTemplateBook": [ "Cite book", "Cite journal", "Cite magazin" ],
"autonameTemplateWeb: [ "Cite web", "Cite insta", "Cite archive" ]
}
```
- Each property represents the name of an autoname-template in the `Template:` namespace
- The value is a list of template names, where this autoname-template should be applied to
- `*` is used to mark an autoname-template as default, so this template is always applied, if a reference with single-template transclusion is found and no other autoname-template is set
- If a template is part of two lists of two autoname-templates, the first autoname template defined in the JSON wins.
==== Implementation
- Read the page in PHP similar to `MediaWiki:Citoid-template-type-map.json`
- Validate the JSON in PHP
- Create a lookup map `template => autoname-template` and forward as JS
- Consider default case if set up in JSON
- Validate the lookup map in JS
- Create a method that extracts the template name from an InternalItem and looks for an autoname template
- Apply default template is set up
- Integrate with the method that generates the autoname
- **New 2026-09-29:** Fall back to increment 1 autonames when a) the map doesn't exist at all b) the template is not found in the map. In our test we had template names like `Template:undfined1`
FALLBACKS:
[] Template parameter needed for autoname generation is missing
[] The map doesn't exist at all
[] The template is not found in the map