Commit graph

57 commits

Author SHA1 Message Date
Umherirrender
1b29f07440 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I73fb416573f5af600e529d224b5beb5d2e3d27d3
2024-10-21 20:41:20 +02:00
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
thiemowmde
b1c9ec74fa Remove meaningless @var documentation from constants
A constant is not a variable. The type is hard-coded via the value
and can never change. While the extra @var probably doesn't hurt much,
it's redundant and error-prone and can't provide any additional
information.

Change-Id: Iee1f36a1905d9b9c6b26d0684b7848571f0c1733
2024-10-09 09:33:12 +02:00
jenkins-bot
c09ac42243 Merge "build: Use inline ignore for MediaWiki.Usage.DeprecatedGlobalVariables" 2024-10-05 15:59:19 +00:00
Bartosz Dziewoński
ff6b625f88 MessageCache: More consistently treat redirects as not existing
MessageCache::loadFromDB() already did that, but other code paths like
updateMessageOverride() didn't. To ensure every code path behaves the
same, add a check for redirects in getMessageTextFromContent().

Bug: T376398
Change-Id: I113e65f016401563009d1ccd60b4d1555ed0d283
2024-10-03 18:06:36 +00:00
James D. Forrester
53b67ae0a6 Add namespace to remaining parts of Wikimedia\ObjectCache
Bug: T353458
Change-Id: I3b736346550953e3b2977c14dc3eb10edc07cf97
2024-09-27 16:19:10 -04:00
James D. Forrester
9e5c1e8ac7 Add namespace to IDBAccessObject and DBAccessObjectUtils
Bug: T353458
Change-Id: I23cf7991f8792d4d000d1780463d8ce76dc0aee0
2024-09-27 16:19:10 -04:00
Umherirrender
c7cd5399e7 build: Use inline ignore for MediaWiki.Usage.DeprecatedGlobalVariables
This avoids addition of new code with the deprecated global,
or at least it gives extra attention on review when new code also uses
the inline ignore

Change-Id: I5c1bc5a1685c28f153d4fbe3525959930f54b557
2024-09-26 18:15:32 +00:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
James D. Forrester
6df7a51484 Drop MessageContent, deprecated since 1.38
Change-Id: Ib53d4a04e6faa82b0ea553221e6c0c827f36017a
2024-08-10 09:28:37 +02:00
Umherirrender
9a107e6b03 Use expression builder instead of raw sql
Bug: T361023
Change-Id: Ibf1c93ddbf8f680e8fb9442816f6fed94a069c0a
2024-07-23 23:30:45 +02:00
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
Fomafix
b0b0066682 language: Deprecate MessageCache::get without Language object
Trigger a deprecation warning if MessageCache::get gets called without
a Language object. On omitted parameter still the content language is
used.

Also change from $langcode = true to $language = null. This allows to
introduce a PHP type check in I8d0de2c7c2e6d087228844874d8251933b4acea4.

Change-Id: Ib27cfc0af090790daca3995fb1c3d78712d53ae6
2024-05-19 14:55:47 +00:00
Umherirrender
33dd935478 Migrate to IReadableDatabase::newSelectQueryBuilder
This cases cannot benefit from the SelectQueryBuilder as each argument
get processed by hooks with fix signature or coming from abstract
functions providing the arguments separate.

Bug: T344971
Change-Id: I6490caae3984efaae81bd2583220a7dd1c3b371d
2024-05-05 17:29:51 +02:00
Bartosz Dziewoński
f93a690d5b Show overridden message keys when using &uselang=qqx
When displaying messages, the requested message key can be overridden
by hooks such as 'MessageCacheFetchOverrides'. If this happened,
display the overridden key when using &uselang=qqx, to help users and
developers track down where a message is coming from.

Bug: T363729
Change-Id: I81d814278ca810035066ce4632f617f30536f1ab
2024-04-30 18:38:34 +00:00
Subramanya Sastry
e55cc517da Move Parser to Mediawiki\Parser namespace
Bug: T166010
Co-Authored-By: Daimona Eaytoy <daimona.wiki@gmail.com>
Co-Authored-By: James Forrester <jforrester@wikimedia.org>
Co-Authored-By: Subramanya Sastry <ssastry@wikimedia.org>
Change-Id: I79b4e732c45095eedbaa80afa5eb7479b387ed8a
2024-02-16 09:18:38 -05:00
James D. Forrester
060a1b1668 Replace last remaining wfGetDB() calls in core, except ResourceLoader
Bug: T330641
Change-Id: I6d30af6ff9f667e367d39befb80c2bb0bf5fb29e
2024-02-14 11:02:01 -05:00
Amir Sarabadani
ea268ddcfd Move away from wfGetDB() calls
If we are serious about getting rid of wfGetDB(), we should start
replcing callers with proper replacement.

These classes don't have any injection so it doesn't make sense to
introduce it for this specific usecase.

