Hi all,
Sorry to be spamming this list due to my own incompetence. I'm basically doing an upgrade-a-thon of our various extensions to the new extension format, and therefore running into issues as I go.
In a previous email I discussed a problem I was having with the fact that the new extension registration doesn't support PHP constants, which I was using for explicit dependencies. Now I'm working on upgrading another extension where I use PHP constants to allow users to configure options for my extension.
My extension is called CommentStreams. In the old registration approach, inside of CommentStreams.php, I had three constants defined:
define('NS_COMMENTSTREAMS', 1000); define('CS_COMMENTS_EXPANDED', 0); define('CS_COMMENTS_COLLAPSED', 1);
NS_COMMENTSTREAMS is a custom namespace I define using the CanonicalNamespaces hook, but I wanted to expose this variable through a PHP constant so users could configure the extension in LocalSettings.php, for example for use with $wgNamespacesToBeSearchedDefault:
$wgNamespacesToBeSearchedDefault[NS_COMENTSTREAMS] = true;
(Of course I could just require the user of my extension to define NS_COMMENTSTREAMS in their own LocalSettings.php, but I wanted to encapsulate it in the extension so they wouldn't have to worry about it.)
The story with CS_COMMENTS_EXPANDED and CS_COMMENTS_COLLAPSED is similar - internally defined constants that I wanted to expose for users to be able to use to configure things in LocalSettings.php.
With the new extension registration, I tried to put these constant definitions inside of the custom registration https://www.mediawiki.org/wiki/Manual:Extension_registration#Customizing_registration callback function, hoping that this callback would be called before the rest of LocalSettings.php is parsed, so the usage could remain something like this:
wfLoadExtension('CommentStreams'); $wgNamespacesToBeSearchedDefault[NS_COMMENTSTREAMS] = true; // other configuration with CS_COMMENTS_EXPANDED or CS_COMMENTS_COLLAPSED
However, that doesn't seem to be the case - I get warnings of defined constants all over the place, breaking my functionality.
Is there a way around this? Alternatively, if this is bad coding practice (I do not profess to be well versed in good PHP convention, and I'm still learning good MediaWiki convention), is there a better way to handle this?
Thanks for the assistance!
-- Jason Ji jason.y.ji@gmail.com