Commit graph

378 commits

Author SHA1 Message Date
Kevin Israel
7d250d2109 Remove CryptHKDF and MWCryptHKDF
MWCryptHKDF was added ten years ago (in af66c04d39), and as far as
I can tell, it was never used anywhere. It seems unlikely that CryptHKDF
will be used in the future, at least in its current form, for several
reasons:

* PHP 7.1.2+ has hash_hkdf(), so HKDF() would not be needed.

* At the time MWCryptHKDF was created, access to a CSPRNG was dependent
  on server configuration: operating system, enabled PHP extensions,
  open_basedir, etc. The "clock drift" RNG used as a last resort was not
  considered to be secure or fast enough for generating large amounts of
  output.[1] random_bytes(), added in PHP 7, changed the situation.

* Depleting the input pool of Linux's RNG is no longer a concern; there
  is no more blocking output pool for /dev/random.[2][3] In 2022, this
  change and others, including some that improved performance,[4] were
  backported to stable kernels as old as 4.9.[5]

* $wgAuthenticationTokenVersion obviated the primary use case of
  quickly resetting the user_token field for all users, assuming all
  the existing tokens are unique.

* CryptHKDF seems to perform much slower than random_bytes(), at least
  on Linux, making it pointless to use given that the other reasons for
  its existence no longer apply.

[1]: https://bots.wmflabs.org/logs/%23mediawiki-core/20161004.txt
[2]: https://lwn.net/Articles/808575/
[3]: https://lore.kernel.org/all/cover.1577088521.git.luto@kernel.org/
[4]: https://www.zx2c4.com/projects/linux-rng-5.17-5.18/
[5]: https://lore.kernel.org/all/Yo3pmh9hiUFtQz77@zx2c4.com/T/

Change-Id: I29136fad826341d21728671aa30285d5551f1162
2024-11-10 22:49:37 -05: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
James D. Forrester
9203493606 Add namespace to remaining parts of Wikimedia\FileBackend
Bug: T353458
Change-Id: I49c843c9d8f6459c0fbf774afeea7a82fa564b59
2024-10-03 16:21:22 +00:00
James D. Forrester
cc28acc455 Add namespace to remaining parts of Wikimedia\Mime and Wikimedia\Stats
Bug: T353458
Change-Id: If0137003ab625017d322d57870448a02569668c3
2024-09-27 16:19:10 -04:00
Adam Wight
188d2cbbb0 Remove unchecked exception annotations
Callers should not catch an unchecked exception, so it doesn't belong
in a function signature.  Unchecked exceptions indicate a coding error,
which by definition the code will not be able to handle correctly.

If any of these exceptions were supposed to be in response to an edge
case, user input, or initial conditions, then they should be changed
to a runtime error.  If the exception class cannot be changed, then
the annotation should include a comment explaining its purpose and
prognosis.

Bug: T240672
Change-Id: I2e640b9737cb68090a8e1cb70067d1b74037d647
2024-09-17 22:20:58 +02:00
Ebrahim Byagowi
f903bae012 Remove UIDGenerator, deprecated since 1.35
Change-Id: I5e47ecd560218df7e48af68e6aee351bc2a57823
2024-09-04 14:38:30 +03:30
jenkins-bot
53936dc79c Merge "utils: Add missing documentation to class properties" 2024-09-01 15:19:10 +00:00
Umherirrender
574e8b702c utils: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Improve a mixed type to string

Change-Id: Id994553eaeac181775ac782423ff53928ad45466
2024-09-01 14:40:01 +00:00
Umherirrender
3a09698763 utils: Remove unused ZipDirectoryReader::$data class property
Unused since addition of class property in 6906724935 (r100779)
Unused since dynamic creation in 0a21e2de12 (r82783)

Change-Id: I72c7dab67ef12d229fb232311e404467260d742d
2024-09-01 12:07:08 +00:00
thiemowmde
dca4931b42 Make use of the ??= and ?? operators where it makes sense
This touches various production classes and maintenance scripts.
The code should do the exact same as before. The main benefit is that
the syntax avoids any repetition.