Bug: T330641
Change-Id: I645f67324d441288c63787c7e42390b59106c585
2024-02-12 21:23:38 +01:00
James D. Forrester
102a4f8a35 build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manually
* Switch out raw Exceptions, mostly for InvalidArgumentExceptions.
  * Fake exceptions triggered to give Monolog a backtrace are for
    some reason "traditionally" RuntimeExceptions, instead, so we
    continue to use that pattern in remaining locations.
* Just entirely give up on PostgresResultWrapper's resource vs. object mess.
* Drop now-unneeded false positive hits.

Change-Id: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
2024-02-10 02:22:41 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Amir Sarabadani
014bc61006 Remove more indirect calls to IDBAccessObject::READ_* constants
Found via (?<!IDBAccessObject)::READ_

We are planning to deprecate and remove implementing IDBAccessObject
interface just to use the constants.

Bug: T354194
Change-Id: I89d442fa493b8e5332ce118e5bf13f13b8dd3477
2024-01-23 15:42:38 +01:00
James D. Forrester
9bfb75ff90 Namespace ParserOutput
Most used non-namespaced class!

Bug: T353458
Change-Id: I4c2cbb0a808b3881a4d6ca489eee5d8c8ebf26cf
2023-12-14 14:57:34 -05:00
Amir Sarabadani
5270dad2ad Migrate two easy cases to expression builder
Now that we have builder for NOT_LIKE

Change-Id: Ic81556b94e74372cdeeefffb26ed151e8aba2e41
2023-12-06 20:10:40 +01:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
Amir Sarabadani
8fcd7726e9 Migrate all non-API code to use expression builder instead of buildLike
Bug: T210206
Change-Id: Icf3a2c5e5fb40ff31c65ba182937510d44186e46
2023-11-07 18:53:18 +01:00
Reedy
40f7d7632a Language: minor cleanup
* Remove unnecessary duplicate documentation
* Code tweaks

Change-Id: I9c8c190bee58195eace08cba18a51e4572896ef7
2023-10-02 13:34:11 +00:00
Fomafix
6d61b366a2 Support message parameters on the uselang=x-xss feature
This allows to check also message parameters for possible JavaScript
injections.

Bug: T340201
Change-Id: I6bef28cd9c6b91713b66b40cba46e9b2dc2a1f05
2023-09-28 15:33:00 +00:00
Lucas Werkmeister
e9991ffb68 Create 'x-xss' language code feature
This creates a new language code, 'x-xss', which is enabled using the
setting $wgUseXssLanguage (similar to how $wgUsePigLatinVariant enables
the 'en-x-piglatin' language code, and likewise defaults to false; will
be enabled in development settings soon).

In this language code, all messages become “malicious”, trying to run
some alert() JavaScript; if any alert() actually fires in the browser,
the message was not escaped properly. ($wgRawHtmlMessages are exempt,
since they’re already known to be “unsafe” and require more rights to
edit on-wiki.) Messages that are not escaped properly are generally a
minor security issue; they effectively let a user with 'editinterface'
right (such as a sysop, on many wikis) run arbitrary JS, without needing
the 'editsitejs' right (normally restricted to interface admins).

Developers can use this language code to more easily check their code
for escaping issues / cross-site scripting vulnerabilities.

Bug: T340201
Change-Id: Ia9a1cf712b139fea5da72046e37035e6de39d8d5
2023-09-28 15:50:11 +02:00
Amir Sarabadani
44a6dd21b3 Migrate another major batch to SelectQueryBuilder
I fixed some edge cases in the script that migrates to SQB and it
managed to fix these now.

Bug: T344971
Change-Id: I00cc9a6660d9bd4c64c976121b2121ccd7aae1f0
2023-09-20 13:32:09 +02:00
jenkins-bot
43607fd156 Merge "language: Inject ParserFactory into MessageCache" 2023-08-16 15:59:05 +00:00
Derick Alangi
2abbb1a774 objectcache: Remove IExpiringStore interface
Interface was deprecated since 1.35 in favor of ExpirationAwareness
or StorageAwareness interfaces. No longer used anywhere, see dependent
patches.

Depends-On: Ida557b3180eb5e7ebae46968142b4f154f26ffbc
Depends-On: I3d6fbf535560655472ade27c37b0e42b3e11a535
Depends-On: I2b0a669d41d9e6a8a859cba314c0e9e4c0ef40d7
Depends-On: I776040c2c8f61e25ae986e93bb1975fdd8bf9dd5
Change-Id: I9c5ffa9f51aec6356e3e27458fd098a37cd754ad
2023-08-08 20:15:03 +00:00
Umherirrender
937ebeb585 language: Inject ParserFactory into MessageCache
Avoid clone of Parser object, create a new one

Reset the UrlUtils services after changing the server setting,
it is a dependency of the ParserFactory and gets initalizied earlier now

Bug: T250448
Change-Id: Ie62250242965d3d90873909795ced2cbda506ddb
2023-07-30 22:08:46 +02:00
Umherirrender
1086958611 Replace array_keys in foreach to use $_ as value instead
When the value of the associated array is not used, there is no need to
use array_keys and create internal a copy of the array, just omit the
value with $_ to tell static analyzer that the var is unused.

