Commit graph

59 commits

Author SHA1 Message Date
Timo Tijhof
6c4f7ad9db localisation: Remove conditional for plurals-mediawiki.xml file
Follows-up bbbcf089db.

This file always exists. If we want to support disabling this, we
could introduce a configuration option rather than encouraging users to
apply core hacks by modifying or removing this file.

Also move the file paths into an array for re-use.

Bug: T225756
Change-Id: I6c86b5b0bdc4b0242bc406599eb0a172f17f2d03
2021-08-05 01:44:41 +00:00
Jack Phoenix
b326dd4352 Remove capitalize-all-nouns CSS class support
Functionality has been moved to MonoBook.

Bug: T97892
Change-Id: I3d4d74a2caa77f975b415af5977253ddeff6af21
Depends-On: I598c4469c46d284562ea3aec79330f9a1f40d2ce
2021-07-30 16:59:36 +00:00
libraryupgrader
5357695270 build: Updating dependencies
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
2021-07-22 03:36:05 +00:00
Tim Starling
9c3c0b704b Use array_fill_keys() instead of array_flip() if that reflects the developer's intention
array_fill_keys() was introduced in PHP 5.2.0 and works like
array_flip() except that it does only one thing (copying keys) instead
of two things (copying keys and values). That makes it faster and more
obvious.

When array_flip() calls were paired, I left them as is, because that
pattern is too cute. I couldn't kill something so cute.

Sometimes it was hard to figure out whether the values in array_flip()
result were used. That's the point of this change. If you use
array_fill_keys(), the intention is obvious.

Change-Id: If8d340a8bc816a15afec37e64f00106ae45e10ed
2021-06-15 00:11:10 +00:00
Thiemo Kreuz
6805f39a30 Remove unused default values from class properties
In all these cases the property is unconditionally set in
the constructor. The extra initialisation is effectively
dead code and an extra source of errors and confusion.

Change-Id: Icae13390d5ca5c14e2754f3be4eb956dd7f54ac4
2021-05-12 13:44:28 +02:00
Lucas Werkmeister
799716d78f Remove unneeded isset() before unset()
unset() does not throw an error if the value to be unset does not exist
in the first place, so guarding it with an isset() check is unnecessary.
Remove a few ifs that didn’t do anything else.

Change-Id: Ie5493c8a4c4d25e12a029d0257374527cd12303d
2020-11-10 16:52:14 +01:00
Aryeh Gregor
a24e8a06b5 Mark CONSTRUCTOR_OPTIONS as internal
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
2020-08-21 00:18:45 -04:00
Umherirrender
ba216e52e7 includes: Use expression assignment operator += or |= where possible
It is easier to read.

Change-Id: Ia3965b80153d64f95b415c6c30f526efa252f554
2020-07-31 22:26:42 +00:00
Kunal Mehta
0b43c49465 Revert "Add a new type of database to the installer from extension"
It caused a 20% latency regression by unconditionally parsing extension.json
files on every single load instead of using the existing caching
infrastructure. There are further problems with the use of parsing/loading
extension.json files in a method that is incompatible with the existing
architecture.

This primarily reverts commit 46eabe275c.

Also needed to revert 16381261ae and 7c72347ec1.

Bug: T258664
Change-Id: I34a783c3f0df0447876a26441bb2d12e02368871
2020-07-22 16:05:31 -07:00
jenkins-bot
8b2f44b6e7 Merge "phan: Enable redundant_condition_detection" 2020-07-02 00:28:10 +00:00
Umherirrender
bc5cb7ae64 phan: Enable redundant_condition_detection
Remove duplicate casts
Suppress false positives

Bug: T248438
Change-Id: I2f89664a4bcd3b39b15e7cf850adda2f0c90ae6f
2020-07-01 20:13:07 +00:00
ArtBaltai
46eabe275c Add a new type of database to the installer from extension
Decouple Installer services
Implement injection class Autoloader and i18n messages from extension.json
Implement extension selector by type
Add i18n message key `version-database`
Extensions for testing:
- https://github.com/MWStake/PerconaDB - real Percona extension
- https://github.com/killev/mediawiki-dbext2 - fake extension for test

