Commit graph

99 commits

Author SHA1 Message Date
Vivek Ghaisas
9f5b6f5aeb Fix whitespace issues around parentheses
Fix issues found by MediaWiki.WhiteSpace.SpaceyParenthesis sniff.

Bug: T102617
Change-Id: Iec7f71e64081659fba373ec20d9d2006306a98f4
2015-06-16 22:14:02 +03: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
Bryan Davis
3354b3e0d0 Remove MWLogger and non-namespaced MWLogger* shim classes
These classes were introduced and deprecated during the 1.25 development
cycle.

Bug: 100098
Change-Id: I3a479d194bdf5137f99a7e27fc71c7b438b1e136
2015-05-23 22:28:12 +02:00
Timo Tijhof
b391983f14 Make $wgDBerrorLogTZ actually default to $wgLocaltimezone
Change-Id: I6ef84bf6b91a6783d1ff1c3dd0c4016ebf076367
2015-04-29 04:06:43 +00:00
Timo Tijhof
9838eeb6f2 resourceloader: Add ResourceLoader::makeInlineScript utility and use it
Plucked from the e86e5f846 which got reverted.

Change-Id: I4bba3f3c31c5181867378ae174537429b49a50df
2015-04-20 19:45:27 +00:00
jenkins-bot
4fa0240228 Merge "API: Overhaul ApiResult, make format=xml not throw, and add json formatversion" 2015-04-16 01:05:51 +00:00
Brad Jorsch
1c57794e37 API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.

ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.

So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
  arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
  Formatters are responsible for stripping it if necessary. "raw mode"
  is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
  question, and so on.
* New class for formatting warnings and errors using i18n messages, and
  support for multiple errors and a more machine-readable format for
  warnings. For the moment, though, the actual output will not be changing
  yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
  between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
  modules currently returning booleans will need to use
  ApiResult::META_BC_BOOLS to preserve their current output.

Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.

Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2015-04-10 16:57:15 -04:00
Kunal Mehta
2ddcffa0f2 debug: Add missing "use DateTimeZone" in LegacyLogger.php
Seen in fatal.log in production: ErrorException from line 264 of
/srv/mediawiki/php-1.26wmf1/includes/exception/MWExceptionHandler.php:
Fatal Error: Class undefined: MediaWiki\Logger\DateTimeZone

Bug: T95727
Change-Id: Icb303314caaef47ac767fbf593e92d09e818f147
2015-04-10 10:57:01 -07:00
Bryan Davis
19c8f103c6 phpdoc: make references to \MediaWiki\Logger\Spi fully qualified
Change-Id: I4a5dbc3894ea175053e1238e7fc5de4c4cf085ca
2015-04-10 09:58:43 -06:00
Bryan Davis
6bf78b3274 Separate Monolog shims from other logging shims
Move the non-namespaced classes referencing external Monolog classes to
an isolated PHP source file so that they aren't brought into scope by
the need to load another shim class.

Bug: T95220
Change-Id: I8270b8d5cd25db5a0f84fa94f59a6555052ae1ae
2015-04-06 20:28:13 +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
jenkins-bot
b594c133f3 Merge "Use wikimedia/utfnormal library, add backwards-compatability layer" 2015-03-31 00:51:16 +00:00
Bryan Davis
7ab9e6ed0c Remove MWLoggerMonologSamplingHandler
The Monolog\Handler\SamlingHandler class available since Monolog v1.12.0
is an upstreamed equivalent of MWLoggerMonologSamplingHandler.

Requires: I8790da95fd658234e35b2d846af35993ebcd80e9
Change-Id: I3841cbab95382a66098d90f5570fa0bf3521578a
2015-03-27 20:27:32 +00:00
jenkins-bot
7958fe5dc9 Merge "Update MWLoggerLegacyLogger phpdoc" 2015-03-27 17:06:36 +00:00
jenkins-bot
571d4c27c1 Merge "Allow MWLoggerMonologHandler to take prefix from channel" 2015-03-27 17:06:01 +00:00
Ori.livneh
2b6eb60ce5 Revert "Optimize order of styles and scripts"
The patch did not improve performance. I'd like to think that the increased
control over when inline scripts are executed makes the patch worthwhile
regardless, but that is post hoc justification and possibly a bit of personal
ego. Krinkle agrees that we may use some of the ideas in this patch in the
future but he thinks we're better off not heading down this path before we
have a better sense of where we're going, and I trust his judgment.

This reverts commit e86e5f8460.

Change-Id: I151f74a41dd664b5a0aa5cfd99fcc95e2686a1e6
2015-03-25 04:40:46 +00:00
Kunal Mehta
13975fe76a Use wikimedia/utfnormal library, add backwards-compatability layer
This drops support for the custom utf8 normal PHP extension in favor
of the intl extension.

Bug: T90825
Change-Id: Ifbaeb2ef684217cf6187ccc4fb4d303f89608300
2015-03-24 12:59:26 -07:00
Bryan Davis
99fb48e3aa Update MWLoggerLegacyLogger phpdoc
Add a missing @return declaration for MWLoggerLegacyLogger::interpolate

Change-Id: Ia7d35606d63a3da92b1e38284c611de1961a0c8e
2015-03-22 16:18:52 -06:00
Bryan Davis
f16f8fe9c5 Allow MWLoggerMonologHandler to take prefix from channel
Make MWLoggerMonologHandler replace a prefix of "{channel}" with the log
event channel when formatting an event for a udp2log stream. This allows
a simpler configuration for a typical Monolog configuration where
a separate file is desired for each logging channel that is emitted to
udp2log. One handler can be shared by multiple channels.

Change-Id: Ie2b24ba02b281b8d8cf2ad58d28874c710e1e2e5
2015-03-22 16:12:25 -06:00
Kunal Mehta
8911a8d0b7 Send messages logged via MWLoggerLegacyLogger::log() to the debug toolbar
Bug: T93145
Change-Id: Ia96525faf4ffcbd2b5beae9716d6be009f2b6074
2015-03-18 23:57:47 +00:00
Ori Livneh
e86e5f8460 Optimize order of styles and scripts
The current ordering of scripts and stylesheets in <head> causes all major
browsers to serialize and defer requests that could be performed in parallel.

The problem is that external stylesheets are loaded before inline scripts. As
Steven Souders explains, "all major browsers preserve the order of CSS and
JavaScript. The stylesheet has to be fully downloaded, parsed, and applied
before the inline script is executed. And the inline script must be executed
before the remaining resources can be downloaded. Therefore, resources that
follow a stylesheet and inline script are blocked from downloading."[1]

In other words: the browser could start loading body images, but it refuses to
do that until it has executed inline scripts in head. And it refuses to execute
those scripts until the external CSS is downloaded, parsed and applied. You can
see the effect of this in this image, showing the request waterfall for
[[en:Gothic Alphabet]]: [2]. Notice how no images were requested before the
browser had finished processing the three load.php requests at the top.

To fix this, we want to move the inline scripts above the external CSS. This is
a little bit tricky, because the inline scripts depend on mw.loader, which is
loaded via an external script. If we move the external script so that it too is
above the external stylesheet, we force the browser to serialize requests,
because the browser will not retrieve the external CSS until it has retrieved
and executed the external JS code. So what we want is to move the inline
scripts above the external stylesheet, but keep the external script (which the
inline scripts depend on) below the external stylesheet.

We can do this by wrapping the inline script code in a closure (which binds
'mw') and enqueuing the closure in a global array which will be processed by
the startup module at just the right time.

Net result: external CSS and JS is retrieved in parallel, retrieval of images
(and other external assets) is unblocked, but the order in which code is
evaluated remains the same.

[1]: <http://www.stevesouders.com/blog/2009/05/06/positioning-inline-scripts/>
[2]: <http://people.wikimedia.org/~ori/enwiki-waterfall.png> (excerpted from
 <http://www.webpagetest.org/result/150316_0C_7MB/1/details/>.

Change-Id: I98d383a6299ffbd10210431544a505338ca8643f
2015-03-17 03:10:49 +01:00
Bryan Davis
8382b5570e Update MWLoggerMonologHandler for Monolog 1.12.0
Monolog 1.12.0 "fixed" Handler::isHandling() so that instead of a full
log record it is only passed an array with the log event's level.
MWLoggerMonologHandler was relying on a full record to allow inspecting
the channel name and looking for a 'private' flag in the context
information.

Update MWLoggerMonologHandler to do legacy processing checks in
Handler::write() where the full log event is present for inspection.

Bug: T89313
Change-Id: Ia878c2cb6bff47d6b35ff38ba3b7ac2ea5556565
2015-02-13 18:12:30 -07:00
Bryan Davis
f058574fcd Add Monolog handler for syslog UDP transport
The stock Monolog\Handler\SyslogUdpHandler only works with a specifically
tailored Formatter class and it's output cannot be fed directly into
Logstash's syslog input. This handler implements RFC 3164 in a way that
can be used with any Formatter and parsed directly by Logstash.

Bug: T88870
Change-Id: Ib098d5cb8fe9643742360bf51b54fc0e27996c0f
2015-02-09 22:38:26 -07:00
Bryan Davis
d62f6391f8 Provide a backwards compatibility shim for MWLogger
MWLogger was renamed MWLoggerFactory and reduced to a static utility
class in Ie474676. Reintroduce an MWLogger that proxies the public
static methods of MWLoggerFactory to ease the transition of users who
have implemented $wgMWLoggerDefaultSpi configurations that reference
MWLogger.

As noted in the class, this is a temporary bandaid that should be ripped
off before 1.25 becomes an official release.

Change-Id: Iaccb78a510c60aab2ff20a9aa7c0869699657388
2015-01-22 22:11:08 +00:00
Bryan Davis
56b70b61af Replace MWLogger with MWLoggerFactory
Time wounds all heels. During the code review for the PSR-3 logging
introduction, several people asked me why we needed a wrapper
for Psr\Log\LoggerInterface if the point was to use the standard. At the
time I was convinced that it would be better to introduce the dependency
via a wrapper class so that we could use the wrapper to patch over any
deficiencies that we might find in the PSR-3 API. After going on to work
on a project to disentangle other MediaWiki components from internal
project dependencies I have suddenly and clearly seen the error of my
ways.

We still need a logger factory as PSR-3 does not specify
a standard mechanism for creating Psr\Log\LoggerInterface instances. My
solution is to convert MWLogger into MWLoggerFactory to retain a static
factory interface for creating PSR-3 loggers but remove the MWLogger
wrapper class itself in favor of direct exposure of
Psr\Log\LoggerInterface to the MediaWiki consumer classes.

Change-Id: Ie47467657dcf341991ada00827dca5e8eff95438
2015-01-22 22:10:49 +00:00
Kunal Mehta
4316c8c48b Implement support for a minimum log level in $wgDebugLogGroups
For some log groups, we only want to log them if they meet a certain
level of severity. An example of this is the current 'memcached-serious'
log group, which can be merged with the normal 'memcached' group
in the future, and report at a severity of ERROR.

This adds a 'level' parameter to the $wgDebugLogGroups, for example:
    $wgDebugLogGroups['memcached'] = array(
        'destination' => '/var/log/mw/memcached.log',
        'level' => \Psr\Log\LogLevel::ERROR,
    );

Bug: T85073
Change-Id: Ic53bc4c8e318ed188fe6f4e838e6789b3c3fd574
2014-12-31 18:16:17 +00:00
Reedy
e0a9aba3ba Add use statement for type used in MWLoggerMonologSamplingHandler::setFormatter()
Change-Id: I02629711eccfecdab77c5e6d80833806d48d07cf
2014-12-24 17:21:20 +00:00
Bryan Davis
1bad1d020f monolog: MWLoggerMonologSamplingHandler
Introduce the MWLoggerMonologSamplingHandler which can
be used to probabilistically sample the log event stream.

Bug: T85067
Change-Id: Icd14fc8c44ca9eef0f3f5cc4f1d1d8b68d517f07
2014-12-20 14:35:55 -07:00
jenkins-bot
d34a6ca677 Merge "Fix some stuttering in comments and documentation" 2014-12-17 22:28:27 +00:00
Ricordisamoa
12dec5d85d Fix some stuttering in comments and documentation
Change-Id: I9c0088b9aab37335203cad45a1d6fa8ac3f43321
2014-12-17 19:44:10 +00:00
Bryan Davis
6aa3c4fe84 Logging related comment updates
* Pretty up some logging related comments.
* Send wfDebugLog messages to logger at info level

Change-Id: I97b8629095e8d6168dbeb791dfb5e7753d281cbe
2014-12-16 17:12:23 -07:00
Bryan Davis
dad7abd9ce Create a generic UDP transport class
Code moved from MWLoggerLegacyLogger::emit(), which was formerly
in wfErrorLog().

Bug: T74572
Bug: T78599
Change-Id: I9e0e63d41bed6ccb468f3a9f1d52f156acc355a8
2014-12-15 15:06:43 -07:00
Bryan Davis
45cf5b1803 Do not require that a Monolog handler has a formatter
Not all handlers require a formatter.

Change-Id: Ifb31aa278d4e90b7fa3a2b7bf3b20173b8345afd
2014-12-12 13:29:35 -07:00
Timo Tijhof
ff6513f28b Remove '@section LICENSE'
This was used in 2 special classes, the logger classes and spread
to a few other random classes.

Afaik this has no meaning. Is for something we don't use, and
goes against the meaning of '@section' in Doxygen, which we do
use.

In Doxygen output, all LICENSE references became links to
ProfilerXhprof (the one Doxygen encoutered first).

Bug: T72328
Change-Id: Icc7c443245c70bc0f549bee7d105eef5691c864d
2014-11-26 02:20:55 +00:00
Bryan Davis
f210ce84cd Allow limiting Monolog output using legacy settings
Add $useLegacyFilter option to MWLoggerMonologHandler constructor that
will use MWLoggerLegacyLogger::shouldEmit to decide if a given log
message should be emitted.

Bug: T845
Change-Id: If311308faad35348fdc7e85155a1bc16bbf75c85
2014-11-20 23:30:42 -07:00
Bryan Davis
0223290e84 Add Monolog formatter that mimics legacy log output
Having a log formatter for the Monolog stack that mimics the legacy wf*
logging function output will ease the transition for users wishing to
use Monolog who have tooling that expects the legacy log formats.

Bug: T845
Change-Id: I06295ccc4b068c61d7971024213366004b69c03d
2014-11-20 17:45:20 -07:00
Bryan Davis
2792ea9783 Add logging context to database logs
* Add optional $context parameter to wfDebug, wfDebugLog, wfLogDBError
  and wfErrorLog that will be passed to MWLogger.
* Add support for PSR-3 style log message parameter interpolation in
  MWLoggerLegacyLogger.
* Add context information to wfLogDBError calls made from DatabaseBase,
  DatabaseMysqlBase and LoadBalancer instances.
* Deprecate wfDebugTimer() which now appears to be unused.

Change-Id: Ic90d593d00a2b0b5b80ed205908cbe624042603c
2014-11-19 17:59:55 +00:00
Chad Horohoe
9144673b5c Remove profiler support from debugging toolbar
It never worked and creates extra dependencies on the profiler

Change-Id: I584c9e94d144baf48a654e23dd9f47690d94f13b
2014-11-17 18:27:46 +00:00
jenkins-bot
19c2a08267 Merge "Use MWLogger logging for wfLogProfilingData" 2014-11-04 21:17:19 +00:00
Bryan Davis
ed6af3296e die() with explanation when \Psr\Log\LoggerInterface is missing
Add an explicit check for the \Psr\Log\LoggerInterface in the source
file that declares MWLogger and `die()` with an explanation and links to
documentation if the interface is not present.

MediaWiki requires the PSR-3 logging library to be present in the PHP
search path or via an autoloader after I1e5596d. The composer.json for
MediaWiki requires the necessary library, but usage of Composer with
MediaWiki is not wide spread yet and users may be caught unaware by the
new dependency. The default log messages generated when PHP fails to
load the required interfaces and classes are not instructive as to how
to correct the problem.

Bug: 72777
Change-Id: I3db489702ed5d7973c6b5963eac22f181ca28c72
2014-11-03 09:16:35 -07:00
jenkins-bot
cc3b1d1e2c Merge "Fixed spacing" 2014-10-30 20:09:54 +00:00
Kunal Mehta
0e17070d40 Require PHP >= 5.3.3
Bug: T839
Change-Id: Iac827ef8505ff0653a40e45d759b0f79619351ee
2014-10-30 10:10:52 -07:00
umherirrender
2a7c95acda Fixed spacing
- Changed spaces to tabs for indentation
- space after 'function'/'if'
- Added/Removed space after parenthesis/brackets/end of line
- Removed space after cast

