Commit graph

245 commits

Author SHA1 Message Date
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
jenkins-bot
dbe8c4b9aa Merge "WebRequest: Deprecate parameter $default in getRawVal" 2024-10-10 15:05:35 +00:00
jenkins-bot
c09ac42243 Merge "build: Use inline ignore for MediaWiki.Usage.DeprecatedGlobalVariables" 2024-10-05 15:59:19 +00:00
Fomafix
9208216d6b WebRequest: Deprecate parameter $default in getRawVal
Use
	$request->getRawVal( 'key' ) ?? 'default'
instead of
	$request->getRawVal( 'key', 'default' )

The ?? is more flexible, avoids a wrong type detection by phan and
avoids the evaluation of the default value if not needed.

Bug: T376245
Depends-On: I3ed6b85c0d117ed7cb3a8b79f73a3eb42977891e
Change-Id: I8b02f9297b76d04e21f8cb9194f3b85631956eca
2024-10-03 15:49:33 +00: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
Umherirrender
f910edce6d Add @phan-mandatory-param for function name arguments
Providing the function name is often optional from the php code,
but it is needed for better logging, so make it mandatory and let phan
report issues about this.

Bug: T374546
Depends-On: Iaed5489a85a5a6e685829e151436afc94310fbd0
Depends-On: Ie2a1e5052e5b61bbb5b89905de942f47d3f1413d
Change-Id: I5227f2fa65850ac8c6f620900f22d1f4e7bfd470
2024-09-20 16:23:17 +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
Bartosz Dziewoński
c9f73efd5a Namespace MessageSpecifier under Wikimedia\Message\
In change I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83 I am planning to
make Wikimedia\Message\MessageValue use it, and we try to pretend that
it is a library separate from MediaWiki, so it makes sense to move
MessageSpecifier to the same namespace under Wikimedia\.

Bug: T353458
Change-Id: I9ff4ff7beb098b60c92f564591937c7d789c6684
2024-07-28 14:21:32 +02:00
WMDE-Fisch
c16a572770 Use UserFactory in RequestContext class
Change-Id: Iea7d02b886195e6e6f072883e89056c0eb3c797c
2024-05-04 15:22:22 +03: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
Tim Starling
aa01c94b3d In RequestContext::setUser() also reset $this->skinName
Viewing a page which transcludes Special:Prefixindex leads to the
default skin being used for the main request, instead of the user's
skin, in a regression of a bug from 2023. Tracing shows that
OutputPage::setupOOUI() calls RequestContext::getSkinName(), and the
skin name is permanently cached.

So, reset the skin name when the user is reset. This is a simple partial
fix.

Bug: T336504
Change-Id: If630f337ba6fb2b889e657d49112b878c3ad5f83
2024-02-27 10:35:42 +11: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
Umherirrender
080a1807fc context: Fix documentation for IContextSource::getLanguage
The function is not defined in the extends interfaces to inherit
documentation from.

Follow-Up: I8334cc89dcf0f293298b82e004116be50a90f0d1
Change-Id: I14b2adfaa3c859ce7b196fc639b0974bbbf01834
2024-02-09 18:47:12 +01:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
daniel
3d55397207 Move creation of BlockErrorFormatter into FormatterFactory
The idea is that all formatters that need the user language or
other request specific context should be instantiated by
FormatterFactory.

Change-Id: I8334cc89dcf0f293298b82e004116be50a90f0d1
2024-01-26 13:03:44 -05:00
Daimona Eaytoy
175c0c4abf Replace more instances of deprecated MWException
Bug: T328220
Change-Id: Iba90f7f9b5766bccc05380d040138d74d5e9558a
2024-01-19 23:11:59 +00:00
Reedy
2b8c13d610 IContextSource: Minor comment tweaks
Change-Id: Ie71bf8f949c87533da254c91cdd688d5be27fe07
2024-01-02 02:20:27 +00:00
Bartosz Dziewoński
ce93c44da1 RequestContext: Replace $wgCommandLineMode checks with MW_ENTRY_POINT
Using FauxRequest in CLI mode was originally added in
2f7f99b1f1 / r91460.

Bug: T313841
Change-Id: Id3bdc551088d70f13f0d8e90392dab9f1aa33832
2023-12-19 00:27:51 +01:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Wandji69
ca4cb02e4c context: Disallow cloning RequestContext object and throw an error
Bug: T323187
Change-Id: Ib4a1e97d7ab9f91b937e099394ccd9a2d37a841b
2023-09-14 22:09:35 +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
Amir Sarabadani
d8e542abf9 Reorg: Move three output related classes to includes/Output/
And namesapce them:
 - StreamFile
 - OutputHandler
 - OutputPage

Bug: T321882
Change-Id: Iedf8d88c595e580f2d8f0734c92aa5c45618ba33
2023-09-05 19:36:42 +01:00
Umherirrender
0be0c60c4c Reset the cached skin in RequestContext::setAuthority()
Similiar to the reset in setUser() from 242a5b2a
Just in case as more code could be migrated to use setAuthority()

