Re: Get a configuration variable at runtime

Brian Wolff <[email protected]>
Newsgroups gmane.science.linguistics.wikipedia.technical
Message-ID <CA+oo+DW9cY4T_AhDSXvhvnZ6PFMwL+jcFdqWnOSfLbdnit4AHw@mail.gmail.com>
> This is a very obscure corner of MediaWiki, it took me a while to get
this working. I'm not even sure what is the division of responsibility
between WikiMap and SiteLookup.

I think WikiMap was first. Site was added later for wikidata without much
consideration for what came before. I think the difference was that Site
was more tied to the Site DB table and WikiMap is more based around
$wgConf. In any case, i suspect the two classes should be merged in theory
as both do basically the same thing.

--
Brian


On Thursday, 18 December 2025, Bartosz Dziewoński <[email protected]>
wrote:

> On 2025-12-19 00:08, Brian Wolff wrote:
>
>> Why cant you use the MediaWikiSite class to get a site reference, call
>> ->getLanguageCode() then make a language object and use the language object
>> to get the direction?
>>
>
> Indeed, this is the best advice for this case. Just to expand on it, since
> there are several non-obvious steps:
>
>     use MediaWiki\WikiMap\WikiMap;
>     $services = MediaWiki\MediaWikiServices::getInstance();
>
>     $wikiId = WikiMap::getWikiFromUrl( 'https://en.wikipedia.org/' );
>     // $wikiId is a string like 'enwiki' or false if the URL isn't known
>     $site = $services->getSiteLookup()->getSite( $wikiId );
>     $langCode = $site->getLanguageCode();
>     // $langCode is a string like 'en' or null if it's not known
>     $lang = $services->getLanguageFactory()->getLanguage( $langCode );
>     $dir = $lang->getDir();
>     // $dir is a string: 'ltr' or 'rtl'
>
> This is a very obscure corner of MediaWiki, it took me a while to get this
> working. I'm not even sure what is the division of responsibility between
> WikiMap and SiteLookup.
>
> Each wiki in a wiki farm knows a little bit about every other wiki, but
> only a little bit. You can use these classes to look up the language code
> or format links, but not much more than that. It doesn't know all of the
> configuration, so if you ever need e.g. the list of namespaces on the other
> wiki, you'll need to fall back to doing API requests to the 'siteinfo' API
> or make up some configuration of your own.
>
> --
> Bartosz Dziewoński
> _______________________________________________
> Wikitech-l mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://lists.wikimedia.org/postorius/lists/wikitech-l.lists
> .wikimedia.org/

_______________________________________________
Wikitech-l mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.