Commit graph

149 commits

Author SHA1 Message Date
DannyS712
845094fe3d Language: retrieve MainConfig instead of using a bunch of globals
Change-Id: I791af9197a4a53723adf2869d7b3b9f41fe9c059
2022-03-15 02:58:42 +00:00
jenkins-bot
df8ae68fd9 Merge "language: Fix order of arguments in truncateHtml()" 2022-03-13 21:59:20 +00:00
Alexander Vorwerk
9b09bf3112 Use updated ObjectFactory namespace
Depends-On: I99c5e5664d2401c36a9890f148eba7c25e6e8324
Depends-On: I48ab818b2965da14af15ef370aa83ad9455badd9
Depends-On: I018371e4b77911e56152ca7b2df734afc73f58a5
Change-Id: I04ebdb52102f6191d49a9cc70b1f98308299e72f
2022-03-09 23:04:51 +00:00
Umherirrender
b8bb463dba language: Fix order of arguments in truncateHtml()
The arg order of truncate_endBracket is tag, type, lastCh, tags, but the
type and lastCh are in wrong order. This is only relevant when $tag is
still non-empty after the loop, which is only happen for unclosed html
tags.

Found by phan strict checks

Change-Id: I08d6926dd4aac8ccc86c776f57a26437013ecb1d
2022-03-08 22:34:33 +00:00
jenkins-bot
c268687d46 Merge "Hard deprecate Sanitizer::removeHTMLtags()" 2022-03-08 19:29:55 +00:00
jenkins-bot
d1cfc0317d Merge "Add explicit casts between scalar types" 2022-03-08 17:32:26 +00:00
Umherirrender
6ea3d6ac2c Add explicit casts between scalar types
php internal functions like floor/round/ceil documented to return
float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: I92daeb0f7be8a0566fd9258f66ed3aced9a7b792
2022-03-08 16:59:01 +00:00
C. Scott Ananian
d6576e5dc6 Hard deprecate Sanitizer::removeHTMLtags()
Rename Sanitizer::removeHTMLtags() into an @internal method named
::internalRemoveHtmlTags() so that we can deprecate external use.

Code search:
https://codesearch.wmcloud.org/deployed/?q=removeHTMLtags&i=nope&files=&excludeFiles=&repos=

Followup-To: Ic864c01471c292f11799c4fbdac4d7d30b8bc50f
Depends-On: Iaca83ed06e9c61d8366579cd2283cba653c82319
Depends-On: I1963bfe9a99198ea02ca482a5769467ce806cd58
Depends-On: I83923d8b38d33f3638cd53958dd10f257ec21f7c
Depends-On: I018b34bb5f6e113056da9b04cc72d4318422adce
Change-Id: I202826f8b27519f7be89643e24eda47a6e3fc9f6
2022-03-07 22:04:56 -05:00
Bartosz Dziewoński
ba96351f46 Only apply transformations for &uselang=qqx when actually using it
Depends-On: I4f3b01eccf571475f1248db838a8aa6cba18b93e
Depends-On: I0a0681b332abb623fc6871ab78da9e64a79fad84
Bug: T300069
Bug: T302469
Change-Id: I45f58034117e9041fe5403dbfcf83ba25f20518d
2022-03-08 01:50:44 +00:00
Bartosz Dziewoński
0954804d0a Use Message::newFromSpecifier() in wfMessage()
As a result, when an existing Message object is passed in the $key
parameter, the function will return a clone of that object, rather
than a new Message constructed based on the key extracted from the
old message.

This is mostly relevant when the passed object is an instance of
a subclass like RawMessage or ApiMessage, but it could have other
unpredictable consequences. No test failures, though!

Change-Id: I4815e92dfaf5fbcc8c9356106738716c6b9ae0da
2022-03-08 02:49:51 +01:00
Bartosz Dziewoński
04b9dd6b2f Re-apply "Show message fallback keys when using &uselang=qqx"
This affects messages created using wfMessageFallback() and related
functions, in particular many messages used for navigation tabs in
skins.

