* API: fixed titleToKey() to convert values to upper case.
[mediawiki.git] / docs / globals.txt
blobecc5ab33fdb13f61a5af270a6f816e2a0b956722
1 globals.txt
3 Globals are evil. The original MediaWiki code relied on
4 globals for processing context far too often. MediaWiki
5 development since then has been a story of slowly moving
6 context out of global variables and into objects. Storing
7 processing context in object member variables allows those
8 objects to be reused in a much more flexible way. Consider
9 the elegance of:
11     # Generate the article HTML as if viewed by a web request
12     $article = new Article( Title::newFromText( $t ) );
13     $article->view();
15 versus
17     # Save current globals
18     $oldTitle = $wgTitle;
19     $oldArticle = $wgArticle;
21     # Generate the HTML
22     $wgTitle = Title::newFromText( $t );
23     $wgArticle = new Article;
24     $wgArticle->view();
26     # Restore globals
27     $wgTitle = $oldTitle
28     $wgArticle = $oldArticle
30 Some of the current MediaWiki developers have an idle
31 fantasy that some day, globals will be eliminated from
32 MediaWiki entirely, replaced by an application object which 
33 would be passed to constructors. Whether that would be an 
34 efficient, convenient solution remains to be seen, but 
35 certainly PHP 5 makes such object-oriented programming 
36 models easier than they were in previous versions.
38 For the time being though, MediaWiki programmers will have
39 to work in an environment with some global context. At the 
40 time of writing, 418 globals were initialised on startup by 
41 MediaWiki. 304 of these were configuration settings, which 
42 are documented in DefaultSettings.php. There is no 
43 comprehensive documentation for the remaining 114 globals, 
44 however some of the most important ones are listed below. 
45 They are typically initialised either in index.php or in 
46 Setup.php.
49 $wgOut
50         OutputPage object for HTTP response.
52 $wgUser
53         User object for the user associated with the current
54         request.
56 $wgTitle
57         Title object created from the request URL.
59 $wgLang
60         Language object selected by user preferences
62 $wgContLang
63         Language object associated with the wiki being
64         viewed.
66 $wgArticle
67         Article object corresponding to $wgTitle.
69 $wgParser
70         Parser object. Parser extensions register their
71         hooks here.
73 $wgLoadBalancer
74         A LoadBalancer object, manages database connections.