Commit graph

329 commits

Author SHA1 Message Date
Gergő Tisza
b4dc368f72 HttpError: Cast Message to string
In theory PHP should use coerce objects with a __toString method
to string when passing them to a method which has a string-typed
argument, but with the native Exception class this doesn't seem
to be working, so cast explicitly.

Bug: T388171
Change-Id: I310b97164877445837babed2a4c47795f1c2c277
(cherry picked from commit a14ef848f758612ac9d4e8c881ecdbbccf3e1158)
2025-03-11 21:58:06 +00:00
Reedy
fc1759bfe6 MWExceptionHandler: Add error suppression to constant( 'E_STRICT' )
Bug: T375707
Change-Id: I075edf064cefa012d3d7a2c734a2e9051a826074
Follows-Up: I5937cacdf5b01614042a06d4deb5112ffff51727
(cherry picked from commit 96a12a2dd6b98a25e4a9048a25b2b5010036e32c)
2025-01-21 22:31:11 +00:00
xtex
7fec3fdec6 exception: Convert E_STRICT errors to E_USER_NOTICE
E_STRICT is deprecated in PHP 8.4.0.

MediaWiki (and almost all extensions) no longer produces errors at this
level.
To not break the compatibility, let's converts all E_STRICT level errors
to E_USER_NOTICE, which is also mapped to warning severity.

Using '@' operator to avoid generating the deprecation warning of
E_STRICT.

This should addresses the deprecation warning of E_STRICT when another
warning or error is raised.

Bug: T375707
Change-Id: I5937cacdf5b01614042a06d4deb5112ffff51727
2025-01-03 16:31:41 +00:00
Tim Starling
218bb176cb exception: Suppress dependency loop exception
If an exception is thrown or an error is raised during HookContainer
construction, don't be surprised when you can't get a HookContainer.

When checking if we need to roll back transactions, use peekService()
instead of isDisabled(). According to the disableService()
documentation, peekService() will always return null for a disabled
service. If the service hasn't been created, there can be no
transactions open and so there is no point in rolling back.

It's not necessary to catch DBError exceptions from peekService(),
since it never calls the instantiator.

Fix phan error by broadening the onLogException() parameter type. Phan
is correct, the parameter is not guaranteed to be
Exception|ErrorException and so the previous documentation was wrong.

Bug: T379125
Change-Id: Ie5ec2bd1ecfb0114f3d00fc28b2c5e3db9bd87c0
(cherry picked from commit 5cf3cd03dfd3f7acca4d78bf12054f3c315fee28)
2024-11-08 16:16:00 +00: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
Dreamy Jazz
0fa81768c2 Send temporary accounts to Special:CreateAccount on ::requireNamed
Why:
* When code throws a UserNotLoggedIn error for a temporary account,
  this takes them to Special:UserLogin and asks them to log in to
  an account
* Users using temporary accounts are less likely to have a named
  account, so should instead be sent to Special:CreateAccount
  (as described in T358586)
* When doing this, the warning message should be customised to
  talk about the user needing to create an account (and not
  log in)

What:
* Update UserNotLoggedIn to redirect to Special:CreateAccount
  when the user is logged in to a temporary account
** The code which constructs the exception object can override
   this and force the redirect to always be to Special:UserLogin.
* When the redirect is to Special:CreateAccount, allow customising
  the message shown by adding a '-for-temp-user' suffix to the
  message key in UserNotLoggedIn.
** This suffix is only added if the resulting message exists,
   so that code can choose whether they need a message that is
   different to the one on Special:UserLogin.
* Update SpecialPage::requiredNamedUser to allow special pages to
  force the redirect to always be to Special:UserLogin
** This is made use of in Special:ChangeEmail and
   Special:ConfirmEmail, as these special pages only make sense
   for use with an existing account.
* Update and add message keys to allow a different message for
  Special:CreateAccount.
* Update and add tests for these changes.

Bug: T358586
Change-Id: Ie0dd06f51b1e2b85eef6be377f673a02732ce604
2024-09-24 21:42:17 +00: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
Umherirrender
6eec17e9a9 Add missing documentation to class properties (miscellaneous classes)
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.

Change-Id: I1da4b272a6b28c419cc8e860d142dae19ca0bbcf
2024-09-14 10:12:18 +02:00
Umherirrender
31c1011105 exception: Use const for MWExceptionHandler::$fatalErrorTypes
Also remove @var from const, the type is given by the value of the const
and does not need documentation.

