aboutsummaryrefslogtreecommitdiffstats
path: root/includes/language/LanguageFactory.php
Commit message (Collapse)AuthorAgeFilesLines
* Language: Introduce getContentLanguageCode() serviceAmir Sarabadani2024-10-161-0/+8
| | | | | | | | | | | | | | | And use that as much as possible. This makes bootstraping services much faster since Language object is extremely heavy (specially to initialize) and that's why in LanguageFactory it's behind a cache (see LanguageFactory::getRawLanguage) At the same time, most uses of Language object only need the language code (after normalization and mapping and validation) and this allows such change to happen fast and way more decoupled from Language object that has more than 100 methods. Bug: T376565 Change-Id: I1c3d94454896842939dfaad8cbf742e5a3ae5438
* Move Language and friends into Language namespaceJames D. Forrester2024-08-101-3/+3
| | | | | Bug: T353458 Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
* Language: minor cleanupReedy2023-10-021-4/+4
| | | | | | | * Remove unnecessary duplicate documentation * Code tweaks Change-Id: I9c8c190bee58195eace08cba18a51e4572896ef7
* Merge "Allow Bcp47Code as parameter to LanguageCode::bcp47ToInternal()"jenkins-bot2023-09-291-2/+2
|\
| * Allow Bcp47Code as parameter to LanguageCode::bcp47ToInternal()C. Scott Ananian2023-09-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This nominally takes a string-valued language code conforming to the BCP-47 standard, but this is often generated from a Bcp47Code object. Since the MediaWiki Language code implements Bcp47Code, we may have the case where we have a Language object in hand (but typed as a Bcp47Code not Language) and call Language::toBcp47Code() only to pass it to LanguageCode::bcp47ToInternal to convert it back to a mediawiki-internal code. We can save steps and be more efficient if allow the parameter to be a Bcp47Code object, and write a fast path for the special case where that Bcp47Code happens to be a Language object and we can simply call Language::getCode() to obtain the internal code. Change-Id: I24932449b8c40e3a5072748d87667184f4befa67
* | Namespace Config-related classes under \MediaWiki\ConfigJames D. Forrester2023-09-211-1/+1
| | | | | | | | | | Bug: T166010 Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
* | Namespace NamespaceInfo under \MediaWiki\TitleJames D. Forrester2023-09-191-1/+1
|/ | | | | | | One of the big ones, so doing this alone. Bug: T166010 Change-Id: Ibe103cd362535d3cb94cb8931e95fc74099d1497
* Make LanguageFactory::getParentLanguage() consistent with ::getLanguage()C. Scott Ananian2023-01-311-2/+14
| | | | | | | | | | | Allow Bcp47Code (which includes Language) as a parameter to ::getParentLanguage(), to match what was added in Iea158fc849964ba71a27363f9522b1b3bbb82aee. Add a note to warn callers that ::getParentLanguage() does *not* accept the same set of string codes as ::getLanguage(); however if you pass an object instead of a string the behavior matches. Change-Id: I89c581ea12b354d8988c1ae8787a05976b8e3143
* Accept a Bcp47Code object in LanguageFactory::getLanguage()C. Scott Ananian2023-01-301-4/+25
| | | | | | | | | | | | | | This is an efficient and safe downcast if the parameter is already a Language object (since Language implements the Bcp47Code interface); otherwise it does the appropriate conversion to a MediaWiki-internal code and creates the appropriate language object. Note that there are some ambiguities in the internal codes, such that: LanguageFactory::getLanguage( 'egl' )->getCode() # returns 'egl' while: Bcp47Code $bcp = new Bcp47CodeValue( 'egl' ); LanguageFactory::getLanguage( $bcp )->getCode() # returns 'eml' Change-Id: Iea158fc849964ba71a27363f9522b1b3bbb82aee
* LanguageFactory: Avoid MWException and @throws per conventionsBartosz Dziewoński2022-11-281-9/+14
| | | | | | | | | | | | | | Change code to match the consensus currently forming on T321683. People really liked to catch this exception… Depends-On: I017d6c3406bf7a15c6a6196dcc5fc5e73ea67e7c Depends-On: Ifcb31dbb7113ce57526f06558cde2abedee317d7 Depends-On: I3079d8e18d88a4a26c2f2b09dccd4beea06678ee Depends-On: I0eca885a9eb8ae2c422a82b40c1dbef4ca818a59 Depends-On: Iede248c84a76513bad40f4a5130fc5726cd88569 Depends-On: I7520a71a53a09762e6cad0797e374f6df32d40cc Change-Id: I869af06896b9757af18488b916211c5a41a8c563
* Add a new function LanguageFactory::getRawLanguageFomafix2022-09-041-0/+14
| | | | | | | | | | | The new function getRawLanguage does not replace DummyLanguageCodes. Use the new function getRawLanguage on AllMessagesTablePager. This allows to see system messages defined in a dummy or deprecated language code. Bug: T315665 Change-Id: I4569d8106b8b6e0b637bb529a6cf48191d69ec5b
* language: Add missing `@ingroup`, subgroup "Languages" and ungroup filesTimo Tijhof2022-06-281-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | == Ungroup file blocks Remove `@ingroup` from `@file` blocks and keep only the class block. This matches similar changes previously applied to API, Skins, Profile, and ResourceLoader. This helps make the API documentation easier to navigate. E.g. Modules -> Language in the sidebar of <https://doc.wikimedia.org/mediawiki-core/master/php/> as well as <https://doc.wikimedia.org/mediawiki-core/master/php/group__Language.html> These are currently cluttered with tons of duplicate entries for files and classes both. We only need to group files that aren't also documented as a class (e.g. message files, entry points, other scripts or files that we mainly consider a data file). This has the helpful side-effect that we don't encourage duplication of the class description (or worse, place useful docs only in the file block), and makes the class files consistently start with a mentally ignorable block. Basically, unless there's something other than a class, don't describe or group the file itself. == Missing group Various classes in this subtree were missing the `Language` group, or were using different group from before T225756. == Subgroup For ease of navigation, move Converter subclasses to a group called "Languages", which for documentation purposes is a subgroup of "Language". The next commit does the same for Messages* files, and Language subclasses (done separately for ease of review). Change-Id: I301f471f86ba2dee924fece29a16dc3c20b5bebe
* Language: Inject NamespaceInfoBartosz Dziewoński2022-05-111-0/+8
| | | | Change-Id: I90eee60467698bbefb619bfa69abfaa10c759fea
* Use MainConfigNames instead of string literals, #4Aryeh Gregor2022-04-261-2/+3
| | | | | | | | | | | | | | | | | | | | | Now largely automated: VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \ tr "\n" '|' | sed "s/|$/\n/;s/'//g") sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \ $(grep -ERIl "'($VARS)'" includes/) Then git add -p with lots of error-prone manual checking. Then semi-manually add all the necessary "use" lines: vim $(grep -L 'use MediaWiki\\MainConfigNames;' \ $(git diff --cached --name-only --diff-filter=M HEAD^)) I didn't bother fixing lines that were over 100 characters unless they were over 120 and triggered phpcs. Bug: T305805 Change-Id: I74e0ab511abecb276717ad4276a124760a268147
* Language: retrieve MainConfig instead of using a bunch of globalsDannyS7122022-03-151-2/+13
| | | | Change-Id: I791af9197a4a53723adf2869d7b3b9f41fe9c059
* Use hasVariant in loop to determine parent language in LanguageFactoryFunc2021-12-061-10/+9
| | | | | | | Code of some language's parent language can't simply strip out the subcode. e.g. ike-cans should get iu. Change-Id: I4cf5bb1ddc463a8d98064451dd8e4dbebeca96e9
* Use getWithSetCallback() instead of get() + set()Daimona Eaytoy2021-11-181-8/+6
| | | | | | | This allows the backend to do whatever it can to ensure atomicity, and is also easier to read, since the intent is obvious. Change-Id: Ibbfecd92a2c6d9a5997ca37ea101e068bd1e8202
* language: Remove $wgLangObjCacheSize from LanguageFactoryTimo Tijhof2021-08-011-14/+10
| | | | | | | | | | | | | | | | | The $wgLangObjCacheSize configuration variable was added in 2012 with commit 121cf60119814. From what I could gather, no-one has ever needed to change its value. Not for any WMF wikis, not for heavy-duty special-purpose wikis like translatewiki.net, not for any third-parties that have public configuration files (e.g. Fandom, WikiApiary, Miraheze), not for developer environments, and not for test suites. This follows-up 0484ac9e7a88dfc1, where the implementation changed from a FIFO array to use MapCacheLRU (which requires a non-zero size) and thus introduced conditional complexity and code duplication. This could be simplified by other means, but it seems like we could just remove it. Change-Id: I5143e238857f760f2a2ab6f2e0af174872e9cd43
* Remove deprecated Language::$mLangObjCachePetr Pchelko2021-07-261-25/+12
| | | | | | | | Removing this deprecated cache allows LanguageFactory to start using MapCacheLRU instead of implementing LRU semantics manually. Change-Id: I8093067fb6f51110351b8592fcbcfa7559d942ee
* build: Updating dependencieslibraryupgrader2021-07-221-2/+2
| | | | | | | | | | | | | | composer: * mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0 The following sniffs now pass and were enabled: * Generic.ControlStructures.InlineControlStructure * MediaWiki.PHPUnit.AssertCount.NotUsed npm: * svgo: 2.3.0 → 2.3.1 * https://npmjs.com/advisories/1754 (CVE-2021-33587) Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
* Mark CONSTRUCTOR_OPTIONS as internalAryeh Gregor2020-08-211-2/+1
| | | | | | | | These were never meant to be part of the public interface and should not ever have been marked with @since. They're only useful for constructing the respective objects, which no outside users should be doing. Change-Id: I86e01272d46fc72af32172d8a12b9180971d4613
* language: Improve documentation of bool return values and suchThiemo Kreuz2020-07-141-2/+3
| | | | Change-Id: I9e2680b10473115a4d9af1083fbd2484af1c23f4
* Hooks::run() call site migrationTim Starling2020-05-301-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Migrate all callers of Hooks::run() to use the new HookContainer/HookRunner system. General principles: * Use DI if it is already used. We're not changing the way state is managed in this patch. * HookContainer is always injected, not HookRunner. HookContainer is a service, it's a more generic interface, it is the only thing that provides isRegistered() which is needed in some cases, and a HookRunner can be efficiently constructed from it (confirmed by benchmark). Because HookContainer is needed for object construction, it is also needed by all factories. * "Ask your friendly local base class". Big hierarchies like SpecialPage and ApiBase have getHookContainer() and getHookRunner() methods in the base class, and classes that extend that base class are not expected to know or care where the base class gets its HookContainer from. * ProtectedHookAccessorTrait provides protected getHookContainer() and getHookRunner() methods, getting them from the global service container. The point of this is to ease migration to DI by ensuring that call sites ask their local friendly base class rather than getting a HookRunner from the service container directly. * Private $this->hookRunner. In some smaller classes where accessor methods did not seem warranted, there is a private HookRunner property which is accessed directly. Very rarely (two cases), there is a protected property, for consistency with code that conventionally assumes protected=private, but in cases where the class might actually be overridden, a protected accessor is preferred over a protected property. * The last resort: Hooks::runner(). Mostly for static, file-scope and global code. In a few cases it was used for objects with broken construction schemes, out of horror or laziness. Constructors with new required arguments: * AuthManager * BadFileLookup * BlockManager * ClassicInterwikiLookup * ContentHandlerFactory * ContentSecurityPolicy * DefaultOptionsManager * DerivedPageDataUpdater * FullSearchResultWidget * HtmlCacheUpdater * LanguageFactory * LanguageNameUtils * LinkRenderer * LinkRendererFactory * LocalisationCache * MagicWordFactory * MessageCache * NamespaceInfo * PageEditStash * PageHandlerFactory * PageUpdater * ParserFactory * PermissionManager * RevisionStore * RevisionStoreFactory * SearchEngineConfig * SearchEngineFactory * SearchFormWidget * SearchNearMatcher * SessionBackend * SpecialPageFactory * UserNameUtils * UserOptionsManager * WatchedItemQueryService * WatchedItemStore Constructors with new optional arguments: * DefaultPreferencesFactory * Language * LinkHolderArray * MovePage * Parser * ParserCache * PasswordReset * Router setHookContainer() now required after construction: * AuthenticationProvider * ResourceLoaderModule * SearchEngine Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
* language: Clean up file headers and class-level docsTimo Tijhof2020-02-121-4/+2
| | | | | | | | | | | | | | | | | | | This follows-up d83fcce5cb6, which did something similar for includes/profiler/. * Ensure presence of license header. * Merge any file-level descriptions with the class block, where it gets seen in generated docs about that class. * Add any missing `@ingroup` tags to class blocks. * Remove remaining `@ingroup` from file blocks. These clutter the Doxygen pages with duplicate entries. * Fix some misspelled words from 61e0908fa29 and f136c2953c62. Change-Id: I5d21ec159766b799ba519da951d4f0716bae5f9f
* languages: Introduce LanguageConverterFactoryPeter Ovchyn2020-02-031-3/+11
| | | | | | | | | | | | | | | | | | | Done: * Replace LanguageConverter::newConverter by LanguageConverterFactory::getLanguageConverter * Remove LanguageConverter::newConverter from all subclasses * Add LanguageConverterFactory integration tests which covers all languages by their code. * Caching of LanguageConverters in factory * Make all tests running (hope that's would be enough) * Uncomment the deprecated functions. * Rename FakeConverter to TrivialLanguageConverter * Create ILanguageConverter to have shared ancestor * Make the LanguageConverter class abstract. * Create table with mapping between lang code and converter instead of using name convention * ILanguageConverter @internal * Clean up code Change-Id: I0e4d77de0f44e18c19956a1ffd69d30e63cf51bf Bug: T226833, T243332
* LanguageFactory to replace Language::factory()Aryeh Gregor2019-10-231-0/+215
Languages with variants no longer can override the parent's constructor (which is now used for injecting services). Instead, they need to override Language::newConverter(). Bug: T201405 Change-Id: I923400d61763cf1db88cb0c3f684c9c10e58032d