Allow extensions to insert into specialParserFunctions for CodeMirror
Closed, ResolvedPublicFeature

Description

Feature summary (what you would like to be able to do and where):
This is a follow-up to T389902. Currently we have

const specialParserFunctions = {
		ifexist: 0,
		lst: 0,
		lstx: 0,
		lsth: 0,
		filepath: 6,
		int: 8,
		invoke: 828
	},
        ...
}

Which cannot be modified by other extensions. A configuration variable such as wgCodeMirrorSpecialParserFunctions can be used to allow other extensions to add more parser functions to the list. For example, the Widgets extension can use

"CodeMirror": {
  "SpecialParserFunctions": {
    "widget": 274
  }
 }

so that {{#widget:WidgetName}} links to Widget:WidgetName.

The code changes shouldn't be too complicated since CodeMirror just need to pass this config to the frontend and then merge additional configs from other extensions with existing values in specialParserFunctions. The main question is whether this additional complexity is warranted.

Event Timeline

How many extensions will need this? If there is only MediaWiki-extensions-Widgets, we can hard code it, which is way more easier.

Besides Widget, Flex Diagrams has {{#display_diagram, DataMaps has {{#displaydatamap, and Mustache (this is the intended use case, but it's a new extension and is still very niche, so I used Widget as the example) has {{#html and {{#mustache. There are some other extensions such as CSS which conditionally needs to link to a wiki page, so those use cases may require some more abstractions which could overcomplicate things.

Admittedly this is not too important of a feature so it's not a big deal if it can't be added to CodeMirror.

The only supported case is that the first argument of the parser function must be a page in the given namespace and the namespace prefix must be omitted. Other cases will not be supported.

Note that, if this were done, several of the current parser functions could be moved out into their respective extensions as well (ifexist is from Extension:ParserFunctions; lst, lstx, and lsth are from Extension:Labeled Section Transclusion; and invoke is from Extension:Scribunto).

Change #1312095 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/CodeMirror@master] DataScript: add special parser functions as extension attributes

https://gerrit.wikimedia.org/r/1312095

Bhsd changed the task status from Open to In Progress.Jul 18 2026, 4:18 AM
Bhsd claimed this task.

Change #1312100 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/Scribunto@master] extension.json: register parser functions for CodeMirror

https://gerrit.wikimedia.org/r/1312100

Change #1312103 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/ParserFunctions@master] extension.json: register parser functions for CodeMirror

https://gerrit.wikimedia.org/r/1312103

Change #1312104 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/LabeledSectionTransclusion@master] extension.json: register parser functions for CodeMirror

https://gerrit.wikimedia.org/r/1312104

Change #1312107 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/Widgets@master] extension.json: register parser functions for CodeMirror

https://gerrit.wikimedia.org/r/1312107

Change #1312095 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] DataScript: add parser function ns ids as extension attributes

https://gerrit.wikimedia.org/r/1312095

Change #1312107 merged by jenkins-bot:

[mediawiki/extensions/Widgets@master] extension.json: register parser functions for CodeMirror

https://gerrit.wikimedia.org/r/1312107

Change #1312104 merged by jenkins-bot:

[mediawiki/extensions/LabeledSectionTransclusion@master] extension.json: register parser functions for CodeMirror

https://gerrit.wikimedia.org/r/1312104

Change #1312100 merged by jenkins-bot:

[mediawiki/extensions/Scribunto@master] extension.json: register parser functions for CodeMirror

https://gerrit.wikimedia.org/r/1312100

Change #1312103 merged by jenkins-bot:

[mediawiki/extensions/ParserFunctions@master] extension.json: register parser functions for CodeMirror

https://gerrit.wikimedia.org/r/1312103

Bhsd moved this task from Improvement to Done on the MediaWiki-extensions-CodeMirror board.