What's the registerExtension() function for? Registering stuff that can't be registered through the JSON file?
Topic on Manual talk:Extension registration
Can you give an example of what you mean?
Two extensions (Math and Spamblacklist) define a registerExtension() function that is never explicitly called. There are also patches in gerrit to add it to two other extensions (TimedMediaHandler and MobileFrontend). The function has no documentation anywhere. As best as I can tell it seems to be for registering globals that can't be migrated to extension.json.
Those are "callbacks", see the docs. Some of them, like the ones in WikiEditor were necessary because extension.json didn't support 2d arrays (it does now) and can probably be removed.
Why is this implemented in such a convoluted way? Couldn't we just use a regular hook?
It's somewhat intentionally convoluted, any instance of it indicates that extension.json is missing support for a feature or an extension is doing something wrong.
A hook isn't feasible due to the way these are called, plus we try to avoid as many dependencies upon the rest of MediaWiki in early initialization, including the Hooks class.
OK, I'm beginning to understand this. If people would just follow the coding conventions and document their functions, things wouldn't be so confusing :P
Would it be possible for you or someone else involved in extension registration to update Manual:Extension registration/Limitations? This seems like a pretty critical documentation page and it hasn't been kept up to date. I tried to make a few changes myself, but I don't know the Phab tickets for any of these issues. Thanks!
- It's confusing that the example gives it a hook name but it isn't. I added a note to Manual:Extension registration#Customizing registration mentioning this.
- When does registration call the callback, is it immediately after registering this one extension or after registering all extensions? Some extensions try to do stuff based on the presence of other extensions, and then wind up being order-dependent.
- The section says "There are two features that can be used to support these cases". What's the second?
Answer here or update the docs, thanks