Thank you, Bartozh. It took a couple of days, but I wrote the code, and
debugged almost all of it. The only part I couldn't debug is
$site = $siteLookup->getSite( $wikiId );
$langCode = $site->getLanguageCode();
because  $siteLookup->getSites of Patch Demo returns an empty array. All
the rest works fine. Thank you for your help again.
Igal


<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.www.avg.com
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

‫בתאריך יום ו׳, 19 בדצמ׳ 2025 ב-3:54 מאת ‪Bartosz Dziewoński‬‏ <‪
[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/
_______________________________________________
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/

Reply via email to