aboutsummaryrefslogtreecommitdiffstats
path: root/docs/globals.txt
diff options
context:
space:
mode:
authorTim Starling <tstarling@users.mediawiki.org>2005-12-23 07:25:44 +0000
committerTim Starling <tstarling@users.mediawiki.org>2005-12-23 07:25:44 +0000
commit6f30897671f9fa423021c4446c3a036f99069bcb (patch)
treecd289cbcc54450421c89f9628f003e4df5118e05 /docs/globals.txt
parent6ca65246643875ad1cd2a4d2df8a91a8faaf5250 (diff)
downloadmediawikicore-6f30897671f9fa423021c4446c3a036f99069bcb.tar.gz
mediawikicore-6f30897671f9fa423021c4446c3a036f99069bcb.zip
PHP hates globals
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/12224
Diffstat (limited to 'docs/globals.txt')
-rw-r--r--docs/globals.txt72
1 files changed, 60 insertions, 12 deletions
diff --git a/docs/globals.txt b/docs/globals.txt
index 519b4161aa74..b36f8ea3c8b7 100644
--- a/docs/globals.txt
+++ b/docs/globals.txt
@@ -1,29 +1,77 @@
globals.txt
-PHP loves globals. I hate them. This is not a great
-combination, but I manage. I could get rid of most of
-them by having a single "HTTP request" object, and using
-it to hold everything that's now global (which is exactly
-what I'd do in a Java servlet). But that's really
-awkward in PHP, and wouldn't really provide much benefit
-in readability or maintainability, so I go with the flow
-of PHP and use globals. Here's documentation on the
-important globals used by the system.
+Globals are evil. The original MediaWiki code relied on
+globals for processing context far too often. MediaWiki
+development since then has been a story of slowly moving
+context out of global variables and into objects. Storing
+processing context in object member variables allows those
+objects to be reused in a much more flexible way. Consider
+the elegance of:
+
+ # Generate the article HTML as if viewed by a web request
+ $article = new Article( Title::newFromText( $t ) );
+ $article->view();
+
+versus
+
+ # Save current globals
+ $oldTitle = $wgTitle;
+ $oldArticle = $wgArticle;
+
+ # Generate the HTML
+ $wgTitle = Title::newFromText( $t );
+ $wgArticle = new Article;
+ $wgArticle->view();
+
+ # Restore globals
+ $wgTitle = $oldTitle
+ $wgArticle = $oldArticle
+
+Some of the current MediaWiki developers have an idle
+fantasy that some day, globals will be eliminated from
+MediaWiki entirely, replaced by an application object which
+would be passed to constructors. Whether that would be an
+efficient, convenient solution remains to be seen, but
+certainly PHP 5 makes such object-oriented programming
+models easier than they were in previous versions.
+
+For the time being though, MediaWiki programmers will have
+to work in an environment with some global context. At the
+time of writing, 418 globals were initialised on startup by
+MediaWiki. 304 of these were configuration settings, which
+are documented in DefaultSettings.php. There is no
+comprehensive documentation for the remaining 114 globals,
+however some of the most important ones are listed below.
+They are typically initialised either in index.php or in
+Setup.php.
+
$wgOut
OutputPage object for HTTP response.
+$wgUser
+ User object for the user associated with the current
+ request.
+
$wgTitle
Title object created from the request URL.
$wgLang
- Language object for this request.
+ Language object selected by user preferences
+
+$wgContLang
+ Language object associated with the wiki being
+ viewed.
$wgArticle
- Article object corresponsing to $wgTitle.
+ Article object corresponding to $wgTitle.
$wgLinkCache
LinkCache object.
-...
+$wgParser
+ Parser object. Parser extensions register their
+ hooks here.
+$wgLoadBalancer
+ A LoadBalancer object, manages database connections.