Previous attempt in 11d7d97768,
reverted in c83b530f95 due to T302469.

This attempt doesn't introduce any new placeholders to avoid that
issue.

Bug: T300069
Change-Id: Ib0e282b3864caf345e42dd7af4a529f43ae7ba67
2022-03-08 00:56:12 +00:00
Umherirrender
a9aa1e7346 Fix type of value directly passed to php internal functions
Found by phan strict checks

Change-Id: Icc44cd143f2e98fa3ca188e625a3289441de0f73
2022-03-07 20:41:55 +01:00
Reedy
11cc2d6993 Consistently use @deprecated since rather @deprecated
Change-Id: I301786f35cd6eb9c63fb72e0b64cffa9efd7b86b
2022-03-06 02:55:54 +00:00
Func
b339659df9 LanguageConverter: Fix a deprecation and avoid some use of phan suppression
Change-Id: I89299407bda692948e84bd27e343eb465499484d
2022-02-26 03:00:52 +00:00
Ammarpad
8c559f717e Language: Document StubUserlang in methods that accept it
Many Language methods can't be typehinted with Language as long as
$wgLang/StubUserLang are not completely removed (T160814)

Lack of explicit StubUserlang in the param type often make it
possible for the typehint to be reintroduced after it was removed,
as it happened in Iec1b562 and If72d054

Change-Id: I9b3e87baf38091e2de428de0c92c5a8a6fea32ea
2022-02-25 16:55:50 +01:00
Gergő Tisza
69906cb6fd
Remove TrivialLanguageConverter::__construct() type hint
Follows up I29574c20d2963de826108e5ad9e7e22ec6571ebe.

Bug: T302554
Change-Id: I092a71eb7de56f5e9e8879738ee59a477cf851f7
2022-02-24 22:49:00 -08:00
Gergő Tisza
c1d7cbb996
Remove LanguageConverterFactory::instantiateConverter() type hint
Sometimes the method is called with a stub language object.
There are probably better ways to avoid that in the long-term
but for now this is a risk-free fix.

Change-Id: I29574c20d2963de826108e5ad9e7e22ec6571ebe
2022-02-24 21:53:44 -08:00
Reedy
86934b2fa8 Replace some more usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I2eb133a9e32116cd155f59086245bc4d15ecbfcc
2022-02-24 20:27:46 +00:00
jenkins-bot
dcf44db379 Merge "Use ObjectFactory in LanguageConverterFactory" 2022-02-24 18:11:54 +00:00
Umherirrender
a9bc9f8a04 Use ObjectFactory in LanguageConverterFactory
Use the object factory to inject service into TrivialLanguageConverter
class.
The other language converter classes does not use service directly.
The classes are using indirectly services in some function of
the parent class, which needs injection as well (tracked with T294185).

Needs fallback to global state in TrivialLanguageConverter, because the
class is used in extensions integration tests

Change-Id: If72d054d062a4f357e12c5b168e118bfafffd626
2022-02-24 17:47:09 +01:00
Elliott Eggleston
c83b530f95 Revert "Show message fallback keys when using &uselang=qqx"
This reverts commit 11d7d97768.

Breaking fundraising banners with regexes in them.

Bug: T302469
Change-Id: I0146a6a2907ca72792375e97a5b5392c6465614f
2022-02-23 21:21:45 -05:00
jenkins-bot
f01fa66527 Merge "Show message fallback keys when using &uselang=qqx" 2022-02-18 20:58:31 +00:00
jenkins-bot
b71e80afcb Merge "Fix documentation of wfMessageFallback/Message::newFallbackSequence" 2022-02-18 19:26:30 +00:00
Ammarpad
87b8d3c2ff Message: Fix return type/property doc
Change-Id: I1bd93f7fc1192c5291849f3a2e4c608588f316d1
2022-02-18 19:40:20 +01:00
Ammarpad
4ecf3451e0 Fix documentation of wfMessageFallback/Message::newFallbackSequence
If all keys failed, instance of the last message key is returned, not first

Test: wfMessageFallback( 'x', 'y', 'z' )->text()