Follow-Up: I4fc815f00933193f6b0eeb996a2f75a4295ecb01
Change-Id: I0aa6c3de5413ecf66b5b21f5229dd3026ff9f118
2023-08-03 02:06:16 +02:00
Tim Starling
5c6bb65c1c Normalize the skin name when "skin" is in HiddenPrefs
When $wgHiddenPrefs['skin'] = true and $wgDefaultSkin is set to a
nonexistent skin, SkinFallback should be used. An exception should not
be thrown.

An odd case, but it did work before a99e31533b.

Add test. Simplify the existing tests, using StaticUserOptionsLookup
instead of the mock builder.

Bug: T342733
Change-Id: I372ace56c104a3ecc9c02d87524e8ef0be7239cf
2023-07-27 10:17:13 +10:00
Tim Starling
f3beedd0b8 Normalize the skin name when it comes from preferences or useskin
Bug: T342733
Change-Id: I4459663fb4ce3436dba533104e21533b0b6827e7
2023-07-26 23:01:24 +10:00
jenkins-bot
310376cb2d Merge "context: Simplify RequestContext::getSkin() logic" 2023-07-25 01:41:37 +00:00
jenkins-bot
073e1a6b0b Merge "Ignore parameters to OutputPage::setupOOUI() and deduplicate calls" 2023-07-25 01:03:58 +00:00
Timo Tijhof
8c479bcca1 context: Simplify RequestContext::getSkin() logic
I had to read this 5x to convince myself that it wouldn't discard
the assigned `$this->skin` object (from the elseif branch in the middle)
in the `if ( $skinName !== null )` branch below.

It appears to work fine, but it may be clearer to avoid the indirection
through checking that $skinName got assigned and rather move those
branches together.

This coincidentally matches the evaluation order of fetchSkinName().

Change-Id: Ia20136b8f04c8e8d89d29b97cdd99cb444c09838
2023-07-25 01:54:03 +01:00
Tim Starling
a99e31533b Ignore parameters to OutputPage::setupOOUI() and deduplicate calls
There are about 33 callers in Code Search, and almost all were calling
it with incorrect parameters.

It was incorrect to call it with no parameters, since this would
globally set the wrong skin and direction. Most callers were doing this.

It was incorrect to call it with the values from some local context.
We are setting a global singleton here so only the global RequestContext
has the correct values.

Usually, setupOOUI() is called to avoid the exception which is thrown
when HTML is generated without a singleton. But it was often called
multiple times in a request, because different parts of the stack need
OOUI HTML and they don't know whether OOUI has been initialised.

So, ignore the parameters passed to setupOOUI(). Ignore all calls after
the first one, so that we can stop throwing away the theme object. Reset
the cached data when RequestContext::setSkin or
RequestContext::setLanguage() are called.

Add RequestContext::getSkinName() so that the name of the skin can be
determined without actually creating the skin object. It would be
complicated to add the method to IContextSource since there is a
method of the same name in Skin, which implements IContextSource.

Change-Id: I7a1e8b613408d2ecc2e497e0672644af85ce0da3
2023-07-25 09:51:10 +10:00
thiemowmde
ef84619cd3 Consistently use LogicException for test-only methods
"BadMethodCallException" sounds like it would fit, but it does
have a very different meaning, described as "exception thrown if
a callback refers to an undefined method or if some arguments are
missing". This is not what's going on here. These are methods that
should only be called from unit tests.

This appears to be a common mistake, often copy-pasted.

Change-Id: Ib39e28f596a883481d5f526460a5c871c75f5313
2023-07-22 16:21:42 +00:00
Daimona Eaytoy
b8e380f775 Refactor SpecialPreferencesTest
Make it extend SpecialPageTestBase and simplify it accordingly, removing
a lot of things that are no longer needed. I'm not even sure if this
test still serves a purpose, but at least it should be easier to
maintain now. This also fixes a test failure when
UniversalLanguageSelector is enabled due to a ULS hook error.

This approach still needs a hack for overriding UserOptionsManager,
because it's used in a lot of places with lots of expectations and
global state, and the mock would need to be much more complex for that.

Also:
- Remove unchecked exceptions from doc comments.
- Fix indentation of a conditional where the second line of the
  condition was indented the same as the body, which made it hard to
  read.
- Add some return typehints to various methods. These make it easier to
  write tests because if a method is return-typehinted, PHPUnit will
  mock the return value automatically, instead of returning null and
  leaving it up to the developer to provide a mock explicitly.
- Add string typehint to Skin::normalizeKey. The value is already
  assumed to be a string, and passing null to strtolower emits a
  deprecation notice in PHP 8.1.

Change-Id: I80723b886b2b5a5d75cbb73571e1b19ea4a09af5
2023-07-19 01:28:30 +02:00
Daimona Eaytoy
8adf1bfb93 Replace some more usages of deprecated MWException
Bug: T328220
Change-Id: I3c36835fbd90acc301731e2b33ae4815cd4b0cc5
2023-06-09 02:07:08 +02:00
Tim Starling
242a5b2a56 Reset the cached skin in RequestContext::setUser()
Bug: T336504
Change-Id: I4fc815f00933193f6b0eeb996a2f75a4295ecb01
2023-05-12 10:45:54 +10:00
Umherirrender
e04d3a28f6 Replace internal Hooks::runner
The Hooks class contains deprecated functions and the whole class is
going to get removed, so remove the convenience function and inline the
code.

