Page MenuHomePhabricator

Allow extensions to insert into specialParserFunctions for CodeMirror
Open, Needs TriagePublicFeature

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).