Change-Id: I115a626d5838240665d1f5044dbee1bac1dd5a37
2022-02-18 19:16:55 +01:00
Bartosz Dziewoński
11d7d97768 Show message fallback keys when using &uselang=qqx
This affects messages created using wfMessageFallback() and related
functions, in particular many messages used for navigation tabs in
skins.

Bug: T300069
Change-Id: Ia8ba35419285cfa77197810ae9df99e522a0f4ba
2022-02-17 19:59:40 +01:00
jenkins-bot
0607fc561a Merge "Don't double-escape the ellipses in Language::truncateForVisual()" 2022-02-10 22:47:33 +00:00
C. Scott Ananian
9e033de4f2 Don't double-escape the ellipses in Language::truncateForVisual()
It turns out this gets rid of a bunch of suppressed
"SecurityCheck-DoubleEscaped" that appear to have been accurate
warnings.

There seems to have been some confusion about how ::truncateForVisual()
is supposed to be used; in particular it is to be passed *unescaped*
output, because it is not (generally speaking) safe to truncate
HTML-escaped strings.  The goal of ::truncateForVisual() is to have
a specific number of codepoints in the output for display purposes,
the encoding of those codepoints is not an issue (htmlspecialchars
can be applied to the *return value*.)  If you need a specific number
of *bytes* you should be using ::truncateForDatabase().  If you want
a certain number of *HTML bytes* then the ::truncateHtml() method
is probably what you want.

Slightly refactor some code in RevDelLogItem to avoid a false positive.

Bug: T301205
Bug: T290624
Change-Id: I893362e049aedfa699043fcf27caf4815196f748
2022-02-10 17:09:18 -05:00
Tim Starling
b90d2dd5c2 Optimise Skin::getLanguages()
Skin::getLanguages() was consuming 4% of index.php CPU time. In local
testing, it was called three times per page view. So:

* Memoize it, analogous to the nonfunctional code in SkinVector.
* Simplify ClassicInterwikiLookup by removing the option to pass a CDB
  file path. This was only ever supported by a WikimediaMaintenance
  script. In the unlikely event that someone is using this feature, they
  have the same motivation to switch to PHP as we did in T122362.
* Increase the size of ClassicInterwikiLookup's MapCacheLRU from 100 to
  1000. This helps greatly in the case when $wgInterwikiCache is false
  and more than 100 interwikis are requested and seems harmless
  otherwise.
* Optimise Title::getNsText() by assuming that the canonical name of
  NS_MAIN is the empty string.
* Rearrange Message::__construct() to avoid duplicate type checks.

Change-Id: I736cb74efc267fd2473a3267471735238217251c
2022-02-08 22:34:15 +00:00
jenkins-bot
2becc606d3 Merge "Try not to discard Excimer timeout exceptions" 2022-02-03 00:28:16 +00:00
Tim Starling
ca71e69fc6 Try not to discard Excimer timeout exceptions
Don't catch and discard exceptions from the RequestTimeout library,
except when the exception is properly handled and the code seems to be
trying to wrap things up.

In most cases the exception is rethrown. Ideally it should instead be
done by narrowing the catch, and this was feasible in a few cases. But
sometimes the exception being caught is an instance of the base class
(notably DateTime::__construct()). Often Exception is the root of the
hierarchy of exceptions being thrown and so is the obvious catch-all.

Notes on specific callers:

* In the case of ResourceLoader::respond(), exceptions were caught for API
  correctness, but processing continued. I added an outer try block for
  timeout handling so that termination would be more prompt.
* In LCStoreCDB the Exception being caught was Cdb\Exception not
  \Exception. I added an alias to avoid confusion.
* In ImageGallery I added a special exception class.
* In Message::__toString() the rationale for catching disappears
  in PHP 7.4.0+, so I added a PHP version check.
* In PoolCounterRedis, let the shutdown function do its thing, but
  rethrow the exception for logging.

