Commit graph

44 commits

Author SHA1 Message Date
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
jenkins-bot
57d3f41876 Merge "Begin exposing SiteConfiguration via site contexts" 2013-12-09 12:28:51 +00:00
Siebrand Mazeland
1cdc4ef09b Update formatting and documentation in includes/context/
Change-Id: I8bfdbe8f6d9c325063678e24a9d604f18eb83fc3
2013-11-20 05:25:22 +00:00
Chad Horohoe
101a2a160b Begin exposing SiteConfiguration via site contexts
First step of providing configuration without relying on globals.

You can use this in your code now as follows:
 $myvar = $context->getConfig()->get( 'wgMyVar' )

Change-Id: I23194d1ba747a9e0d925154ae065cbd612b4f591
2013-10-25 14:19:04 -07:00
Brad Jorsch
fc684345b1 Allow $context->setTitle( null )
If something is messing around with $wgTitle before MediaWiki::main()
sets $wgTitle in the first place, it needs to be able to reset it back
to null to avoid a problem like bug 53498. And to do that properly, it
also needs to be able to clear the title in the RequestContext.

Bug: 55435
Change-Id: I6c763b70bbffa0762ca52e61acf7dc200da4075f
2013-10-07 15:01:01 -04:00
Brian Wolff
45024d218d Make msg method of DerivativeContext work properly.
Previously, the msg method was not taking into account any
changes to the context, and was just using the original context.

For example, if you had a DerivativeContext object, where the
original context had a language of en, and then you did
$derivContext->setLanguage( 'fr' );, $derivContext->msg( 'foo' )
was still outputting stuff in english instead of french.

Change-Id: I4a87e0e2664e77bf79a80c873db384e0c3f607e7
2013-08-18 09:20:38 +00:00
Brian Wolff
4ccdde83dc Have Chunked upload jobs bail if cannot associate with session.
Also add docs about how suhosin.session.encrypt tends to break
this (I was thinking about throwing an exception if the setting was
on in RequestContext::importScopedSession, but the docs seem to
indicate that you can tweak how the session is encrypted, so it
sounds like somebody could set up their php so everything worked).

Bug: 48371
Change-Id: I5a471c1f941fce046451fbb9abce1c830185cabb
2013-07-07 23:30:39 -03:00
Timo Tijhof
176c5354bb docs: Consistently use "since" phrasing in @deprecated
Most have it already:
https://doc.wikimedia.org/mediawiki-core/master/php/html/deprecated.html

Ran a find/replace on "@deprecated \d" to fix the odd ones.

Change-Id: I5217aaf75264a0036b5426cd8536116b4bb8f535
2013-05-15 00:56:57 +00:00
umherirrender
ee31d37821 Fixed spacing in context/installer/media/templates/upload folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: I9761be9fa47adc3554852a97b19792b4648466ad
2013-04-21 06:22:06 +00:00
Aaron Schulz
f31a0463aa Fixed importScopedSession() and moved exportUserSession() to RequestContext.
* Renamed WebRequest::exportUserSession -> RequestContext::exportSession.
  Updated the only callers of this new function.
* Init the user with User::newFromId() instead of relying on the session
  (which breaks when things like CentralAuth are enabled).
* Made RequestContext::exportSession() include the user ID.
* Removed now-redundant user ID checks in upload jobs.
* Added unit tests for the session import function.

Change-Id: I543e6766f7a8a828ea5d270328c3bc7738c6fe94
2013-03-15 12:49:54 -07:00
Aaron Schulz
fbf34d84ab [Upload] Moved async upload stuff to the job queue.
* (bug 44080) Also carry-over the IP and HTTP header info.
* This adds a RequestContext::importScopedSession() function.

Change-Id: Ie9c0a4d78fb719569c8149b9cc8a5430f0ac5673
2013-02-15 15:00:35 -08:00
Tim Starling
4d15d53259 Weaken the recursion guard on RequestContext::getLanguage()
Just log and soldier on, since for some reason we are seeing a lot of
these exceptions at the moment, with multiple root causes. Based on Matt
Walker's I49dbc2d7. Updates Idc11b547. See bug 44754.

Change-Id: I2e8c062741c1b2ec2acd68dc76d3fb6efb113571
2013-02-08 16:38:41 +11:00
Niklas Laxström
c014e6b060 (bug 44010) Pass context to UserGetLanguageObject
Only way to avoid messing with wrong request contexts.
Had to add recursion guard too.

