Page MenuHomePhabricator

Clean up languages/ directory in MediaWiki core (June 2019)
Closed, ResolvedPublic

Description

The code being split between includes/ and languages/ can be confusing at times and as part of T166010 this would be expected to change regardless.

This task is to start thinking about that specifically for the languages/ directory:

  • How we want to organise it going forward?
  • What (if anything) external to MW would need to be updated? Due to these classes having been in this place for a long time, it's possible various (automated) workflows might have come to depend on their precise location.
  • What do we want to do with files that cannot be autoloaded?
Easy ones

The following are presumably easy candidates to move over without much complication:

  • LanguageCode
  • MessageLocalizer
  • ConverterRule
  • LanguageConverter
  • FakeConverter
  • Language

These could go to includes/language/, alongside the Message class which is already on the "includes" side.

Data files

The data files (those that do not declare functions or classes, but rather return data or export local variables) could go to includes/languages/data similar to what various other sub directories do already (such as includes/collation/).

Language sub classes

These could move over now as well. Or should we keep out of includes/, for proximity with non-code files in messages/ and i18n/ files?

PHP Message files

These are neither clean data files, nor autoloaded classes. They are files that declare local variables in a to-be-included local scope. This is pretty hacky and might be time to convert to a simple static array file that returns these as keys. This should also make the reading of these files much easier to deal with.

Misc files
  • CrhExceptions

This is organised like a data file, but is actually a class with methods. Unsure where it should go.

  • Names.php and ZhConversion.php

An autoloaded class file, but stored in the data directory and uses "data" as actual part of its class name hierarchy as well. (For other components in "includes/" the data file is usually associated with files that are not in the class hierarchy but related to the files nearby). Having the class hierarchy overlap with a "data/" subdirectory might be confusing. In particular, after the PSR-4 transformation this would currently cause there to be two directories that only differ by case-sensitivity (includes/Language/Data and includes/Language/data). That's probably something we want to avoid.

Maybe we'll rename all "data" subdirectories that contain non-class to "Data" to accomodate this issue. Or maybe this could be renamed something that doesn't have "Data" in its namespace path (with back-compat alias). Or something else?

Event Timeline

Change 516955 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] [WIP] language: Move some language-related classes to includes/language/

https://gerrit.wikimedia.org/r/516955

Change 516955 merged by jenkins-bot:
[mediawiki/core@master] language: Move some language-related classes to includes/language/

https://gerrit.wikimedia.org/r/516955

Krinkle updated the task description. (Show Details)
Krinkle updated the task description. (Show Details)

I would be reluctant to move the data files under includes/. The fact that some of them are currently PHP files is just an implementation detail in my opinion.

Also, T190129: Consolidate language metadata into a 'language-data' library and use in MediaWiki purports to drop some of that data in favor of using a more comprehensive data library.

I would be reluctant to move the data files under includes/. The fact that some of them are currently PHP files is just an implementation detail in my opinion.

I agree. The reason I propose moving them is not related to them using PHP syntax. includes/ is where our source files reside, including any data files that a component may need to read. This includes (in MediaWiki core) files with PHP classes, PHP functions, PHP constants, any files read by PHP files such as data in cdb or json or php format, shell scripts, MIME lists, ICC profile, Firejail profile, or Mustache templates used by PHP. None these kinds of files have ever been stored elsewhere afaik, with the exception of maintenance/ and language/.

Change 523009 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] tests: Move unit/languages to unit/includes/language

https://gerrit.wikimedia.org/r/523009

Change 523009 merged by jenkins-bot:
[mediawiki/core@master] tests: Move unit/languages to unit/includes/language

https://gerrit.wikimedia.org/r/523009

Change 532258 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] language: Move ConverterRule to includes/ and add unit test

https://gerrit.wikimedia.org/r/532258

Change 532258 merged by jenkins-bot:
[mediawiki/core@master] language: Move ConverterRule to includes/ and add test case

https://gerrit.wikimedia.org/r/532258

Change 608977 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] language: Move LanguageConverterFactory and TrivialLanguageConverter to includes/

https://gerrit.wikimedia.org/r/c/mediawiki/core/ /608977

Change 608979 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] languages: Put remaining language Hook interfaces under includes/

https://gerrit.wikimedia.org/r/c/mediawiki/core/ /608979

Change 608977 merged by jenkins-bot:
[mediawiki/core@master] language: Move LanguageConverterFactory and TrivialLanguageConverter to includes/

https://gerrit.wikimedia.org/r/c/mediawiki/core/ /608977

Change 608979 merged by jenkins-bot:
[mediawiki/core@master] language: Put remaining language Hook interfaces under includes/

https://gerrit.wikimedia.org/r/c/mediawiki/core/ /608979

eprodromou added a subscriber: eprodromou.

Looks like everything is merged, so tag us if you need us, otherwise we'll let this one go.

Change 709226 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] Move Language subclasses to includes/

https://gerrit.wikimedia.org/r/709226

Change 709783 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] language: Autoload normalize data and remove transformUsingPairFile compat

https://gerrit.wikimedia.org/r/709783

Change 709806 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] localisation: Remove conditional for `plurals-mediawiki.xml` file

https://gerrit.wikimedia.org/r/709806

Change 710131 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] language: Add MediaWiki\\Languages\\Data namespace to PSR-4 autoloader

https://gerrit.wikimedia.org/r/710131

Change 709226 merged by jenkins-bot:

[mediawiki/core@master] Move Language subclasses to includes/

https://gerrit.wikimedia.org/r/709226

Change 709783 merged by jenkins-bot:

[mediawiki/core@master] language: Autoload normalize data and remove transformUsingPairFile compat

https://gerrit.wikimedia.org/r/709783

Change 709806 merged by jenkins-bot:

[mediawiki/core@master] localisation: Remove conditional for `plurals-mediawiki.xml` file

https://gerrit.wikimedia.org/r/709806

Change 710131 merged by jenkins-bot:

[mediawiki/core@master] language: Add MediaWiki\\Languages\\Data namespace to PSR-4 autoloader

https://gerrit.wikimedia.org/r/710131

Change 807649 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] language: Move l10n-related classes from /cache to /language/cache

https://gerrit.wikimedia.org/r/807649

Change 807649 merged by jenkins-bot:

[mediawiki/core@master] language: Move l10n-related classes from /cache to /language

https://gerrit.wikimedia.org/r/807649