Context
For T430131: [Epic] Autonames increment 2: Support content-based references patterns 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 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
- Fallback to increment 1 when the map doesn't exist at all
- Fallback to increment 1 when the template is not found in the map
- Template parameter needed for autoname generation is missing: display error message instead of falling back to increment 1