globals.txt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. globals.txt
  2. Globals are evil. The original MediaWiki code relied on globals for processing
  3. context far too often. MediaWiki development since then has been a story of
  4. slowly moving context out of global variables and into objects. Storing
  5. processing context in object member variables allows those objects to be reused
  6. in a much more flexible way. Consider the elegance of:
  7. # Generate the article HTML as if viewed by a web request
  8. $article = new Article( Title::newFromText( $t ) );
  9. $article->view();
  10. versus
  11. # Save current globals
  12. $oldTitle = $wgTitle;
  13. $oldArticle = $wgArticle;
  14. # Generate the HTML
  15. $wgTitle = Title::newFromText( $t );
  16. $wgArticle = new Article;
  17. $wgArticle->view();
  18. # Restore globals
  19. $wgTitle = $oldTitle
  20. $wgArticle = $oldArticle
  21. Some of the current MediaWiki developers have an idle fantasy that some day,
  22. globals will be eliminated from MediaWiki entirely, replaced by an application
  23. object which would be passed to constructors. Whether that would be an
  24. efficient, convenient solution remains to be seen, but certainly PHP 5 makes
  25. such object-oriented programming models easier than they were in previous
  26. versions.
  27. For the time being though, MediaWiki programmers will have to work in an
  28. environment with some global context. At the time of writing, 418 globals were
  29. initialised on startup by MediaWiki. 304 of these were configuration settings,
  30. which are documented in DefaultSettings.php. There is no comprehensive
  31. documentation for the remaining 114 globals, however some of the most important
  32. ones are listed below. They are typically initialised either in index.php or in
  33. Setup.php.
  34. For a description of the classes, see design.txt.
  35. $wgTitle
  36. Title object created from the request URL.
  37. $wgOut
  38. OutputPage object for HTTP response.
  39. $wgUser
  40. User object for the user associated with the current request.
  41. $wgLang
  42. Language object selected by user preferences.
  43. $wgContLang
  44. Language object associated with the wiki being viewed.
  45. $wgParser
  46. Parser object. Parser extensions register their hooks here.
  47. $wgRequest
  48. WebRequest object, to get request data
  49. $wgMemc, $messageMemc
  50. Object caches