Change-Id: I5c552125469f4d7fb5b0fe494d198951b05eb35f
2024-08-26 09:26:36 +02: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
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
Umherirrender
9879723ef3 Use namespaced classes (1)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Ic4d4dd61de5ab896fb6173eb579c81f164a1e4a3
2024-06-16 20:18:23 +02:00
Bartosz Dziewoński
ccd423225f Add "implements Stringable" to every class with "function __toString()"
In PHP 8, but not in PHP 7.4, every class with a __toString() function
implicitly implements the Stringable interface. Therefore, the
behavior of checks like "instanceof Stringable" differs between these
PHP versions when such classes are involved. Make every such class
implement the interface so that the behavior will be consistent.

The PHP 7.4 fallback for the Stringable interface is provided by
symfony/polyfill-php80.

Change-Id: I3f0330c2555c7d3bf99b654ed3c0b0303e257ea1
2024-06-13 00:23:39 +00:00
Ebrahim Byagowi
d21cc67450 Add namespace and deprecation alias to FileBackend
This patch introduces a namespace declaration for the
Wikimedia\FileBackend to FileBackend and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Id897687b1d679fd7d179e3a32e617aae10ebff33
2024-05-19 22:35:58 +03:30
Ebrahim Byagowi
a717db8e60 Add namespace and deprecation alias to FormatJson
This patch introduces a namespace declaration for the
MediaWiki\Json to FormatJson and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
2024-05-16 16:28:01 +03:30
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
Amir Sarabadani
214674d6b1 namespace MWDebug
Bug: T353458
Change-Id: I99d728bd111ff882220cd175ff09d4da20b81eae
2024-05-03 22:59:47 +02:00
Taavi Väänänen
ed7e787f32
Ignore/fix MediaWiki.Commenting.PropertyDocumentation.WrongStyle
Fix the real issues found by this sniff, and convert the remaining
false positive ignores to per-line ignores so that any more real issues
won't be added.

Change-Id: I18e75d59df327e2d93a3a487c115e92b9f268722
2024-04-22 18:26:14 +03:00
Taavi Väänänen
ec6b4baba2
utils: zip: Fix PSR2.Classes.PropertyDeclaration.Multiple errors
Change-Id: I228f4d6fbf8195ca50b770e916dc09a40383ca1b
2024-04-22 01:13:49 +03:00
thiemowmde
4163b4388b utils: Improve documentation of UrlUtils protocol methods
As well as make use of the ??= operator where it makes sense.

Change-Id: I7d9aea8c4b985613016a918b7e0c87d2e0ffd01b
2024-04-15 15:31:15 +00:00
Bartosz Dziewoński
f32446684a GitInfo: Fix Phan warning on Windows
On my Windows machine, I was getting the following Phan warning:

includes\utils\GitInfo.php:159 UnusedPluginSuppression
  Plugin BuiltinSuppressionPlugin suppresses issue
  PhanPluginDuplicateArrayKey on this line but this
  suppression is unused or suppressed elsewhere