Change-Id: I0e8e6a19b84b5e1308b632a0266cb78f688494ee
2014-10-30 17:50:19 +01:00
Bryan Davis
3328bd9961 Use MWLogger logging for wfLogProfilingData
Output structured profiling report data from wfLogProfilingData using
MWLogger.

Requires Ie667944, I5c82299, and I1e5596d.

Change-Id: Iae11e1e4fe970ada74136f0e969dc624c586ce17
2014-10-29 23:04:09 +00:00
Bryan Davis
28a7ce420b Use MWLogger logging for legacy logging methods
Send wfDebug, wfDebugLog, wfLogDBError and wfLogDBError log messages to
the new MWLogger PSR-3 logger subsystem. Compatibility with the historic
logging operations of wfLogDBError are provided by MWLoggerLegacyLogger
and the MWLoggerLegacySpi logger factory.

Requires the MWLogger system introduced in I5c82299 and the Composer
managed libraries from Ie667944.

Change-Id: I1e5596d590144fbfdfd5f18bc42cf1ef0dbcac12
2014-10-29 11:55:08 -07:00
Southparkfan
19d294e1bd Fix spelling mistake: s/databses/database
Change-Id: Id532b3724792eff5849813888533c251b99edc82
2014-10-29 13:12:45 -04:00
Bryan Davis
51b37035b3 Make $wgMWLoggerDefaultSpi more expressive
Allow $wgMWLoggerDefaultSpi to specify a more expressive object creation
by introducing a new ObjectFactory class which can process an array of
instructions to call either an object constructor or a factory method
with an array of arguments. This allows removal of the
$wgMWLoggerMonologSpiConfig global variable in favor of configuration
using $wgMWLoggerDefaultSpi.

New classes introduced:
; ObjectFactory
: Construct objects from configuration instructions.

Change-Id: If56cce5dcb1ad5712e238d6e2dab809a351f79be
2014-10-25 16:00:06 -06:00
Bryan Davis
9b35801650 Add a PSR-3 based logging interface
The MWLogger class is actually a thin wrapper around any PSR-3
LoggerInterface implementation. Named MWLogger instances can be obtained
from the MWLogger::getInstance() static method. MWLogger expects a class
implementing the MWLoggerSpi interface to act as a factory for new
MWLogger instances. A concrete MWLoggerSpi implementation using the
Monolog library is also provided.

New classes introduced:
; MWLogger
: PSR-3 compatible logger that wraps any \Psr\Log\LoggerInterface
  implementation
; MWLoggerSpi
: Service provider interface for MWLogger factories
; MWLoggerNullSpi
: MWLoggerSpi for creating instances that discard all log events
; MWLoggerMonologSpi
: MWLoggerSpi for creating instances backed by the monolog logging library
; MWLoggerMonologHandler
: Monolog handler that replicates the udp2log and file logging
  functionality of wfErrorLog()
; MWLoggerMonologProcessor
: Monolog log processer that adds host:wfHostname() and wiki:wfWikiID()
  to all records

New globals introduced:
; $wgMWLoggerDefaultSpi
: Default service provider interface to use with MWLogger
; $wgMWLoggerMonologSpiConfig
: Configuration for MWLoggerMonologSpi describing how to configure the
  Monolog logger instances.

This change relies on the Composer managed Psr\Log and Monolog libraries
introduced in Ie667944.

Change-Id: I5c822995a181a38c844f4a13cb172297827e0031
2014-10-14 00:20:32 +00:00
Shahyar
fcd3b60903 Fix malformed UTF-8 going to query profiler
Bug: 69926
Change-Id: I1c2e3f22104792fbc59491b1c6a17f2a6a0dd0b6
2014-08-28 17:10:45 -07:00
jenkins-bot
914e7e2b5d Merge "Indicate the actual version of HHVM in use" 2014-08-27 22:42:12 +00:00