Bug: T226857, T255151
Change-Id: I9ec8a18ad19283f6be67ac000110ac370afc0815
2020-06-26 13:37:32 +03:00
Tim Starling
68c433bd23 Hooks::run() call site migration
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
2020-05-30 14:23:28 +00:00
Reedy
b1e515e36e Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I4a30a44bc33fc98479799438d65342f6529e14f9
2020-05-16 00:51:46 +01:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Umherirrender
0688dd7c6d Set method visibility for various constructors
Change-Id: Id3c88257e866923b06e878ccdeddded7f08f2c98
2019-12-03 20:17:30 +01:00
Brad Jorsch
aa0720d37c ParamValidator: Use MessageValue!
Trying to get away with returning a single code and parameter-list that
was supposed to represent both human-readable and machine-readable data
was a mistake.

This patch converts it to use DataMessageValue, which represents the two
separately and also provides guidance for supplying translations of all
the error codes.

This also eliminates the "describeSettings()" method that was trying to
serve multiple use cases (in terms of the Action API, action=paraminfo
and action=help). It's replaced by two methods that each serve one of
the use cases. Also some of the functionality was moved out of the
TypeDef base class into ParamValidator, to better match where the
constants themselves live.

Also I wound up creating a NumericDef base class so FloatDef can share
the same range-checking logic that IntegerDef has. I probably should
have done that as a separate patch, but untangling it now would be too
much work.

Bug: T235801
Change-Id: Iea6d4a1d05bb4b92d60415b0f03ff9d3dc99a80b
2019-11-01 15:49:31 -04:00
Amir Aharoni
64e2d73f5c Split rest messages from the main en.json
Bug: T233192
Change-Id: I3990ae4e34a51e7648f74a05a4b7ac744fa9b9c4
2019-10-22 03:07:42 +00:00
jenkins-bot
52b44696ba Merge "Split some Language methods to LanguageNameUtils" 2019-10-08 21:10:07 +00:00
James D. Forrester
ebac0247cf Services: Convert LocalisationCache's static to a const now HHVM is gone
Change-Id: If5c015debed7efc034613b976bc5292ac30036d7
2019-10-08 11:25:30 -07:00
Aryeh Gregor
6d80b6c082 Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

This was previously committed as 2e52f48c2e and reverted because it
depended on e4468a1d6b, which had to be reverted for performance
issues. There should be no changes other than rebasing.

Bug: T201405
Change-Id: Ifa346c8a92bf1eb57dc5e79458b32b7b26f1ee8a
2019-10-07 15:20:52 -07:00
Aryeh Gregor
043d88f680 Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

An earlier version of this patch (e4468a1d6b) had to be reverted
because of a massive slowdown on test runs. Based on some local testing,
this should fix the problem. Running all tests in languages is slowed
down by only around 20% instead of a factor of five, and memory usage is
actually reduced greatly (~350 MB -> ~200 MB). The slowdown is still not
great, but I assume it's par for the course for converting things to
services and is acceptable. If not, I can try to optimize further.

Bug: T231220
Bug: T231198
Bug: T231200
Bug: T201405
Change-Id: Ieadbd820379a006d8ad2d2e4a1e96241e172ec5a
2019-10-07 13:18:47 -07:00
Timo Tijhof
7d82ce8bfd localisation: Remove PHP5-specific perf optimisation
The `apc.cache_by_default` setting is a PHP5-era setting relating
to the part of php5-apc now known as opcache (as opposed to the
part now known as apcu).

This setting doesn't exist in PHP 7, and trying to set it doesn't
do anything useful.

Bug: T206986
Change-Id: I46a91897b2b33b5ce6505beb74d404982cb0641c
2019-09-21 02:31:04 +01:00
Daimona Eaytoy
5eac6d131c Unsuppress more phan issues (part 3)
Bug: T231636
Depends-On: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
Change-Id: I58e67c2b38389df874438deada4239510d21654f
2019-08-31 16:38:55 +00:00
Amir Sarabadani
308e6427ae Revert "Make LocalisationCache a service"
This reverts commits:
 - 76a940350d
 - b78b8804d0
 - 2e52f48c2e
 - e4468a1d6b