Change-Id: I4c3770b9efc76a1ce42ed9f59329c36de04d657c
2022-02-02 16:27:44 +11:00
Reedy
e7bcea5548 Implement __serialize/__unserialize for PHP 8.1 support
ApiMessageTrait/Message/MapCacheLRU migrated so far

Bug: T299312
Change-Id: Ie126fb8808c5e6611e66fd63972682198cca0e0d
2022-01-31 19:43:39 +00:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Siddharth VP
b77dd0640c Fix typos in comments (M)
Change-Id: I5ab88a01ba3e5ea2aae853bb6f06492fbc84ceb5
2022-01-09 23:00:20 +05:30
Siddharth VP
b4b2a62040 Fix typos in comments (L)
Change-Id: I3deb34aec51504e09b20a367a93ebe863335be26
2022-01-09 22:54:04 +05:30
Umherirrender
44956083db LanguageConverter: Remove duplicate deprecation hint
There is no need for deprecatePublicProperty, when later
deprecatePublicPropertyFallback gets called.

Change-Id: Ib24d1e1bdc729bef132d55234a2062892dd3cf59
2022-01-02 21:30:16 +00:00
Derick Alangi
3a2d2cddc2 Language: Remove unused, deprecated class members & constants
Change-Id: I57c2cacd0211cf0548e45d8a0c43dd7d47a7b2d4
2021-12-21 10:38:00 +00:00
jenkins-bot
d0507a2740 Merge "Use hasVariant in loop to determine parent language in LanguageFactory" 2021-12-07 00:03:05 +00:00
Func
cdd5b4db86 Use hasVariant in loop to determine parent language in LanguageFactory
Code of some language's parent language can't simply strip out the subcode.
e.g. ike-cans should get iu.

Change-Id: I4cf5bb1ddc463a8d98064451dd8e4dbebeca96e9
2021-12-06 13:52:46 +00:00
Alexander Vorwerk
3aa5b6643b Use LanguageNameUtils constants instead of strings
Change-Id: I8521d00675008da0d7c8c768ab75352212653c66
2021-12-05 22:13:34 +01:00
Umherirrender
3f08cd753a Replace deprecated Language::fetchLanguageNames
Change-Id: Iecd5481edb4dae6c7911157e24c32a51f4438ab2
2021-12-05 21:11:49 +01:00
Reedy
c054b10423 Remove or replace usages of "sane"
Bug: T254646
Change-Id: Ia660ab95353cd8f05c50e60f30d29fd22b018a43
2021-11-22 15:48:03 +00:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Daimona Eaytoy
e0d3b3e8fc Use getWithSetCallback() instead of get() + set()
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
2021-11-18 18:58:13 +00:00
jenkins-bot
990ec777dc Merge "Add Message/MessageValue user group member parameter type" 2021-11-16 19:08:33 +00:00
TChin
349819dc5a Add Message/MessageValue user group member parameter type
* Added ParamType::OBJECT, which allows Stringable objects to be passed into MessageValue

Bug: T278482
Change-Id: Ib4990f87d4ad70b7525d7aa05c8b97e90c121674
2021-11-16 11:24:35 -05:00
jenkins-bot
ef59b75ba1 Merge "language: Use property LanguageConverter::mUserVariant for optimisation" 2021-11-09 22:40:35 +00:00
Umherirrender
e535eb1e6e language: Use property LanguageConverter::mUserVariant for optimisation
The property was set, but never read. Use it similar to
mHeaderVariant/mURLVariant and return the value when set.

Originally introduced without caching (r60961, 81f62b6f61) but had no
clear explanation. The unclear comment was removed in I62bd09d7d0.

Change-Id: I863d77618c7f26686ae4de76024878655f516e04
2021-11-09 20:52:00 +00:00
Umherirrender
171775e07b doc: Cleanup @param documentation
No extra sign needed between variable and description

Change-Id: Iaaaf62a3ffba7967aef8c31b121121b2830b74c4
2021-11-04 22:32:39 +01:00
jenkins-bot
7c0ffb3b24 Merge "language: Fix nullable documentation for property, args and return types" 2021-11-02 10:21:05 +00:00