Localisation updates for magic, special pages aliases, skin names from Betawiki
[lhc/web/wiklou.git] / docs / globals.txt
1 globals.txt
2
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:
10
11 # Generate the article HTML as if viewed by a web request
12 $article = new Article( Title::newFromText( $t ) );
13 $article->view();
14
15 versus
16
17 # Save current globals
18 $oldTitle = $wgTitle;
19 $oldArticle = $wgArticle;
20
21 # Generate the HTML
22 $wgTitle = Title::newFromText( $t );
23 $wgArticle = new Article;
24 $wgArticle->view();
25
26 # Restore globals
27 $wgTitle = $oldTitle
28 $wgArticle = $oldArticle
29
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.
37
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.
47
48 For a description of the classes, see design.txt.
49
50 $wgTitle
51 Title object created from the request URL.
52
53 $wgArticle
54 Article object corresponding to $wgTitle.
55
56 $wgOut
57 OutputPage object for HTTP response.
58
59 $wgUser
60 User object for the user associated with the current
61 request.
62
63 $wgLang
64 Language object selected by user preferences.
65
66 $wgContLang
67 Language object associated with the wiki being
68 viewed.
69
70 $wgParser
71 Parser object. Parser extensions register their
72 hooks here.
73
74 $wgRequest
75 WebRequest object, to get request data
76
77 $wgMemc, $messageMemc, $parserMemc
78 Object caches
79
80 $wgMessageCache
81 Message cache, to manage interface messages
82