Indeed, this isn't a PhanPluginDuplicateArrayKey issue on Windows,
since DIRECTORY_SEPARATOR is `\`; but it is a legitimate warning
on other systems where DIRECTORY_SEPARATOR is `/`.

Refactor the code slightly so as to not create an array with
potentially duplicate keys.

Change-Id: I4be38aa9fefde26d58139d74a85359961229baec
2024-04-05 23:12:02 +02:00
James D. Forrester
8e940c4f21 Standardise all our class alias deprecation comments for ease of grepping
Change-Id: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0
2024-03-19 20:11:29 +00:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05: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
jenkins-bot
1a66246e19 Merge "Use native str_contains/str_starts_with in a few more places" 2024-01-25 16:27:36 +00:00
thiemowmde
4e7c3ca094 Use native str_contains/str_starts_with in a few more places
This makes the code quit a bit more readable, I believe.

strpos is especially confusing because it can return false when a
string doesn't contain the needle, as well as 0 when the string
starts with the needle. This is sometimes used as a feature (i.e. to
check if a string contains the needle, but doesn't start with it),
but that's not the case here.

A slightly more complicated change is made in TitleTest. But this is
only in a test and should verify itself when the test still succeeds.

Change-Id: I355ad1dc8e1725ae7a1eb652ec047ce7ff589cdf
2024-01-25 12:17:27 +01:00
Bartosz Dziewoński
4aebcfe097 Change more uses of getDBLoadBalancerFactory() to getConnectionProvider()
Some less trivial cases. Also update variable names.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: I6657d783375fac5c7fa856b884ff1fb09285e94c
2024-01-23 16:34:45 +01:00
Daimona Eaytoy
caef81d37a Replace deprecated MWException
Bug: T328220
Change-Id: Ic45438d9e6bbf127f1415add81ab902044765840
2024-01-16 21:04:33 +01:00
Siddharth VP
ce6bd364b9 Allow setting page restrictions on BotPassword grants
Helps bot operators adhere to the principle of least privileges.

Grants can now be restricted to allow editing (and other write
operations) for upto 25 listed pages. The page IDs are persisted within
the bp_restrictions field of bot_passwords table, and in the session
metadata.

This restriction is checked only as part of expensive checks in
PermissionManager, since they are not applicable for UI actions.

Bug: T349957
Change-Id: I3d228eb97664d040a160c5b742d9176fdfae9a43
2023-12-05 14:51:06 +05:30
Siddharth VP
d72917ea2f Refactor HTMLRestrictionsField to allow more restrictions to be added
Earlier, loadDataFromRequest() returned MWRestrictions object only in
case of valid input, and the original string if invalid. Now, an
MWRestrictions object is returned in all cases, on which we now have a
validity field. This also de-duplicates the check to find the invalid IP
address(es).

Bug: T349957
Change-Id: Iadb762b572cf0e7d2b92dbc4912804a3ddb48e74
2023-11-23 16:01:50 +00:00
C. Scott Ananian
bf3665f1e6 [UrlUtils] Update documentation to refer to new location of wfRemoveDotSegments
Change-Id: I44ad0e48835bbe963bfc921b71dd8a1b48eaced1
2023-11-16 12:20:42 -05:00
Timo Tijhof
268c2a5b5a GitInfo: Update use of SpecialVersion utility methods
* Avoid calling the SpecialPage code directly in e.g. an API module.

* Remove unused method "getGitCurrentBranch" on internal class
  without deprecation.

* Mark "getGitHeadSha1" as hard-deprecation first, as there are
  (unfortunately) two direct callers in Codesearch.

* Reduce indirection of non-configurable $IP and $wgBaseDirectory
  variables in favour of MW_INSTALL_PATH or GitInfo::repo().

* Move potentially duplicate brief and ingroup from file doc
  to class doc. See also
  <https://gerrit.wikimedia.org/r/q/message:ingroup+owner:Krinkle>

  Add example of LocalSettings.php use case, based on the
  original 36b1172147 (I2a76662bb4) commit message.

* Remove use of AtEase (T253461).

* Fix potential Windows bug where only backslash was replaced, since
  that is the canonical path separator, but for this use case, regular
  slash should (also) be substituted since most contexts on Windows
  nowadays support that as well, e.g. \foo/bar and \foo\bar are
  equivalent on Windows.

Change-Id: Ib2c89461edc358404544e4236a7a2dc5699b8d4e
2023-10-19 17:21:35 -07:00
jenkins-bot
70ef48b846 Merge "Improve performance of trivial encoding/decoding regexes" 2023-10-17 20:54:11 +00:00
Umherirrender
1e189e7ae0 Use the expression assignment operator to simplify code
Suggested by phan, available since php7.4

Change-Id: Ic372ba9abb14de1196b89fca079e99168464eb06
2023-10-14 00:40:55 +02:00
thiemowmde
f5cd1ba7ca Improve performance of trivial encoding/decoding regexes
Instead of replacing 1 character at a time the functions used here
can replace sequences of any length. This can dramatically reduce the
function call overhead.

Also make use of the `fn ()` syntax because we can.

Change-Id: I2dbc2271aa7847d9b687703f837cb0d850596ef0
2023-10-04 11:09:44 +02:00
jenkins-bot
871c2f2160 Merge "Follow RFC 3986 on what is path in mailto URLs" 2023-09-20 15:38:07 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
Petr Pchelko
5ad8ee4d92 Follow RFC 3986 on what is path in mailto URLs
This hack was originally added to wfParseUrl
as a fix for T10324 specifically for LinkFilter,
however according to the RFC 3986 this is wrong.

RFC defines that in URLs the authority component
must start with //, so in urls without //, e.g. news:
or mailto: there is no authority component, and thus
no host component, everything after : is actually a path,
so default PHP parse_url is correct.

RFC even has an example:
> For example, the URI <mailto:fred@example.com>
has a path of "fred@example.com".

It's fairly ugly to just copy-paste the hack
into LinkFilter, but I didn't find an easy and
elegant way to rewrite it without making any
changes to the link indexes values stored in the DB.

See https://datatracker.ietf.org/doc/html/rfc3986

Co-Authored-by: 沈澄心 <dringsim@qq.com>
Change-Id: I3dd04495db9c7a66f62c3914c0eff06754b7d560
2023-09-04 05:48:23 +00:00
James D. Forrester
aa30717d4a Follow-up 15a2781: Add in-code comment on alias for when it was added
Change-Id: I7fd16236c60cb5e1f2d09b9bdb09df130d345c71
2023-08-29 01:29:55 +00:00
James D. Forrester
8f857f88d8 Follow-up cb73518: Add in-code comment on alias for when it was added
Change-Id: I5ffbe7fc4bd1fec1ff4e4e86b8e11f69b11c1b6d
2023-08-29 01:29:38 +00:00
James D. Forrester
5214e80136 Follow-up c822159: Add in-code comment on alias for when it was added
Change-Id: Ibb7f56128ce44c1a1ae55ac7d964bc364f4428bf
2023-08-29 01:29:22 +00:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Amir Sarabadani
cb7351809e Reorg: Move GitInfo to utils/
Bug: T321882
Change-Id: Ibd8aff5f57555d5b2a3b9cd121c8919a5a96d313
2023-08-21 18:35:32 +02:00
Amir Sarabadani
c822159cb4 Reorg: Move ExtensionInfo to utils/
Bug: T321882
Change-Id: I5d0539821ded4ed9f2698ecbc76c2678612f1c97
2023-08-19 11:15:34 +02:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
Timo Tijhof
b862174dc0 UrlUtils: Make assemble() and removeDotSegments() stateless
Follows-up 472a914c63 (I706ef8a50aafb51), which moved various
functions here en-mass, but these two don't require any state.

The warnings about parse_url() in UrlUtils.php have been obsolete
since about PHP 5.4, when it started to support protocol-relative
URLs, non-slash protocols like "mailto", and deal with spaces/newlines
correctly (https://3v4l.org/YWUkl).

Rather than complicate many components that would otherwise remain
stateless and unit-testable, fix these to once again be the static
functions they were.

For impact, see upto PS17 of change I5117eab95f57297eb02bed.

Bug: T227900
Change-Id: Ifb3f720fc429b107348644c98eb9cd8e1113a42a
2023-08-10 03:39:42 +01:00
jenkins-bot
55340d0683 Merge "Migrate more usages of Database::update() to UpdateQueryBuilder" 2023-06-09 19:39:57 +00:00