Commit graph

60 commits

Author SHA1 Message Date
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
umherirrender
54c1e18eec Remove various double empty newlines
The double empty newline is not needed between functions, variable or at
end of file

Change-Id: Ib866a95084c4601ac150a2b402cfa184ebc18afa
2015-12-27 18:55:12 +00:00
Aaron Schulz
58cffd04b8 Pass __METHOD__ to load balancer commit/rollback methods
Change-Id: I3fd87908c2a493fae49de6a29efe79f8d433c112
2015-12-22 18:30:20 -08:00
Aaron Schulz
3a5c66c7dd Fix some MWExceptionHandler IDEA errors
Change-Id: I98b5aa4f29107185b2279ce4caf05ffe80fcd6b0
2015-12-13 04:26:01 -08:00
umherirrender
cf1d31b604 clone is not a function
Remove parenthesis around clone magic word

Change-Id: I2e0e53303f7c73745bd1ab4bcf32e74943efc4de
2015-10-16 19:34:31 +02:00
Alex Monk
9144554931 Handle $frame['function'] not being set in stack frames
Bug: T115107
Change-Id: I9fbfcd53fbcba1800a924acb1a1702c3c9037cc5
2015-10-14 13:05:29 +00:00
Timo Tijhof
9dcc8c872b resourceloader: Include exception log id in error message
This changes the current:

> Internal error.

To be:

> [89466ede] 2015-09-23 16:40: Fatal exception of type Less_Exception

This matches how exceptions are reported on HTML pages by MediaWiki
(via MWException::getHTML in OutputPage).

The IDs are okay to be public and exposed on HTML pages even when
$wgShowExceptionDetails is disabled.

Follows-up d478ffde10. Ref T110659.

Change-Id: I501eaa629161184ba89d44e53cdac20b39cb0903
2015-09-25 23:40:03 +00:00
Timo Tijhof
fc206806d8 HttpError: Convert line breaks in text message to <br>
Used by MediaWiki::tryNormaliseRedirect() for example with plain text
containing line breaks.

Change-Id: I5949046af4065c5536080212b96374466849b91a
2015-09-16 18:28:41 +00:00
jeroendedauw
8129cd9eca Make MWExceptionHandler work with PHP7's exception changes
See https://wiki.php.net/rfc/throwable-interface

Bug: T107933
Change-Id: I703c8710c8adeff14c1cbaab89f5688f6cb96c24
2015-09-16 11:22:38 +00:00
Bryan Davis
ba1835f159 Enhance debug log output for stacktraces
Make MediaWiki\Logger\LegacyLogger and
MediaWiki\Logger\Monolog\LineFormatter better at outputting stacktrace
information and provide support for 'exception' data in the logging
context that is a structured array in addition to the default Exception
object support. This works with MWExceptionHandler::handleFatalError
generated data that is provided by an HHVM interpreter and cannot be
delivered as an Exception class.

With this patch, a good value for LineFormatter's format would be:
"%datetime% %extra.host% %extra.wiki% %channel% %level_name%: %message%
%context% %exception%\n"

Bug: T89169
Bug: T107440
Change-Id: Ida01ed51c573e1654346e716723e543a1be63090
2015-09-08 07:03:52 +00:00
Bryan Davis
a6016137e8 Enhance stacktrace logging for fatals
Split fatal error handling out of MWExceptionHandler::handleError() and
move to MWExceptionHandler::handleFatalError() which has been updated to
work as a dual purpose error handler and shutdown function. Under HHVM
it will be called as an error handler and receive a stacktrace via an
undocumented extension of the error handler callback data. Under PHP5 it
will be called as a shutdown handler and attempt to gather data via
error_get_last().

Also update the error handler installed by Hooks::run() to delegate to
MWExceptionHandler::handleError() for most errors. This will allow us to
properly handle errors raised from within hooks.

Bug: T89169
Change-Id: I0f1c66f203b91fff9069520169ecc4a3b55c43d0
2015-09-08 07:03:36 +00:00
Ricordisamoa
df9ebe6f99 Fix some space-related phpcs warnings in includes/
Change-Id: I7cf7206696a5e77bc02e3630d1d88d4c176ea844
2015-08-15 08:56:03 +00:00
Ricordisamoa
7838fe300a Remove unused globals
* $wgLogExceptionBacktrace from MWExceptionHandler
  unused since 77a397125f

* $wgPasswordPolicy from WebInstallerName
  unused since 6a69a4eb73

Change-Id: Ibaac1bad05f4326a2602958a93d4d46135bdca63
2015-08-15 08:36:05 +00:00
Bryan Davis
77a397125f Convert MWExceptionHandler to use structured logging
Replace wfDebugLog() calls in MWExceptionHandler with direct use of
LoggerFactory and LoggerInterface. Logged exceptions are added to the
log message context.