Change-Id: I5c6d667e98c0167c0573c683f0d617bc1d4ca619
2023-07-10 02:53:52 +00:00
jenkins-bot
158adf4dde Merge "Collapse sequences of if into short return if possible" 2023-06-20 11:48:55 +00:00
jenkins-bot
dbf8f8d12c Merge "Merge sequences of if that end doing the same thing anyway" 2023-06-17 23:34:51 +00:00
thiemowmde
9b03cde58e Merge sequences of if that end doing the same thing anyway
Motivation:
* Avoid code duplication.
* Hopefully make it easier to read.
* Also order stuff from cheap to expensive, if possible.

Change-Id: I575e3f2027ce60a0d0885be5b9bd3e07bc035eee
2023-06-16 16:09:42 +02:00
thiemowmde
990ef704ce Collapse sequences of if into short return if possible
The main goal is to make this code faster and easier to read, and to
avoid duplication.

Change-Id: I925d742d560e9d90e3ecc9ff19fe7e87b60bf9a4
2023-06-15 15:14:40 +02:00
Func
bfd4001c6c LocalisationCache: Preserve fallback source language info
Prefix messages with their source language code when saving to the cache.

Bug: T229992
Change-Id: I06ae6432c80ffeb924b2a3ac29ad2e876b715b33
2023-06-14 22:06:36 +08:00
Fomafix
a5d6f8539a Hard deprecate global function wfGetLangObj
Duplicate the code of wfGetLangObj as private non-static function
MessageCache::getLanguageObject.

Bug: T332722
Change-Id: I9d422db270a401d6066e9869e1fa7a189959c374
2023-04-07 10:11:56 +00:00
mainframe98
115903a25e MessageCache: Don't initialize messageKeyOverrides in the constructor
Follow-up to I89e1a9b901aff6ff1bde729df8958ba42a45f3d5 where I forgot
to remove this line after initialization was moved to MessageCache::get.

Change-Id: Iae441ccedba08eb12685d81381259aad49b7b42f
2023-03-19 14:51:24 +01:00
mainframe98
ded922c21d MessageCache: Add a new hook for more performant override fetching
This new hook is called only once, for all overrides, instead of
every time a message is fetched.
Overrides can be specified as string or a callable, to allow for
dynamically computing the override on-demand. These callables are
passed the message key, MessageCache instance, the language and a
boolean indicating if the message should be fetched from the
database.

The parameter choices are based upon current usages of the
MessageCache::get hook.

Bug: T328183
Change-Id: I89e1a9b901aff6ff1bde729df8958ba42a45f3d5
2023-03-14 21:11:35 +01:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Aaron Schulz
228141c263 MessageCache: immediately update the local cache upon hash mismatch
The $hashVolatile exception should only apply if the only reason
the local cache is considered stale is due to hash key volatility.

Bug: T258860
Change-Id: I03f595e000cec5a6f14c26c8096456ad3bb153aa
2023-02-22 00:19:36 +00:00
Aaron Schulz
cd7b9a3697 MessageCache: improve handling of I/O errors from cache lock keys
If the cluster cache lock fails due to an I/O error, we should fallback
to loading from the DB using a local server lock and only update
the local server cache.

Fix some code comments and documentation.

Bug: T258860
Change-Id: I672908a0f042f52dc0847a1f8e73723d35cdbc88
2023-02-08 21:05:57 +00:00
Umherirrender
1af3e211eb docs: Add missing StubUserLang type to some @param/@return
Change-Id: Ic1f192c7a21e529113fd7d537a79b2e4f8983b9c
2023-01-12 19:04:20 +01:00
thiemowmde
8b49357b25 Replace some tivial ??= with even more trivial ??
Patch Ifa7a9bc replaced some longer `=== null` constructs with the
new ??= operator we have since PHP 7.4. However, some of these can be
simplified even more with the ?? operator we have since PHP 7.0.

Follow-Up: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
Change-Id: I7b05e723810558bb5437adc97eab54ca04d38c06
2022-12-23 08:35:44 +01:00
DannyS712
c1db64b808 Make use of ??= in more places
New feature from PHP 7.4

Change-Id: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
2022-12-17 01:10:13 +00:00
thiemowmde
70aa9c8e35 Make use of ?:, ?? and ??= operators in mostly trivial cases
The motivation is to make the code less confusing. I hope this is the
case.

?? is an older PHP 7.0 feature.
??= was added in PHP 7.4, which we can finally use.

Change-Id: Id807affa52bd1151a74c064623b41d950a389560
2022-12-05 21:37:13 +01:00
Amir Sarabadani
0fff5089ba Reorg: Move StubObject classes in includes to its own directory
Bug: T166010
Change-Id: Idcf0e9dc6e0841e4f132207bce0f96774dad898c
2022-10-25 16:04:48 -04:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00