Change-Id: I65636f2b97b44387c4320ebfb4be6c81d6f771b9
2024-09-01 13:24:03 +02:00
Bartosz Dziewoński
62cfede3fa PermissionsError: Deprecate public properties
Follow-up to 298ec8382b, which replaced
`public $errors` with `public $status`, causing T372181.

* Add a deprecated fallback getter/setter for $errors
* Make $permission private and add a deprecated getter/setter
* Make $status private

Bug: T372181
Change-Id: If44b2256289d6bde9e9abb901d9dc145555c971f
2024-08-12 21:37:04 +02:00
Bartosz Dziewoński
298ec8382b PermissionsError: Replace use of legacy error arrays
Change-Id: I5493deb8b72f499ecd46b8093b5fffbb12e7c246
2024-08-09 13:53:27 +00:00
Ebrahim Byagowi
466868acf8 Move directionality of the error box to outside of it
If the error back-trace is wide enough, it will make the table
to overflow behind it's first column in an unexpected way that
backtrace's left side which is the most important part will be
hidden in an overflow so let's apply the directionality from
outside of the table.

Change-Id: I862ffc835c5a4a627546ef69d19056adfc285442
2024-08-07 18:24:42 +00:00
Ebrahim Byagowi
bae9e2d5bf Make error box content LTR for exceptions details
This apparently supposed to happen via mw-content-ltr but it actually
isn't and supposed to also use LTR when exceptions details isn't enabled
which both don't work and actually the latter isn't needed as there is
a translated RTL message there make it unnecessary to be in in LTR.

More about the details in the linked bug.

Bug: T371804
Change-Id: Icc3562a7b9a72408790c75a93994c0d63c0f66e2
2024-08-05 16:02:54 +00:00
Bartosz Dziewoński
df4cbf5ac6 Replace gettype() with get_debug_type() in debug/log/test output
get_debug_type() does the same thing but better (spelling type names
in the same way as in type declarations, and including names of
object classes and resource types). It was added in PHP 8, but the
symfony/polyfill-php80 package provides it while we still support 7.4.

Also remove uses of get_class() and get_resource_type() where the new
method already provides the same information.

For reference:
https://www.php.net/manual/en/function.get-debug-type.php
https://www.php.net/manual/en/function.gettype.php

In this commit I'm only changing code where it looks like the result
is used only for some king of debug, log, or test output. This
probably won't break anything important, but I'm not sure whether
anything might depend on the exact values.

