Page MenuHomePhabricator

[Session] Make your extension community configurable
Closed, ResolvedPublic

Description

  • Title of session: Make your extension community configurable
  • Session description: The CommunityConfiguration extension makes it possible to allow on-wiki administrators to configure features (extensions or skins) directly, without needing to involve site administrators. CommunityConfiguration is already available in Spanish betawiki. To make it work with other extensions, such extensions need to be changed to be aware of CommunityConfiguration. The workshop covers how that can be done. The Growth team developers will be interested to know more about situations in which CommunityConfiguration currently behaves in an unexpected way.
  • Username for contact: @Urbanecm_WMF (primary), @Michael (secondary)
  • Session duration: 50min
  • Session type: Workshop
  • Language of session: English
  • Prerequisites: PHP knowledge, basic MediaWiki development knowledge
  • Any other details to share?: Conceptually preceeded by T362877: [Session] Community configuration: What happened in a year?.
  • Interested? Add your username below:

Etherpad: https://etherpad.wikimedia.org/p/wmh2024-Make_your_extension_community_configurable

Notes from session:

Make your extension community configurable

Date and time: May 4, 2025, 10:30

Relevant links

Presenter

[[User:Martin Urbanec (WMF)|Martin Urbanec (WMF)]], [[User:MGrosse-WMF|MGrosse-WMF]]

Participants

Notes