Bug: T231200
Bug: T231198
Change-Id: I1a7e46a979ae5c9c8130dd3927f6663a216ba753
2019-08-26 18:28:26 +02:00
Aryeh Gregor
76a940350d Pass correct store to rebuildLocalisationCache.php
e4468a1d6b completely broke rebuildLocalisationCache.php by
unconditionally passing in LCStoreDB( [] ) instead of constructing the
correct object.

Bug: T231183
Change-Id: I0d52662e8745cf0e10091169b3b08eff48ef2b8f
2019-08-26 12:56:52 +03:00
Aryeh Gregor
2e52f48c2e Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

Change-Id: I245ae94bfc1f62b6af75ea57525139adf2539fe6
2019-08-23 12:52:35 +03:00
Aryeh Gregor
e4468a1d6b Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

Change-Id: Iaa86c48e7434f081a53f5bae8723c37c5a34f503
2019-08-22 14:25:18 +03:00
Antoine Musso
8a0878177d Drop newlines in LocalisationCache debug logs
316d205115 migrated LocalisationCache from wfDebugLog() to the Logger
interface which no more requires the messages to be terminated with a
new line.

Change-Id: Ibe2f750e7ab16cf91801988cb726adb67f7cd9d2
2019-07-24 12:14:33 +02:00
Roan Kattouw
cac26b713c Remove $purgeBlobs parameter from LocalisationCacheRecache hook
No longer allow hook functions to prevent message blobs from being
purged. Pass in an always-true variable for backwards compatibility,
which is then ignored.

Change-Id: I27ac9599711f2f0df2514a3934270af0ce03da7f
2019-07-15 15:32:03 -07:00
Amir Sarabadani
316d205115 Stop using wfDebugLog in LocalisationCache
Using logger interface, this would fix some unit tests, plus it
avoids using global functions and ease the way for proper dependency
injection

Change-Id: I9a545c70ace08e2fd0b832d75d6a2362a83af21e
2019-07-11 00:27:40 +02:00
Derick Alangi
166d09893b languages: Hard deprecate Language::getExtraUserToggles() method
This seems to be still used internally in core but in no extension. Also,
this function really doesn't do anything so hard deprecating in preparation
for removal.

Bug: T62260
Change-Id: I568789483084a97e5b3b462235f3d00c3cb87cf9
2019-05-24 10:59:38 -07:00
Timo Tijhof
7630e2bdb4 localisation: Inject 'directory' option to LCStore classes
Avoid globals for this, inject them from the factory function instead.

