Re: Get a configuration variable at runtime

Bartosz Dziewoński <[email protected]>
Newsgroups gmane.science.linguistics.wikipedia.technical
Message-ID <[email protected]>
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/
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.