Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7712
globals.txt
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
globals.txt
View Options
globals.txt
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 a configuration
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 (2008), 418 globals were
initialised on startup by MediaWiki. 304 of these were configuration settings,
which are defined in MainConfigSchema.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.
$wgTitle
Title object created from the request URL.
Use IContextSource::getTitle() instead.
$wgOut
OutputPage object for HTTP response.
Use IContextSource::getOutput() instead.
$wgUser
User object for the user associated with the current request.
Use IContextSource::getAuthority() instead.
$wgLang
Language object selected by user preferences.
Use IContextSource::getLanguage() instead.
$wgRequest
WebRequest object, to get request data
Use IContextSource::getRequest() instead.
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Sep 10, 14:43 (16 h, 22 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
58/0c/56b46cdb105c9459dc8fe82da405
Default Alt Text
globals.txt (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment