Mailing List Archive

How to add a custom Magic Word in LocalSettings.php?
Could you explain please how to add a custom magic word to mediawiki
LocalSettings.php?

Example:
When writing in the wiki {{CUSTOM_VARIABLE}} it will expand to:
custom-content

In other words... I want to set in LocalSettings.php

$CUSTOM_VARIABLE = "custom-content";

and that custom variable should then be available inside the wiki be as
{{CUSTOM_VARIABLE}}.

If avoidable, writing a mediawiki extension should be avoided.

Is this possible?

Cheers,
Patrick
_______________________________________________
MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
Re: How to add a custom Magic Word in LocalSettings.php? [ In reply to ]
LocalSettings.php is probably not the right place for doing that.

Magic words are added using extensions.

However, magic words are really necessary only when the custom content that
you want to add is so complicated that it can be generated only by
complicated PHP code or when you need a convenient way to use the same
functionality on many wikis.

If you need it only for one wiki, and the content is not exceptionally
complicated, then it's quite possible that you can achieve the thing you
want simply by creating a template on the wiki itself. Read more about it
here:
https://www.mediawiki.org/wiki/Help:Templates
https://en.wikipedia.org/wiki/Help:Template

Templates are written using the same wikitext as usual wiki pages. If you
want to write it using an actual programming language, install the
Scribunto extension, and write a module in Lua. See:
https://www.mediawiki.org/wiki/Extension:Scribunto

--
Amir Elisha Aharoni · ?????? ????????? ??????????
http://aharoni.wordpress.com
?“We're living in pieces,
I want to live in peace.” – T. Moore?


??????? ??? ??, 29 ????? 2021 ?-12:46 ??? ?Patrick Schleizer via
MediaWiki-l?? <?mediawiki-l@lists.wikimedia.org??>:?

> Could you explain please how to add a custom magic word to mediawiki
> LocalSettings.php?
>
> Example:
> When writing in the wiki {{CUSTOM_VARIABLE}} it will expand to:
> custom-content
>
> In other words... I want to set in LocalSettings.php
>
> $CUSTOM_VARIABLE = "custom-content";
>
> and that custom variable should then be available inside the wiki be as
> {{CUSTOM_VARIABLE}}.
>
> If avoidable, writing a mediawiki extension should be avoided.
>
> Is this possible?
>
> Cheers,
> Patrick
> _______________________________________________
> MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
> To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
>
> https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
>
Re: How to add a custom Magic Word in LocalSettings.php? [ In reply to ]
Hi Valerio!

Thank you for looking into this.

Reviewing these links implies that this requires an extension? So it
cannot be done simply, directly from LocalSettings.php?

Could you provide please a minimal example how to set as
$CUSTOM_VARIABLE = "custom-content";?

Template are generally awesome but won't work here.

The use case here is multiple domain support, an alternative domain name
accessing the same wiki/database, which already works great for me.

What I really want to set is something similar to

{{SERVER}} = //www.example.com
{{SERVERNAME}} = www.example.com

But I only need

{{CUSTOM_APEX_DOMAIN_NAME}} = example.com

The use case in mediawiki markup would then be:

[{{protocoll_handler}}://forums.{{apex_domain_name}} our forums]

(I.e. "relative domain names which support sub domain changes")

This is the multiple domain support snippet which already works for me:

###

if (preg_match("/onion.onion/i", $_SERVER['SERVER_NAME'])) {
$wgServer = 'http://www.onion.onion';
$wgCanonicalServer = 'https://www.example.com';
$wgAllowExternalImagesFrom = array( 'http://127.0.0.1/',
'http://www.onion.onion/' );
$wgRenderHashAppend = "www.onion.onion";
$wgCachePrefix = "www.onion.onion";
$wgFileCacheDirectory = "$IP/cache/www.onion.onion";
$wgLocalisationUpdateDirectory = "$IP/cache/www.onion.onion";
$wgCacheDirectory = "$IP/cache/www.onion.onion";
$MY_FQDN = "http://www.onion.onion";
} else {
$wgServer = '//www.example.com';
$wgCanonicalServer = 'https://www.example.com';
$wgAllowExternalImagesFrom = array( 'http://127.0.0.1/',
'https://www.example.com/' );
$wgRenderHashAppend = "www.example.com";
$wgCachePrefix = "www.example.com";
$wgFileCacheDirectory = "$IP/cache/www.example.com";
$wgLocalisationUpdateDirectory = "$IP/cache/www.example.com";
$wgCacheDirectory = "$IP/cache/www.example.com";
$MY_FQDN = "https://www.example.com";
}

###

If I had the snippet to add custom magic words to LocalSettings.php,
then kinda what I would add there is this:

if (preg_match("/onion.onion/i", $_SERVER['SERVER_NAME'])) {
$CUSTOM_APEX_DOMAIN_NAME = 'onion.onion';
} else {
$CUSTOM_APEX_DOMAIN_NAME = 'example.com';
}

Basically, how would I make $CUSTOM_APEX_DOMAIN_NAME available from
inside the mediawiki?

I've left the lengthy description of my use case out from my original
post for brevity.

Kind regards,
Patrick

Valerio Bozzolan:
> Hi Patrick
> Here some documentation for your specific question:
> https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/ParserFunctions/+/refs/heads/master/includes/Hooks.php
> https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit
> Having said that, do you really need it? Why not just a new template?
> Create a page [[Template:Something]] to use {{Something}}.
> -boz
> On mer, 2021-12-29 at 10:46 +0000, Patrick Schleizer via MediaWiki-l
> wrote:
>> Could you explain please how to add a custom magic word to mediawiki
>> LocalSettings.php?
>>
>> Example:
>> When writing in the wiki {{CUSTOM_VARIABLE}} it will expand to:
>> custom-content
>>
>> In other words... I want to set in LocalSettings.php
>>
>> $CUSTOM_VARIABLE = "custom-content";
>>
>> and that custom variable should then be available inside the wiki be
>> as
>> {{CUSTOM_VARIABLE}}.
>>
>> If avoidable, writing a mediawiki extension should be avoided.
>>
>> Is this possible?
>>
>> Cheers,
>> Patrick
>> _______________________________________________
>> MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
>> To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
>> https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
_______________________________________________
MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/