LegacyLogger is also updated to append stack traces to any log event
when $wgLogExceptionBacktrace is true and the PSR-3 recommendation of
passing the exception as an 'exception' context item.

Handling of context data in LegacyLogger is expanded to support arrays,
exceptions and common object types.

Bug: T88649
Change-Id: I71499d895582bdea033a2516c902e23e38084080
2015-07-15 21:03:46 -05:00
Kunal Mehta
f6e5079a69 Use mediawiki/at-ease library for suppressing warnings
wfSuppressWarnings() and wfRestoreWarnings() were split out into a
separate library. All usages in core were replaced with the new
functions, and the wf* global functions are marked as deprecated.

Additionally, some uses of @ were replaced due to composer's autoloader
being loaded even earlier.

Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to
mediawiki/vendor.

Bug: T100923
Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4
2015-06-11 18:49:29 +00:00
Timo Tijhof
70429dc8a2 Use HttpStatus::header instead of manually crafting header()
Also:
* Update wfHttpError() to use uppercase DOCTYPE, to match other code
  such as Html.php, wfThumbError(), HttpError.php, etc.

Change-Id: I4027e7fe1a138b03f78797b6d1bfe7bd1064d360
2015-06-04 02:27:35 +00:00
Gergő Tisza
d0d539e6ba Add a hook for reporting exceptions
Bug: T100141
Change-Id: I893f8b93e09f9ef70beef46922d304fdb3600b78
2015-06-03 05:09:41 +00:00
Timo Tijhof
d01b5bc95c exception: Use standard message for HTTP status 500
This is the only case in the MediaWiki code base where a custom
message is used. Supporting in the standard HttpStatus library
would require a $customMessage parameter which seems unnecessary.

Additional information should be communicated using additional
HTTP response headers or inside the body content.

Besides, in current PHP versions and in Apache 2.4, the message is
already being ignored and replaced with the standard message (see T100984).

Bug: T100984
Change-Id: I11b58a2f3ce22568479d36027d15e5c6f428ff15
2015-06-03 02:49:44 +00:00
aude
acfff1bff1 Add tests for HttpError
Still missing tests for HttpError::report, but would
have caught the issue that Ie216d19 fixed.

Change-Id: Ic35d70af52c3a2d2a25fc3b9952383198db31fb1
2015-06-01 20:42:21 +02:00
Marius Hoch
e826f36d12 Fix undefined variable $header in HttpError
Change-Id: Ie216d1959f2ea903fdbc124b718b4988e08229ae
Follows-up: I8b61d7e9ea4101e3a9ef5f9a59a97db45aeef68c
2015-06-01 19:40:41 +02:00
Timo Tijhof
0e84138017 HttpError: Consistently escape document title
Wasn't actually a vulnerability because HttpStatus::getMessage
can only return one of a fixed set of values which are all plain
text without any special characters. However the return value
there is meant to plain text and not html, so just like
Html::element and other interfaces, things should be consitently
escaped.

Also renamed variables for clarity.

Change-Id: I8b61d7e9ea4101e3a9ef5f9a59a97db45aeef68c
2015-06-01 14:58:19 +01:00
Brad Jorsch
132f1b1ea8 MalformedTitleException should call parent::__construct
There's no reason for $ex->getMessage() to return nothing. Do like
ErrorPageError does and get the default English message for the parent.

Also move the appending of $titleText to $errorMessageParameters into
MalformedTitleException itself and document it, so every catcher of the
exception doesn't need to know about this, and fix the check so it
doesn't screw up for title "0".

Change-Id: I43d988602b847b67a3cf0aa84e271a0b5bd9adae
2015-05-06 16:11:51 -04:00
Bartosz Dziewoński
708918ccbf Provide detailed information about invalid titles
includes/Title.php
* The private method Title::secureAndSplit() now throws a
  MalformedTitleException instead of returning false on invalid
  titles.
* Added Title::newFromTextThrow(), which behaves exactly like
  Title::newFromText() but throws MalformedTitleException instead of
  returning null on invalid titles.

includes/title/MediaWikiTitleCodec.php
* Provide more information with the thrown MalformedTitleExceptions.

includes/MediaWiki.php
* Use the new Title::newFromTextThrow() to get detailed error
  information, display it.

Change-Id: I4da8ecb457a77473e32d745ba48ab8505b35e45f
2015-04-30 23:50:07 +02:00
jenkins-bot
c9a815608f Merge "Some cleanups to MWExceptionHandler::handleException" 2015-04-06 20:44:54 +00:00
Bryan Davis
1195e11a8a Move MWLogger classes to MediaWiki\Logger namespace
Move the MWLogger PSR-3 logging related classes into the
MediaWiki\Logger namespace. Create shim classes to ease migration of
existing MWLoggerFactory usage to the namespaced classes.

