Commit graph

82 commits

Author SHA1 Message Date
Amir E. Aharoni
c6f066b88c Make long lines shorter to pass phpcs in 6 files
Bug: T102614
Change-Id: I3159c33ddd16bded94a70f363258a294f407fc58
2015-09-26 17:07:06 +00:00
Aaron Schulz
bd963865b6 Fixed some RequestContext IDEA errors with msg() callers
Change-Id: I2a382ee8498eafd9fe045550dd9c1f61a8933926
2015-08-25 04:35:34 +00:00
Kunal Mehta
f318d7a04b Add base interface for setters in RequestContext and DerivativeContext
Change-Id: I819633ca5344f73a196623569bb58fd8372d6779
2015-08-03 11:55:41 +00:00
Aaron Schulz
52ffe630f4 importScopedSession() comment updates
Change-Id: I9c545a2c255d2af0826499754555b2e0d95159fb
2015-07-09 14:32:04 -07:00
jenkins-bot
a573c9bd65 Merge "Declare and document $wgStatsdServer and $wgStatsdMetricPrefix" 2015-07-02 08:12:47 +00:00
Timo Tijhof
4ef96ff1f2 Declare and document $wgStatsdServer and $wgStatsdMetricPrefix
Follows-up 87dfc20.

Change-Id: Ie1b799a8f2a73b974ba8c930cfabc00e377d6eee
2015-07-02 08:03:21 +00:00
Ori Livneh
be250544ea Ensure DerivativeContext has a $stats property
Should have been a part of Ie10db1c15 but wasn't.

Change-Id: I4552390e1476766ae2d0946df3836a8a14182b34
2015-07-02 00:41:09 +00:00
umherirrender
70f3afd548 Remove unneeded empty lines at begin of if/else/foreach body
An if body must not begin with an empty line

Change-Id: I62b058be337fcc85a120fcd3dadce564db59a271
2015-06-19 20:05:45 +02:00
Matthew Flaschen
ee8ccd1b54 Document IContextSource->msg
Change-Id: I4cc922c61f77bbb7cd4ece94f28d927c4753c24e
2015-04-25 00:09:51 -04:00
Aaron Schulz
353659085c Mention metrics in IContextSource docs
Change-Id: I9b654a12578758471978ffd1e1ae20476aeeaa0d
2015-03-11 19:15:33 +00:00
Ori Livneh
87dfc20b1e Add StatsD metric logging
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
2015-03-09 16:57:14 -07:00
Aaron Schulz
0d84b20a7c Added clarifying comments to IContextSource
* Also removed some duplicated comments

Change-Id: I2c967d0f3219f3533378ecd5f9fccc40c8f9b219
2015-03-07 13:39:07 -08:00
Aaron Schulz
f6ffc47b4d Clarified RequestContext doc comment
Change-Id: Ibb2a30634b192f4bc77e0b6b1afebc65b2ed3ec9
2015-03-02 21:38:45 +00:00
Aaron Schulz
4ff8136807 Removed remaining profile calls
Change-Id: I31c81c78715048004fc8fca0f27d09c1fa71c118
2015-01-08 02:49:33 -08:00
Brad Jorsch
87070fc674 API: Avoid unstubbing User for language pref when not needed
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
2015-01-05 11:59:48 -05:00
Reedy
4d9143c7f5 Add lots of @throws
Change-Id: I09d0c13070f966fcf23d2638d8fc1328279a5995
2014-12-24 13:49:20 +00:00
Kunal Mehta
0a7815967b Check hasTitle() in RequestContext::setWikiPage()
Calling getTitle() right away can lead to reading from
$wgTitle, so check with hasTitle() first.

This avoids a globaltitlefail in ApiEditPage.

Change-Id: I749cc33dd4f1fd6bc7598be34f37e591d822c3f2
2014-12-12 11:41:22 -08:00
Kunal Mehta
18d952dbcb Add more context to globaltitlefail logs
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
2014-12-12 11:04:33 -08:00
Aaron Schulz
e369f66d00 Replace wfRunHooks calls with direct Hooks::run calls
* This avoids the overhead of an extra function call

Change-Id: I8ee996f237fd111873ab51965bded3d91e61e4dd
2014-12-10 12:26:59 -08:00
Chad Horohoe
95e6efc4d4 Improved/additional logging for $wgTitle abuses
Change-Id: I6599aa8abe30c1888ab5df023a0d4bf346315400
2014-11-10 11:04:43 -08:00
Aaron Schulz
f9ee99b2fa Loosened the CLI restriction in RequestContext::importScopedSession()
* 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
2014-10-01 23:05:23 +00:00
umherirrender
010cdb4360 Avoid [GlobalTitleFail] spam
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
2014-09-26 19:58:02 +02:00
Alexandre Emsenhuber
09149f2ea4 Add missing space to log message
Follow-up I72c5c3fb75 (6fc2e603).