Bug: T335536
Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
2023-05-11 06:17:38 +00:00
Tim Starling
580ec48e5b Fix more PHPStorm inspections (#2)
* Illegal string offset and invalid argument supplied to foreach, due to incorrect type information
* Array internal pointer reset is unnecessary
* $hookData unused since MW 1.35 due to incomplete revert
* array_push() with single element
* Unnecessary sprintf()
* for loop can be replaced with str_repeat()
* preg_replace() can be replaced with rtrim()
* array_values() call is redundant
* Unnecessary cast to string
* Unnecessary ternary. Often the result relies on short-circuit evaluation, but I find it more readable nonetheless.

Change-Id: I4c45bdb59b51b243fa96286bec8b58deb097d707
2023-03-25 00:19:58 +00:00
Matěj Suchánek
c231736471 Fix some typos
Bug: T201491
Change-Id: I5c9408c262f09c936525f35abfacfa92a193b791
2023-03-21 15:58:09 +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
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
jenkins-bot
af9efedb55 Merge "Remove references to Suhosin and its INI settings" 2022-11-10 08:36:01 +00:00
Krinkle
08286fdf91 Setup: Promote clearActionName log message to runtime warning (2)
This reverts dc3bd3d721 (I385dca1d95) and re-applies d4ce0f3255 (Ib9fc34ca64).

The CI failures have been addressed.

Bug: T314008
Change-Id: I35a4f656c31b67ebb662bf6f6366f4ee846ecbda
2022-11-08 23:29:25 +00:00
Kevin Israel
17ba1988c0 Remove references to Suhosin and its INI settings
The Suhosin extension is no longer being developed, and its developers
never made a proper release for PHP 7.[1]

The suggested replacement, Snuffleupagus, does not have a configuration
setting for limiting the length of a request value[2]. If one existed,
it would be in the extension's own config file[3], not in php.ini.

Snuffleupagus does have a session encryption feature, which is similar
to that of Suhosin.[4] Note, however, that with the introduction of the
SessionManager framework, such a feature is incompatible with more than
just RequestContext::importScopedSession(). Snuffleupagus fails to
decrypt the string returned by PHPSessionHandler, zend_bailout() is
called[5], and an empty response is sent (unless, of course,
$wgPHPSessionHandling is set to 'disable').

[1]: https://github.com/sektioneins/suhosin7
[2]: https://github.com/jvoisin/snuffleupagus/blob/v0.8.3/config/suhosin.rules#L239-L251
[3]: https://snuffleupagus.readthedocs.io/config.html
[4]: https://snuffleupagus.readthedocs.io/cookies.html#cookie-encryption
[5]: https://github.com/jvoisin/snuffleupagus/blob/v0.8.3/src/sp_session.c#L53-L56

Change-Id: I561729fe2e3b57523de78ce63870987ab91cfd37
2022-11-03 10:34:03 -04:00
Tim Starling
d47ca15928 Make RequestContext::sanitizeLangCode() accept null
I think it's within the meaning of the method to sanitize the type of
the input. Code review shows that it's almost always called with
technically nullable input, so it's convenient to deal with nulls at
this single place.

The linked bug is a PHP 8.1 deprecation warning due to a test which set
up a StaticUserOptionsLookup without a language option.
StaticUserOptionsLookup does not fall back to the site defaults, so the
language was null, causing an error from strtolower().

Bug: T322099
Change-Id: I6dc61476c6869a7648a67be79a4835a5ac24fa92
2022-11-02 13:05:47 +11:00
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02: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
Umherirrender
56adfea4d3 context: Remove deprecated IContextSource::getStats() implementations
Hard-deprecated since a6fe660.

Change-Id: Id26aabcb6cbcedfe45224af161a998bda3aff451
2022-09-30 19:52:40 +00:00
Timo Tijhof
ee5ad165e6 pager: Clean up file headers and @ingroup
Follows similar commits to the objectcache, rdbms, filerepo,
jobqueue components and other areas [1].

* Remove duplicate descriptions from file blocks in favour of class
  doc blocks. This reduces needless duplication and was often
  incorrect or outdated, and helps (ironically) to make the file header
  more consistently visually ignorable.

* Remove `ingroup` from file blocks in class files as otherwise
  the file is indexed twice (e.g. in Doxygen) which makes navigation
  more messy.

* Fix non-standard `@unstable for implementation` annotations
  in favour of `@stable to type` as per T257789 and
  <https://www.mediawiki.org/wiki/Stable_interface_policy>.

  While at it, fix the only other outstanding uses of `@stable for`
  in core as well in a handful of context/, logging/ and search/
  files.

[1] https://gerrit.wikimedia.org/r/q/message:ingroup+owner:Krinkle

Bug: T257789
Change-Id: Ided3c5ab69e1b587b1b76a3c97a7cdb88f21e130
2022-09-29 21:05:08 +01:00