update per r32672/r32679
[mediawiki.git] / docs / globals.txt
blob11780df8325287fa7a8bb5b5bd6dbde89808b972
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.
48 For a description of the classes, see design.txt.
50 $wgTitle
51         Title object created from the request URL.
53 $wgArticle
54         Article object corresponding to $wgTitle.
56 $wgOut
57         OutputPage object for HTTP response.
59 $wgUser
60         User object for the user associated with the current
61         request.
63 $wgLang
64         Language object selected by user preferences.
66 $wgContLang
67         Language object associated with the wiki being
68         viewed.
70 $wgParser
71         Parser object. Parser extensions register their
72         hooks here.
74 $wgRequest
75         WebRequest object, to get request data
77 $wgMemc, $messageMemc, $parserMemc
78         Object caches
80 $wgMessageCache
81         Message cache, to manage interface messages