[MediaWiki-l] extension.json, onRegistration

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[MediaWiki-l] extension.json, onRegistration

Sigbert Klinke
Hi,

for my Iframe extension I need to load some data. Since the data come
from a file I did not put it into extension.json, but I defined in my
class a function onRegistration with sets a global variable.

However, it turned out that in LocalSettings.php I can not set the
global variable (after calling wfLoadExtesnion('Iframe') ), var_dump
delivers NULL rather than my file data.

Question: where I have to put the reading of my file data (if not into
onRegistration) ?

Thanks Sigbert

--
https://hu.berlin/sk
https://hu.berlin/mmstat3

_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: extension.json, onRegistration

Tobias Oetterer
Hey Sigbert

In your extension.json have something like
        "callback": "Iframe::onRegistration",

You should also register your config variables in extension.json. For instance:
        "config": {
                "IFrameExternalJSONFile": false,
                "IFrameDifferentSetting": 42
        },

The callback is executed during the setup process, after the LocalSettings has been processed in total. It is not called directly when wfLoadExtension('Iframe') is called. So you can add your setting after the wfLoadExtension('Iframe')-call:
        wfLoadExtesnion('Iframe');
        $wgIFrameExternalJSONFile = __DIR__ . '/nice.json';


Inside the onRegistration() method, you can either use $GLOBALS or use the ConfigFactory to access the setting:
$json = $GLOBALS['wgIFrameExternalJSONFile']

$configFactory = MediaWikiServices::getInstance()->getConfigFactory();
$configFactory->register( 'IFrame', 'GlobalVarConfig::newInstance' ); // this is necessary due to a bug in the extension registration process, see [0]
$myConfig = $configFactory->makeConfig(  'Iframe' );
$json = $myConfig->get( 'IFrameExternalJSONFile' )

I know, the use of the config factory looks like a little bit of an overkill, however since mw wants to steer away from using globals, this is the safer way to go.

[0]: https://phabricator.wikimedia.org/T184837

Cheers,
Tobias
--
If this email is rather brief, it is not meant to be impolite but to respect your time.
http://five.sentenc.es
No trees were killed to send this message, but a large number of electrons were terribly inconvenienced

> -----Urspr√ľngliche Nachricht-----
> Von: MediaWiki-l [mailto:[hidden email]] Im
> Auftrag von Sigbert Klinke
> Gesendet: Dienstag, 13. Februar 2018 10:22
> An: MediaWiki announcements and site admin list <mediawiki-
> [hidden email]>
> Betreff: [MediaWiki-l] extension.json, onRegistration
>
> Hi,
>
> for my Iframe extension I need to load some data. Since the data come from
> a file I did not put it into extension.json, but I defined in my class a function
> onRegistration with sets a global variable.
>
> However, it turned out that in LocalSettings.php I can not set the global
> variable (after calling wfLoadExtesnion('Iframe') ), var_dump delivers NULL
> rather than my file data.
>
> Question: where I have to put the reading of my file data (if not into
> onRegistration) ?
>
> Thanks Sigbert
>
> --
> https://hu.berlin/sk
> https://hu.berlin/mmstat3
>
> _______________________________________________
> MediaWiki-l mailing list
> To unsubscribe, go to:
> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l