This patch adds a metric data service object to the IContextSource interface,
with full support for StatsD meters, gauges, counters and timing metrics, via
the liuggio/statsd-php-client, which this patch also introduces.
Usage example:
$stats = $context->getStats();
$stats->increment( 'resourceloader.cache.hits' );
$stats->timing( 'resourceloader.cache.rtt', $rtt );
The metrics are flushed to a StatsD server, which may be specified via the
'StatsdServer' configuration key. If no such configuration key exists, the
metrics are discarded.
The StatsD client supplants MediaWiki's StatCounter class. wfIncrStats()
will continue to work, but it will delegate to the StatsD data object.
Change-Id: Ie10db1c154d225971398e189737de7c560bf0f90
It's fairly common that the API doesn't need to load the user
preferences, except to implement the unfortunate default uselang=user.
So let's move the handling of uselang=user to
RequestContext::getLanguage(), and have the API just assume that its
parent context will eventually fall back to that for uselang=user.
Bug: T85635
Change-Id: I947348d87b31808d331055dac6feb0cc2e1dd15d
Calling getTitle() right away can lead to reading from
$wgTitle, so check with hasTitle() first.
This avoids a globaltitlefail in ApiEditPage.
Change-Id: I749cc33dd4f1fd6bc7598be34f37e591d822c3f2
Currently stuff like:
MessageCache::parse called by Message::toString/Message::parseText/MessageCache::parse with no title set.
is showing up in the logs, and is totally useless.
Change-Id: I0ac3ca906c5a67e19974e3434d0e929e6b27fbb2
* Jobs can be run via HTTP runners rather than just CLI ones.
The old check breaks jobs run on HHVM fcgi runners for example.
* Always check the validity of the IP for sanity.
Change-Id: I1d03c2ab6628b2d124bc7b9f6936788dea22e3e4
MediaWiki::getTitle is checking, if a title is set on the context, but
that needs to call RequestContext::getTitle, which gives a warning, when
no title is set:
RequestContext::getTitle called by MediaWiki::getTitle with no title
set.
Adding a RequestContext::hasTitle function to check the title and avoid
the warning. Was added in I72c5c3fb75c9ceff02390c91b3735f2da90845de.
Change-Id: I4d8f8ef799cd91f0d2affe881019583ac77a31b7
Have to pass a context to the constructor to acutally use it for
settings.
Also adds a RequestContext::getMainAndWarn to get a default warning,
when using the main request, but it would be better to pass one.
Change-Id: I1628a1790c45d44aa4239701486b8b1b7c59a0e6
Modeled similar to ConfigFactory, this lets skins
register themselves via a callback, allowing for
proper dependency injection.
Loading via $wgValidSkinNames is still supported,
but considered "legacy", not deprecated though.
Skin::newFromKey is now deprecated (and had only
one caller in an extension, which I'll update
afterwards).
Change-Id: I1960483f87c2ef55c994545239b728fa376f17f4
- 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: I7b65fe04db431342cc58b469dc48f41a50c4e891
User::newFromId() will never return false. We have to actually
load from the database to see whether the user still exists.
Change-Id: Id9329635717e6a4f1f34d0b2b665bb790685d2fa
Its state can change when people do something with objects it returns or
when they alter globals like $wgRequest. By resetting this singleton, we
ensure that no such change will propagate outside of a test.
Change-Id: I7e8598716d810a09c17f80a05deecab617b62346
To avoid misleading errors in case of failed initialization,
flags used to protected against recursion need to be reset
in case of an exception being thrown.
Change-Id: Ifbc1db4b827012177fcfd271981179ebb2329b52
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Change-Id: I8c9f30128b46086064326708a4878228ba459447
Allows configuration options to be fetched from context.
Only one implementation, GlobalConfig, is provided, which
simply returns $GLOBALS[$name]. There can be more classes
in the future, possibly a database-based one. For convinience
the "wg" prefix is automatically added.
Ironically, this adds the $wgConfigClass global variable
which is used to determine which implementation of Config
to use by default.
The ContextSource getConfig and setConfig methods were introduced
in I23194d1ba (1.23), but have no uses in Gerrit, so they can safely
be re-purposed.
Change-Id: I13baec0b6d4ea7badf20b9c5f9b40846348838e4