Bug: T93406
Change-Id: I359cc81fbd2dcf8937742311dcc7d3dee08747b0
2015-04-03 11:32:24 -07:00
Timo Tijhof
532337e6ff Use "string|false" as @return instead of "string|bool" where appropiate
This makes sure static analyzers don't warn for supposedly unsafe
code accessing variables as strings when they could be boolean after
having only checked against false.

https://github.com/scrutinizer-ci/php-analyzer/issues/605

Change-Id: Idb676de7587f1eccb46c12de0131bea4489a0785
2015-04-01 09:48:30 +01:00
Aaron Schulz
50b7a49e66 Some cleanups to MWExceptionHandler::handleException
* Do not bother with profiling data, which is just another
  thing that can go wrong.
* Catch DB rollback errors to avoid getting stuck in
  report() loops during network partitions.

Change-Id: I92293b2261c48cf49625ea14a51987e5619ab8d4
2015-03-31 16:29:20 -07:00
Kunal Mehta
039e19f1c7 exception: Log fatal errors to a new 'fatal' log group
'error' is currently disabled in Wikimedia production, but we still need
to log stack traces for fatals.

Bug: T89169
Change-Id: Id0255651f228037152b87022f5eb696c1050b9ec
2015-03-31 04:40:14 +00:00
Marius Hoch
ff707bba77 Don't log HttpErrors in the exception log, use MWLogger
Bug: T85795
Change-Id: Ic36f657a6447dd99c78681536e5dfb066d97b409
2015-03-18 15:45:29 +00:00
Kunal Mehta
90f3ca0439 Fix phpcs errors and warnings in includes/exception
Change-Id: I979c94a41df67426e621a734d5a86d55b890d269
2015-03-14 19:36:51 -07:00
Federico Leva
9f7d683fe5 Add i18n for the infamous "Fatal exception of type MWException" errorbox
These errors usually need to be reported, so it's better for the user
to understand them as much as possible.

Bug: T40095
Change-Id: Ibd2f984b66acb9150400126f21acf7cc5fc85acd
2015-02-23 21:33:24 +00:00
Timo Tijhof
b5efa72afd exception: Hide suppressed errors in 'error' log, flag in 'error-json'
Follows-up 399ba2f.

Bug: T75619
Bug: T45086
Change-Id: I1f312660c058a3940bf1e9425f86cfd531121ba3
2015-01-13 00:21:11 +00:00
jenkins-bot
8cddc9269b Merge "Tweaked the message for non-MW exceptions" 2015-01-13 00:20:14 +00:00
Aaron Schulz
6921770414 Updated some try-catch statements: MWException -> Exception
Change-Id: I76601a86e30f4984e3b1a8c8ec5ef5a0f652433a
2015-01-09 17:20:22 -08:00
Aaron Schulz
608ef0c625 Tweaked the message for non-MW exceptions
Change-Id: I46dae88d66b65aa596743bdbdbdee270d53ae803
2015-01-09 15:00:11 -08:00
Timo Tijhof
f86b759ac1 exception: Implement error-json log
Follows-up 399ba2f.

Bug: T75619
Bug: T45086
Change-Id: Ia7ba355d5925a6268ffa321ffc13cc6906b487f8
2015-01-05 20:17:00 +00:00
Bryan Davis
3ae8eb2416 Register a shutdown function to log fatal errors
MWExceptionHandler::handleFatalError() is installed as a shutdown
function to inspect `error_get_last()` output and log the error via
MWExceptionHandler::logError(). The error is examined to determine if it
is a missing class error so that a descriptive log message can be
provided instructing the server administrator on 3rd party library
installation methods.

Bug: T74777
Change-Id: I04748626487022c51050ffa7846236947a082d68
2014-12-09 23:27:40 +00:00
Timo Tijhof
164ac414fa exception: Prefix error type in front of error message
Follows-up 399ba2fecf which didn't include any translation of the error
type in the logged message (e.g. "PHP Notice" or "PHP Warning").

Before
 Error from line 2130 of mediawiki/includes/OutputPage.php: Undefined variable: bar
 Error from line 2130 of mediawiki/includes/OutputPage.php: strpos() expects at le..

After
 Error from line 2130 of mediawiki/includes/OutputPage.php: PHP Notice: Undefined variable: bar
 Error from line 2130 of mediawiki/includes/OutputPage.php: PHP Warning: strpos() expects at le..

Based on the log formatter in php
 https://github.com/php/php-src/blob/0f5858e3a328/main/main.c#L1086-L1119

Change-Id: I52f98e52caa64955050ed73e1acbc78b1116a9fd
2014-11-24 18:23:09 +00:00
Timo Tijhof
399ba2fecf MWException: Log stack traces for php errors (not exceptions)
* Remove use of 'error' where it's redundant.
* Remove call to logException from responsibility of MWException.
  Call from exception handler instead.