Bug: T218207
Change-Id: Ia961e8e08dcf1ca154d74ea6a3dadd2d59c1299c
2019-05-14 16:35:29 +00:00
Timo Tijhof
b96e187cbd localisation: Improve documentation around wgLocalisationCacheConf
Bug: T218207
Change-Id: I15a77d5df7b358b69cd9049036a69a28d31ebaae
2019-05-07 22:40:44 +00:00
Roan Kattouw
a6643499a4 Obtain MessageBlobStore instance in a consistent way
Use MediaWikiServices (not OutputPage) to obtain a ResourceLoader
instance, then call ->getMessageBlobStore() to obtain its
MessageBlobStore instance (don't construct a new one).

Change-Id: I6b8bacac9888b5807328eece01134a6c5747dc72
2019-05-07 01:09:45 +00:00
Kunal Mehta
e7186d68bd Upgrade to newer phan
MediaWiki core now runs phan 1.2.6, bringing in nearly 2+ years of upstream
fixes.

Configuration was moved from `tests/phan` to `.phan/`. The legacy bash wrapper
script is still kept in the repository in its own location for any extensions
that are still using it. It should be removed before 1.33 is released.

Since there's a lot of new issues being flagged, all currently failing issues
are suppressed, and will be fixed in follow-up patches.

We're dropping the jetbrains/phpstorm-stubs repository in favor of just
the minimal stubs we need. Stubs for PHP extensions are kept in
the new `.phan/internal_stubs` directory, since they're in a slightly
different format than normal stubs.

Normal stubs are kept in `.phan/stubs`. wikidiff2 and excimer are kept with
these since we're also the upstream for them.

Change-Id: I3fe437befa17f4fbaf97aa6271f659b56021f396
2019-03-23 18:06:35 -07:00
Timo Tijhof
3edaa0b37c resourceloader: Make $rl parameter mandatory for MessageBlobStore
Change-Id: I851b2417b7e495a1d0c7ee1aa8be2b2e970840bb
2019-02-19 17:16:57 +00:00
Kunal Mehta
cc5d9a92a2 build: Updating mediawiki/mediawiki-codesniffer to 24.0.0
Change-Id: I66b1775b7c1d36076d9ca78cbeb42787a743f2aa
2019-02-07 18:39:42 +00:00
Amir Aharoni
9dc4ff216b Move exif messages to a separate i18n file
Bug: T167762
Change-Id: I17900ff07cd9b15f00c7118b4206cf1cdc074469
2018-12-27 17:05:55 +02:00
Kunal Mehta
d0463178df LocalisationCache: Avoid use of compact()
In PHP 7.3, compact() now raises notices if the variable is undefined, which
is something that we expect. So we can check whether the key exists instead
of bothering with compat() and suppressing warnings.

Bug: T206979
Change-Id: I612049db4debd850a2e6d10bc631d31aa17be898
2018-10-15 13:35:30 -07:00
Ed Sanders
8477d4a6f5 Define which languages explicitly fallback to 'en'
In the message store, all messages fall through to English,
but only a few languages should actually explicitly fallback
to English (English variants and dialects).

These new explicit fallbacks are used by ResourceLoaderImageModule,
and this change doesn't affect the message fall through system.

Bug: T203350
Change-Id: I6b68a17f4d69341bccdae748727b5133a600d8bc
2018-09-19 15:55:38 -07:00
James D. Forrester
7cadf392f6 resources: Rename oojs-ui file paths to ooui per general branding
No change to the module names yet.

Change-Id: Ica33520b0128bd56dc06c8951bdc6932fce041fe
2018-09-10 14:35:45 -07:00
Aaron Schulz
1081356412 Move l10n_cache table to a separate DB for sqlite via the installer
This does not set 'db' as the cache type so that admins can still
easily set the cache directory to use the file-based cdb system.
If they do not, then at least the second DB file will be used to
avoid heavy contention.

Bug: T93097
Change-Id: Ib3912f00cf12de99801ebda4f06135b2987ce71a
2018-08-14 17:29:01 +00:00
Max Semenik
ae314346d5 Enclose compact() call in error suppression
In PHP 7.3, compact() now emits warnings when a variable doesn't exist.
Because our language files aren't required to contain all the possible
variables, this results in massive spam trying to run tests.

Change-Id: Idab0340ec1cdebfca67cb448e350a408438bcbbc
2018-07-28 08:09:19 -07:00
Fomafix
0f1858321c Use PHP 7 '??' operator instead of if-then-else
Change-Id: I790b86e2e9e3e41386144637659516a4bfca1cfe
2018-06-12 23:14:18 +02:00
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00:00
Umherirrender
3124a990a2 Use ::class to resolve class names in includes files
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I07a925c2a9404b0865e8a8703864ded9d14aa769
2018-01-27 20:34:29 +01:00
Bartosz Dziewoński
eb6bb6b7b9 Generalize non-digit-grouping of four-digit numbers
In some languages it's conventional not to insert a thousands
separator in numbers that are four digits long (1000-9999).
Rather than copy-paste the custom code to do this between 13 files,
introduce another option and have the base Language class handle it.

This also fixes an issue in several languages where this logic
previously would not work for negative or fractional numbers.

To implement this, a new option is added to MessagesXx.php files,
`$minimumGroupingDigits = 2;`, with the meaning as defined in
<http://unicode.org/reports/tr35/tr35-numbers.html>. It is a little
roundabout, but it could allow us to migrate the number formatting
(currently all custom code) to some generic library easily.

Bug: T177846
Change-Id: Iedd8de5648cf2de1c94044918626de2f96365d48
2018-01-02 11:17:25 +01:00
Kunal Mehta
d452a4fb5b LocalisationCache: Remove unused "use" statements
Change-Id: Ie1cdd52d87deffa251b7af0554370ba9a4edce73
2017-08-21 20:40:52 -07:00