Change-Id: I7c1f0a8f669228643e86f8e511c0e26a2edb2948
2024-07-31 19:33:57 +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
Umherirrender
08f758e29a exception: Avoid raw \n in HttpError
Follow-Up: Id8360ff3ca6dbe7b78e30194fde292763479cb21
Change-Id: I9f5b8544a0a12d7ad394712106c08f7ca52afee8
2024-07-16 21:39:19 +02:00
Umherirrender
472891385d Use namespaced classes (2)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Id9f3e775e143d1a17b6b96812a8230cfba14d9d3
2024-06-16 20:23:55 +02:00
jenkins-bot
2ec0f7d9ec Merge "Add dark mode support to plain html outputs" 2024-06-11 11:19:09 +00:00
Ebrahim Byagowi
ede4d6ec12 Add dark mode support to plain html outputs
Nowadays files transferred to browser via text/* MIME are also getting
automatic dark mode by the browsers so this makes these simple pages
compatible with those features of the browsers.

Change-Id: Id8360ff3ca6dbe7b78e30194fde292763479cb21
2024-06-09 15:03:14 +03:30
Bartosz Dziewoński
1fa0d1f73d PermissionsError: Replace duplicated code
Change-Id: Ie873137494f5f57c2a1001afc211a48af567550e
2024-06-06 02:35:21 +00:00
jenkins-bot
7fc3b17a9e Merge "LoginSignupSpecialPage: Support &display=popup" 2024-05-23 16:03:19 +00:00
Bartosz Dziewoński
5623b2e44c LoginSignupSpecialPage: Support &display=popup
Setting this URL parameter will replace the default skin with a
"micro-skin" that omits most of the usual interface elements,
making the page suitable to be displayed in a small popup window.
Its design (such as it is) is mostly based on Vector 2022.

In the future, we might allow normal skins to serve this mode too,
if they advise that they support it by setting a skin option.
For now that is out of scope.

The login/signup process is otherwise completely normal. To make use
of it, launch the login page in a popup, and set &returnto=... to
redirect back to your own success page, which should communicate the
successful login to your app and then close itself.

The display=popup / display=page vocabulary is borrowed from the
OpenID Connect spec.

Bug: T362706
Change-Id: Ic7cbbe98344b25d2e965750e0c4429ce157163ed
2024-05-22 22:06:31 +02:00
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
Timo Tijhof
ee292ca30d exception: Remove "error-json" debug log channel
This was introduced to allow maintainers during local development,
and e.g. when debugging in production, to capture silenced runtime
warnings, such as those silenced via AtEase or the `@` PHP operator.

These are not expected to be of interest to capture by default on
web requests, hence placed in a separate channel that e.g. one would
only enable during development, or when debugging.

When this was introduced, MediaWiki was only just starting to
experiment with PSR-3 structuerd logging, and thus it hardcoded JSON.

Now that we support structured logging natively, this has been
obsoleted by the "error" channel (for warnings in production),
and (since last December) the "silenced-error" channel (for debugging
and development) with commit f6cb39979b (I34b19837c3).

With the above two alternatives available, there is no longer a need
for the duplicate "error-json" channel.

Bug: T193472
Change-Id: I7a6e6fa52a47a29ec04411a6c8b05e005a0a4fc7
2024-05-14 17:42:08 +00:00
Amir Sarabadani
214674d6b1 namespace MWDebug
Bug: T353458
Change-Id: I99d728bd111ff882220cd175ff09d4da20b81eae
2024-05-03 22:59:47 +02:00
Bartosz Dziewoński
3bb9d855c1 Remove error printing in MWException
Was deprecated in I66d896f6f229b90e6ba9949311b56a6b6ab3da3d.

Bug: T353444
Change-Id: I004b1b87a7ef1a908123369842792d940b7d8079
2024-04-25 11:58:53 +00:00
Taavi Väänänen
8173e9f80c
exception: Fix PSR2.Classes.PropertyDeclaration.Multiple errors
Change-Id: I665fb6d661b4c92f0e473632c9c35b0452ff0e1a
2024-04-21 22:17:32 +03:00
Bartosz Dziewoński
02044a5ba1 Document more methods that accept MessageSpecifier, not just Message
These methods can already handle any MessageSpecifier, but their
documentation didn't show this.

Change-Id: I1323d18baf17a8a27cc9bed31860c4cc89e61a22
2024-04-09 20:25:18 +02:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Gergő Tisza
5dbacd0b23
Limit language logic when displaying exceptions / outage messages
* Avoid looking up the message in the database. We might be
  displaying a readonly error or the connection might be in a
  broken state, and there is little reason for per-wiki
  customization of error messages in any case.
* Prevent a user-language lookup if the user is not available
  (this happens e.g. for errors in load.php).

Bug: T127233
Bug: T356578
Change-Id: Ib5ea11a39257bed7381faa277a5df0bf4d0f5e97
2024-02-04 02:23:27 -08: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
jenkins-bot
3f814c0753 Merge "Deprecate error printing in MWException" 2024-01-22 02:16:11 +00:00
Daimona Eaytoy
1d6776fdbc Replace deprecated MWException
Also remove some unchecked exception from doc comments.

Bug: T328220
Bug: T240672
Change-Id: I88b1e948ce5da77d9c4862a2b98793d6ba00cf8b
2024-01-19 21:58:42 +00:00
thiemowmde
06c13725f1 Fix string→array type mismatch in ReadOnlyError
The parent's ErrorPageError::__construct() expects an array of
params.

Change-Id: I1a3a225df97c75fba20d8b32d5a19e974d80c7a1
2024-01-16 18:16:33 +00:00
Bartosz Dziewoński
825bf602a5 Deprecate error printing in MWException
It's now deprecated to use the individual error printing functions in
MWException or to override them. Printing MWException now works the
same as any other exception, and happens in MWExceptionRenderer.

It's still allowed to override MWException::report() to replace the
entire error page, for example in ErrorPageError.

Bug: T353444
Change-Id: I66d896f6f229b90e6ba9949311b56a6b6ab3da3d
2024-01-10 16:38:43 +01:00
daniel
a4853b0aa5 Introduce MediaWikiEntryPoint and ActionEntryPoint
This extracts the MediaWikiEntryPoint base class and ActionEntryPoint
class from the MediaWiki class. MediaWiki itself be deprecated.

The intent is to create other subclasses of MediaWikiEntryPoint for the
use by other entry points such as thumb.php or api.php. This will allow
us to share code between entry points, and make these entry points
testable by moving their implementation into a class.

Bug: T354216
Change-Id: Ib70e4e67e4cb1b65ac218c095864fb6eb43d0929
2024-01-03 19:20:44 +01:00
jenkins-bot
c8d061d177 Merge "exception: Send silenced errors to a new log channel with level=DEBUG" 2023-12-21 18:38:46 +00:00
Bartosz Dziewoński
5c8a688b4d exception: Replace $wgCommandLineMode checks with MW_ENTRY_POINT
Replace some other global variable checks with MW_ENTRY_POINT too.

This unfortunately makes it difficult to override the result of
isCommandLine() for testing. However, the existing tests weren't
really checking anything useful, but rather just duplicated the real
code, so I won't miss them.

Bug: T313841
Change-Id: I8bc200d67877ce04f80fd587481a76c7df629d51
2023-12-14 18:01:17 +00:00
Umherirrender
72d6b46339 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: I443aada1c18c8628b02671aa9fd6f441961e5c2e
2023-12-11 16:07:18 +01:00
Timo Tijhof
f6cb39979b exception: Send silenced errors to a new log channel with level=DEBUG
Follows-up 4f08bb3be9 (I240b75f5a4), which improved the "error" channel
to make use of the PSR-3 severity level (instead of defaulting to
ERROR).

This change exposes the suppressed errors to a new channel,
with a forced severity level DEBUG.

The formatted message is unchanged and reflects the original severity
through its "message" (i.e. "PHP Notice", "PHP Warning", etc.)

Bug: T193472
Change-Id: I34b19837c391ff4acdb55fc0c310c0f554f15da2
2023-12-10 04:17:22 +00:00
James D. Forrester
439a60eabb Drop MWExceptionHandler::rollbackMasterChangesAndLog(), deprecated in 1.37
Change-Id: I1fb68eca5159b56725f6a16822b3d3fcb503d4e4
2023-12-08 17:32:58 -05:00
Thalia
448fac4362 Display multiple block messages on UserBlockedError page
Bug: T349826
Change-Id: I8ce74d7dc88aef9c30266e844425a748125f0715
2023-11-02 13:09:42 +00:00
jenkins-bot
9b1db9b8bd Merge "Deprecate explicit arguments to OutputPage::prepareErrorPage()" 2023-09-22 12:12:14 +00:00
Umherirrender
f4ef430d28 Use ::class for class name resolution
Change-Id: Ic74a3d317c9d36509a50c658e52fad65026e7ac7
2023-09-21 23:27:28 +02:00
C. Scott Ananian
ea7ef391c2 Deprecate explicit arguments to OutputPage::prepareErrorPage()
Callers should use OutputPage::setPageTitleMsg() instead of the code
inside ::prepareErrorPage() which invokes ::setPageTitle(), in order
to opt in to proper HTML escaping of the message argument.  For
backward compatibility, preserve the old behavior of
::prepareErrorPage() but deprecate passing explicit parameters to that
method and instead suggest that callers explicitly call
OutputPage::setPageTitleMsg() themselves.

Bug: T343994
Bug: T343849
Change-Id: I12b19198f09504683ecbeb72c581946c91a744a6
2023-09-21 16:38:22 -04:00
James D. Forrester
468e69bccc Namespace Sanitizer under \MediaWiki\Parser
Bug: T166010
Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
2023-09-21 05:39:23 +00:00
James D. Forrester
3851805f64 Namespace remaining User-related classes under \MediaWiki\User
Bug: T166010
Change-Id: Ibda1e8be0f23c6262a32b607f8260cad36f188fc
2023-09-20 09:12:08 +01:00
James D. Forrester
5bc2a04b08 Namespace remaining Title-related classes under \MediaWiki\Title
Bug: T166010
Change-Id: Ia2e5a7367cc8cdbd8a7b845ae2fd5d776ff22891
2023-09-19 05:21:23 +00:00
James D. Forrester
459cbb0494 Namespace remaining 'specialpage' files under \MediaWiki\SpecialPage
SpecialPageFactory is already here, but none of the others were yet.

Bug: T166010
Change-Id: I9689bf0a1ab329625e23669b99f019b96295fffd
2023-09-18 18:23:13 +01:00
Daimona Eaytoy
f78fd3710d Add $wgRequest to phan's globals_type_map
The base phan config uses a file_exists check to determine whether to
use the namespaced class name, but it doesn't work when running against
core because MW_INSTALL_PATH isn't set. So specify the type in the local
config, and remove @phan-var annotations added in I6bbdbbe6.

Also use `::class` instead of string literals for classes.

Change-Id: I994a0ed32ea948253ed07ee3cc8868a0eaa6d8b9
2023-09-11 23:22:12 +02:00