Samwilson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371077 )

Change subject: Add new-style configuration values with prefix
......................................................................

Add new-style configuration values with prefix

This adds a configuration prefix and an example of how to use it.

Bug: T97105
Change-Id: Icbc643487427964e6eee9ba8df78ad78e7b87d14
---
M BoilerPlate.hooks.php
M extension.json
M specials/SpecialHelloWorld.php
3 files changed, 27 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BoilerPlate 
refs/changes/77/371077/1

diff --git a/BoilerPlate.hooks.php b/BoilerPlate.hooks.php
index e96cba0..f850b31 100644
--- a/BoilerPlate.hooks.php
+++ b/BoilerPlate.hooks.php
@@ -8,4 +8,11 @@
 
 class BoilerPlateHooks {
 
+       /**
+        * @return GlobalVarConfig
+        */
+       public static function makeConfig() {
+               return new GlobalVarConfig( 'boilerplate' );
+       }
+
 }
diff --git a/extension.json b/extension.json
index 10cde12..852177e 100644
--- a/extension.json
+++ b/extension.json
@@ -12,8 +12,15 @@
                "BoilerPlateHooks": "BoilerPlate.hooks.php",
                "SpecialHelloWorld": "specials/SpecialHelloWorld.php"
        },
+       "config_prefix": "boilerplate",
+       "ConfigRegistry": {
+               "boilerplate": "BoilerPlateHooks::makeConfig"
+       },
        "config": {
-               "BoilerPlateEnableFoo": true
+               "EnableFoo": {
+                       "value": true,
+                       "description": "Whether or not the foo feature is 
enabled."
+               }
        },
        "ExtensionMessagesFiles": {
                "BoilerPlateAlias": "BoilerPlate.i18n.alias.php"
@@ -48,5 +55,5 @@
        "SpecialPages": {
                "HelloWorld": "SpecialHelloWorld"
        },
-       "manifest_version": 1
+       "manifest_version": 2
 }
diff --git a/specials/SpecialHelloWorld.php b/specials/SpecialHelloWorld.php
index 0b5057e..58d4b8a 100644
--- a/specials/SpecialHelloWorld.php
+++ b/specials/SpecialHelloWorld.php
@@ -6,6 +6,8 @@
  * @ingroup Extensions
  */
 
+use MediaWiki\MediaWikiServices;
+
 class SpecialHelloWorld extends SpecialPage {
        public function __construct() {
                parent::__construct( 'HelloWorld' );
@@ -61,8 +63,13 @@
                                'label' => 'Weapons to use',
                                'options' => [ 'Cannons' => 'cannon', 'Swords' 
=> 'sword' ],
                                'default' => [ 'sword' ],
-                       ],
-                       'radiolol' => [
+                       ]
+               ];
+
+               // If foo is enabled, add another form field.
+               $config = 
MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'boilerplate' 
);
+               if ( $config->get( 'EnableFoo' ) ) {
+                       $formDescriptor['radiolol'] = [
                                'class' => 'HTMLRadioField',
                                'label' => 'Who do you like?',
                                'options' => [
@@ -71,8 +78,8 @@
                                        'both' => 'Both'
                                ],
                                'default' => 'pirates',
-                       ],
-               ];
+                       ];
+               }
 
                // $htmlForm = new HTMLForm( $formDescriptor, 
$this->getContext(), 'testform' );
                $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, 
$this->getContext(), 'testform' );

-- 
To view, visit https://gerrit.wikimedia.org/r/371077
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icbc643487427964e6eee9ba8df78ad78e7b87d14
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BoilerPlate
Gerrit-Branch: master
Gerrit-Owner: Samwilson <s...@samwilson.id.au>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to