Introductions by Martin and Michael
We will show you converting an extension to using CommunityConfiguration, and then the second half is that we will get you to convert some extensions. We have a list in case you do not have any in mind specifically.
We will start converting the HackathonExtension ( https://gitlab.wikimedia.org/repos/growth/hackathon-extension )
The extension allows the background site colour to be changed and also shows a special page that provides information about the site.
The Special:GetSiteInfo page displays the database name, database username, whether growth experiments are enabled, and the background colour of the site
A schema defines and validates the configuration options that are availible to the user to configure on-wiki. We do this by creating a schema class which extends the JsonSchema class from the CommunityConfiguration extension.
Configuration values are defined via constants in the schema class where the name is the name of the configuration value. You must define a type and default, as the CommunityConfiguration extension could have errors otherwise
Then you add a attribute to the extension.json which is named "CommunityConfiguration". There is another example extension which has this code defined that you can use. The configuration here defines where the configuration is stored. This is currently only on a wikipage that contains JSON. The validator is defined as the class we created in the first step.
Types - "type": "Data" and "type":"mw-config"
After these steps, the community configuration should be set up on the special page but is not completely ready. We will also need to define i18n messages that are generated by the Special:CommunityConfiguration page. Some of these are required, such as the title but other message keys are not required and if not specified would be ignored.
Then you define a service which is the name of the extension plus "CommunityConfiguration". This allows you to use this service to get the values that are configured, and if the extension is not installed then it loads the main config instead of the value from the JSON file on-wiki.
Then we replace all uses of ::getConfig with this new service. You can do this by injecting the service which can be marked as the "Config" type. It can use a configuration value from the extension that is not defined in the community configuration config. This means that the values can be updated in the schema without having to replace calls to ::getConfig a future change.
The JSON file it also validated to ensure that if a user modified the JSON file directly it does not break the config.

Questions

Q: Do we have a option for chips, like select box or
A: We have several different types including numbers, boolean, strings, page titles, namespaces. We will figure out more once we have use cases for them.

Q: What if I want to add search inputs which are conditional. For example, if I click the 'A' switch I want to show the 'B' switch
A: It is possible to do this. What we want to add sectioning so that you can define which section it is in. If you have more complex problems.

Q: Could we restrict the form to a specific right?
A: The right is currently interfaceadmin, but a logged out user can still view the form and the data that is currently saved (as well as the history). To do this you could define a custom provider class and then override the user rights check. The configuration being shown needs to be public as anyone can view it unless you define your own store. This get complicated quickly, as you will also need to override the form and also need to put history somewhere.

Q: Is it possible to contribute to the CommunityConfiguration extension to add new configuration types? Does it use Codex?
A: Yes it uses codex. CommunityConfiguration is on gerrit, so you can submit patches.

Q: Is it possible to get the community configured data via a community configuration API? I am using VueJS which means I'd like to get this configuration over the API
A: It should be there, but it doesn't seem to be. I will create it.

Q: Could you specify HTMLForm attributes, like hide-if to the JsonSchema to hide a field conditionally
A: HTMLForm is isn't used for the CommunityConfiguration, so you can't specify such values (like hide-if).

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
debt triaged this task as Medium priority.Apr 22 2024, 2:43 PM

Notes:

Make your extension community configurable

Date and time: May 4, 2025, 10:30

Relevant links

Presenter

[[User:Martin Urbanec (WMF)|Martin Urbanec (WMF)]], [[User:MGrosse-WMF|MGrosse-WMF]]

Participants

Notes

Introductions by Martin and Michael
We will show you converting an extension to using CommunityConfiguration, and then the second half is that we will get you to convert some extensions. We have a list in case you do not have any in mind specifically.
We will start converting the HackathonExtension ( https://gitlab.wikimedia.org/repos/growth/hackathon-extension )
The extension allows the background site colour to be changed and also shows a special page that provides information about the site.
The Special:GetSiteInfo page displays the database name, database username, whether growth experiments are enabled, and the background colour of the site
A schema defines and validates the configuration options that are availible to the user to configure on-wiki. We do this by creating a schema class which extends the JsonSchema class from the CommunityConfiguration extension.
Configuration values are defined via constants in the schema class where the name is the name of the configuration value. You must define a type and default, as the CommunityConfiguration extension could have errors otherwise
Then you add a attribute to the extension.json which is named "CommunityConfiguration". There is another example extension which has this code defined that you can use. The configuration here defines where the configuration is stored. This is currently only on a wikipage that contains JSON. The validator is defined as the class we created in the first step.
Types - "type": "Data" and "type":"mw-config"
After these steps, the community configuration should be set up on the special page but is not completely ready. We will also need to define i18n messages that are generated by the Special:CommunityConfiguration page. Some of these are required, such as the title but other message keys are not required and if not specified would be ignored.
Then you define a service which is the name of the extension plus "CommunityConfiguration". This allows you to use this service to get the values that are configured, and if the extension is not installed then it loads the main config instead of the value from the JSON file on-wiki.
Then we replace all uses of ::getConfig with this new service. You can do this by injecting the service which can be marked as the "Config" type. It can use a configuration value from the extension that is not defined in the community configuration config. This means that the values can be updated in the schema without having to replace calls to ::getConfig a future change.
The JSON file it also validated to ensure that if a user modified the JSON file directly it does not break the config.

Questions

Q: Do we have a option for chips, like select box or
A: We have several different types including numbers, boolean, strings, page titles, namespaces. We will figure out more once we have use cases for them.

Q: What if I want to add search inputs which are conditional. For example, if I click the 'A' switch I want to show the 'B' switch
A: It is possible to do this. What we want to add sectioning so that you can define which section it is in. If you have more complex problems.

Q: Could we restrict the form to a specific right?
A: The right is currently interfaceadmin, but a logged out user can still view the form and the data that is currently saved (as well as the history). To do this you could define a custom provider class and then override the user rights check. The configuration being shown needs to be public as anyone can view it unless you define your own store. This get complicated quickly, as you will also need to override the form and also need to put history somewhere.

Q: Is it possible to contribute to the CommunityConfiguration extension to add new configuration types? Does it use Codex?
A: Yes it uses codex. CommunityConfiguration is on gerrit, so you can submit patches.

Q: Is it possible to get the community configured data via a community configuration API? I am using VueJS which means I'd like to get this configuration over the API
A: It should be there, but it doesn't seem to be. I will create it.

Q: Could you specify HTMLForm attributes, like hide-if to the JsonSchema to hide a field conditionally
A: HTMLForm is isn't used for the CommunityConfiguration, so you can't specify such values (like hide-if).