Change-Id: I9375da8542b3c2fb33cf0b692ab38722445081bc
2014-09-23 12:18:57 +02:00
Chad Horohoe
6fc2e60319 Begin logging RequestContexts relying on global title
Change-Id: I72c5c3fb75c9ceff02390c91b3735f2da90845de
2014-09-22 15:25:19 -07:00
umherirrender
b0cfcd0fcb Add missing @return and @param to doc blocks
Change-Id: I9d99ba1968ed8f97624d957754c8847dfe1b41da
2014-08-27 21:57:45 +02:00
Bartosz Dziewoński
9e5443abc3 No space within the ?: operator
This style is a lot more common in our code.

Change-Id: I7f2fb3716c24c4a95a4c6c4a732b0226c315f242
2014-08-25 17:40:51 +02:00
jenkins-bot
d98adbae49 Merge "Use config instead of globals for ImageGallery" 2014-08-22 23:53:13 +00:00
umherirrender
a5ed2df445 Use config instead of globals for ImageGallery
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
2014-08-22 22:36:59 +02:00
aude
513ff7975d Rename variable in RequestContext, $t => $title
Change-Id: Id416816f1c291fea9b7b97b41290b5078936705b
2014-08-18 12:51:40 +02:00
Kunal Mehta
fa46ef3f0c Normalize key before creating a Skin object
Bug: 69566
Change-Id: Id0af543cf206f47a3577019313597388ebc63b6a
2014-08-14 13:53:18 -07:00
Kunal Mehta
eb37e9d1ff Introduce SkinFactory
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
2014-08-09 21:40:54 +01:00
Kunal Mehta
d6e7c6b3f1 RequestContext: Use Config instead of globals
Change-Id: Id6107d0446f5143e60885d002bc8df80a7dc7c10
2014-08-08 10:25:03 +01:00
umherirrender
02dc9da399 Cleanup some docs (includes/[a-d])
- 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
2014-07-24 19:42:45 +02:00
withoutaname
8c2d4fa8e2 Make if checks in RequestContext.php more concise
Change-Id: Ieb1eaeb595fc77ba926ba6ff96140dff44ba840f
2014-07-21 23:50:23 +00:00
jenkins-bot
004cb173d8 Merge "ContextSource::getContext() can return any IContextSource" 2014-07-19 13:06:02 +00:00
Kunal Mehta
78a8351111 Properly check whether a user exists
User::newFromId() will never return false. We have to actually
load from the database to see whether the user still exists.

Change-Id: Id9329635717e6a4f1f34d0b2b665bb790685d2fa
2014-07-13 22:03:00 -07:00
Kunal Mehta
41f159e372 ContextSource::getContext() can return any IContextSource
Change-Id: Ie5866ce42accf87a2bfb1bc1a24c8966a0d3c20d
2014-07-12 21:41:45 -07:00
withoutaname
a395db765b Enforce type hinting for setTitle() in IContextSource subclasses
Change-Id: Iecd8535b04072823a6f4efe33697148f4d20118e
2014-07-13 01:05:39 +00:00
Max Semenik
859aa19359 Reset RequestContext between tests
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
2014-06-27 10:59:47 -07:00
daniel
9636d44448 Guard recursion flag against exceptions.
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
2014-06-24 15:55:39 +02:00
withoutaname
1be828aa6c Removed setLang() too from IContextSource subclasses
getLang() has been removed by e45e0b1a6.

Change-Id: I813f96b78211fbbe5b2e93488fcf1c28878b8d5a
2014-06-22 19:54:14 +00:00
withoutaname
e45e0b1a66 Removed getLang() from IContextSource and subclasses
Change-Id: I94c3df814c06c54c071f371101882dcc71c99417
2014-06-20 11:36:59 -07:00
Kunal Mehta
07c748343c DerivativeContext::setConfig should take a Config object
Change-Id: Icc16a9c206c57fac2d26547cb874e02ef09c0485
Follows-Up: I13baec0b6d4ea7badf20b9c5f9b40846348838e4
2014-05-26 19:36:59 -07:00
jenkins-bot
5aec437d5e Merge "Make abstract Config class truly implementation-agnostic" 2014-05-27 01:43:39 +00:00
Kunal Mehta
8977e56a6b Make abstract Config class truly implementation-agnostic
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
2014-05-26 02:59:57 -07:00
Marius Hoch
e2fbfb2f3b Document that IContextSource::getTitle can return null
That can happen if wgTitle is null.

Change-Id: I3d8aab232d408e75afb8be82ca714bf5c4fe2427
2014-04-24 19:53:20 +02:00
umherirrender
9c614ac02d Fixed some @params documentation
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
2014-04-14 19:52:18 +00:00
Siebrand Mazeland
f077c4b1d6 Update formatting
Change-Id: I18aff576262479c9bb1c56eb8e1d1aaae200e4b1
2014-02-06 09:27:05 +01:00
Kunal Mehta
fbfe789b98 Config: Add Config and GlobalConfig classes
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
2014-01-27 21:10:30 -08:00
Kunal Mehta
7e0ab7ffd0 Fix typo in DerivativeContext doc
Change-Id: Ife6395fa7f78cb7b52b78cc60419fd387bd8509c
2013-12-25 22:56:49 -08:00