Change-Id: I8764cf5df87b226813c9b9cf99f9b4f3fa4b7c92
2014-11-16 14:37:15 +01:00
Florianschmidtwelzow
1c0e593bc2 UserLogin: Allow extensions to add valid error messages
Add hook LoginFormValidErrorMessages to allow extensions, to add own valid
error messages to redirect to the login form.

Bug: 71769
Change-Id: I9e996a88e3972f09946726060916a21124de049c
2014-11-03 21:28:18 +01:00
aude
3e87e7edf5 Log non-MediaWiki exceptions for requests via main entry point
Previously, non-MediaWiki exceptions were logged only for api requests,
job runner, resource loader, etc. but not for general requests
such as page views.

Bug: 61914
Change-Id: Id4de5cac0b9996a98cdaf5e73655d49fa55ea8c3
2014-10-06 23:57:49 +00:00
aude
ec6ee905b5 Move TimestampException to exception directory
Change-Id: Id3829cbd155636839a272dc7e28e45bee7b87e8b
2014-10-06 11:03:54 +02:00
Anomie
8f0ed5f5a7 Revert "Replace wfMsgReplaceArgs by RawMessage"
This was merged too quickly, has several issues.

This reverts commit 6abefb274f.

Change-Id: Ibf3e464fa9eb534d599274dd9262a30d5a6a6948
2014-09-29 17:41:56 +00:00
umherirrender
6abefb274f Replace wfMsgReplaceArgs by RawMessage
The replace of $n params can also be done using the Message class. In
case there are no message keys, the RawMessage class is used.

Deprecated wfMsgReplaceArgs, but added no warning, because it is used in
some extensions and from deprecated functions

Change-Id: I62091b09e4490e59ed7258566e0ddf2f8ee799d2
2014-09-29 19:23:19 +02:00
umherirrender
3b2b6a2773 Add missing @param to function docs
Change-Id: I47fa96a976f55a1a93cb75397285edb8c7f4cd8a
2014-08-14 20:22:52 +02:00
Tyler Romeo
d0439af89f Make UserNotLoggedIn redirect to login page
For pages like Special:Watchlist that throw
a UserNotLoggedIn exception when the user is
anonymous, this patch makes the page redirect
to the login page automatically.

This is instead
of the current behavior of showing a link to
the login page that the user must click.

(Also, Special:Userlogin has existing functionality
that will redirect the user back once they are
logged in.)

Bug: 15484
Change-Id: Idd9325374cb5dc13c4c057f45f88a33bdff523a9
2014-08-07 13:38:16 -04:00
umherirrender
b883e8c7c0 Cleanup some docs (includes/[e-l])
- Swap "$variable type" to "type $variable"
- Added missing types
- Fixed spacing inside docs
- Makes beginning of @param/@return/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: I41a84e8e1dec39170aa655250325ffc485eaeaef
2014-07-24 19:43:03 +02:00
Bartosz Dziewoński
57fd33ff74 Revert "Make UserNotLoggedIn redirect to login page"
Lots of small issues that could be very annoying:

* Usability regression: the user is not informed *why* they were
  redirected to the login screen. Not even a generic "You must log in
  to complete this action".
* When testing this on my watchlist, after logging in I am now redirected
  to http://localhost/wiki/index.php?title=Watchlist&title=Special%3AWatchlist
  (the title is repeated twice and one of them is incorrect). This
  worked correctly before.
* SpecialPage::requireLogin() needs documentation and code updates.
* A whole ton of messages used in these prompts is now unused.
* Probably needs release notes.

I don't have the time to fix up myself right now, and a WMF
branch cut is looming. Let's just try this again later.

This reverts commit e0af129cbd.

Bug: 15484
Change-Id: I728e477cf6e10b90846ee0b2d9e5087bc3a0af3e
2014-07-15 23:13:17 +00:00
Tyler Romeo
e0af129cbd
Make UserNotLoggedIn redirect to login page
For pages like Special:Watchlist that throw
a UserNotLoggedIn exception when the user is
anonymous, this patch makes the page redirect
to the login page automatically.

This is instead
of the current behavior of showing a link to
the login page that the user must click.

(Also, Special:Userlogin has existing functionality
that will redirect the user back once they are
logged in.)

Bug: 15484
Change-Id: Ic7e1d5a8984e1b42c8f2ebceff094106a3ed1efa
2014-07-15 14:48:09 -04:00
Chad Horohoe
fefc89448d MWException: Remove deprecated methods
No callers in core or extensions.

Change-Id: I3e2dc615bcd23838cf096625a767a7cf50fea140
2014-05-14 22:01:37 +00:00