Change-Id: Idc11b54752450321e01d92004e08fc95fb6170e6
2013-01-18 10:56:27 +01:00
Siebrand Mazeland
f741f6c092 Update doc comments and code formatting.
Change-Id: I1896d7b1ab5d11d3a609fd97db7c503ad6c590e5
2013-01-11 16:56:04 +01:00
Daniel Friesen
0b6b78d13a It should not be possible for a RequestContext's WikiPage and Title to be different.
Looks like someone messed with RequestContext when I wasn't looking at it.
WikiPage is a representation of the Title. It should not be possible for wikipage
to point to a different title than the context's title.

Fix this issue by unsetting WikiPage when setting title and updating title when
setting wikipage.

Change-Id: I40471b12d08763cb1b47b8382f96d8db94b4f319
2012-10-24 08:17:27 -07:00
umherirrender
85d8ee1f87 Remove a bunch of trailing spaces and unneeded newlines
Change-Id: I00f369641320acd7f087427ef031f3ee7efa0997
2012-10-10 20:14:40 +02:00
Siebrand Mazeland
d4b046a893 Update docs for return and exception info
* Removed some inline tabs in the process.
* IDE fixed some incorrect leading spaces, too.

Change-Id: Ic9303eff6db4424ac3f1fa2816839692b43e6190
2012-10-09 09:41:58 +00:00
Alexandre Emsenhuber
caf5df17ab Per Aaron, fix for r108274: added canUseWikiPage() to context objects to know whether getWikiPage() can be safely called 2012-01-14 14:27:46 +00:00
Sam Reed
f67893fd4a Push msg from ContextSource/RequestContext into IContextSource 2012-01-13 02:37:04 +00:00
Alexandre Emsenhuber
418b3503b1 * Added WikiPage to RequestContext and related so that it can be shared to avoid creating a new object each time and thus avoiding database queries to load the state of the object
* Added Article::getPage() as accessor to the WikiPage object so that it can be set in the context from MediaWiki::initializeArticle()
* Use it WikiPage::main() to call doViewUpdates()

I'm doing to this now so that I can revert r105790 and use the WikiPage object before the 1.19 release
2012-01-06 20:00:04 +00:00
Daniel Friesen
e96d2d6802 Add RequestContextCreateSkin hook to allow extensions to override the loading of skins. 2012-01-03 01:58:27 +00:00
Sam Reed
6c507f38c0 Followup r106619, mark said method public due to callers 2011-12-19 19:07:18 +00:00
Sam Reed
8126793bbf @private is a lie, based on usage, it'd need to be at least protected
Removing useless documentation replacing with param/return doc
2011-12-19 01:07:30 +00:00
Jeroen De Dauw
c65cceab1f doc++ 2011-12-18 21:29:41 +00:00
Jeroen De Dauw
49cdca93be add missing deprecation notices and added deprecation version to existing ones 2011-12-13 05:19:05 +00:00
Daniel Friesen
b9e1326d30 Add missing @since tags for getLanguage and deal with this sanitizeLangCode fatal that no-one bothered to fix. 2011-12-05 18:56:09 +00:00
John Du Hart
51a6eadec1 Followup r103817, updating setLang usages 2011-11-23 10:28:21 +00:00
John Du Hart
216d661d3b Bug 29524 - Rename RequestContext::getLang to getLanguage
I'll be amazed if this doens't break any tests.
2011-11-21 16:13:21 +00:00
Sam Reed
450814de00 More documentation updates 2011-10-28 18:11:47 +00:00
Alexandre Emsenhuber
b212bace90 Per Nikerabbit's comment on r100621:
* Removed OutputPage::setPageTitleMsg() and OutputPage::setHTMLTitleMsg() and make OutputPage::setPageTitle() and OutputPage::setHTMLTitle() accept a Message object
* Updated core calls (including some that I missed last time because of non-matching case)
* Added Message::setContext() and use it in RequestContext so that I don't need to duplicate the call in OutputPage
* Yes, I'm calling $this->msg() on places and then setting the context one more time in OutputPage::setPageTitle() or OutputPage::setHTMLTitle(), but at least I won't be confused about which objects $
2011-10-27 20:23:16 +00:00
Sam Reed
f6300aaeae Leave a fixme comment on context stuff 2011-10-26 04:15:54 +00:00
Platonides
97ab876991 Fix fatal: Fatal error: func_get_args(): Can't be used as a function parameter in includes/context/ContextSource.php on line 121 2011-10-21 22:18:02 +00:00
Daniel Friesen
8dfa97ff0a Separate RequestContext.php into separate files inside of context/
Update the AutoLoader too. This is also a follow up to r97161 since I forgot to add the AutoLoader line.
2011-09-15 17:42:17 +00:00