design.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. design.txt
  2. This is a brief overview of the new design.
  3. More thorough and up-to-date information is available on the documentation
  4. wiki at https://www.mediawiki.org/
  5. Primary classes:
  6. User
  7. Encapsulates the state of the user viewing/using the site. Can be queried
  8. for things like the user's settings, name, etc. Handles the details of
  9. getting and saving to the "user" table of the database, and dealing with
  10. sessions and cookies.
  11. OutputPage
  12. Encapsulates the entire HTML page that will be sent in response to any
  13. server request. It is used by calling its functions to add text, headers,
  14. etc., in any order, and then calling output() to send it all. It could be
  15. easily changed to send incrementally if that becomes useful, but I prefer
  16. the flexibility. This should also do the output encoding. The system
  17. allocates a global one in $wgOut.
  18. Title
  19. Represents the title of an article, and does all the work of translating
  20. among various forms such as plain text, URL, database key, etc. For
  21. convenience, and for historical reasons, it also represents a few features
  22. of articles that don't involve their text, such as access rights.
  23. See also title.txt.
  24. Article
  25. Encapsulates access to the "page" table of the database. The object
  26. represents a an article, and maintains state such as text (in Wikitext
  27. format), flags, etc.
  28. Revision
  29. Encapsulates individual page revision data and access to the
  30. revision/text/blobs storage system. Higher-level code should never touch
  31. text storage directly; this class mediates it.
  32. Skin
  33. Encapsulates a "look and feel" for the wiki. All of the functions that
  34. render HTML, and make choices about how to render it, are here, and are
  35. called from various other places when needed (most notably,
  36. OutputPage::addWikiText()). The StandardSkin object is a complete
  37. implementation, and is meant to be subclassed with other skins that may
  38. override some of its functions. The User object contains a reference to a
  39. skin (according to that user's preference), and so rather than having a
  40. global skin object we just rely on the global User and get the skin with
  41. $wgUser->getSkin().
  42. See also skin.txt.
  43. Language
  44. Represents the language used for incidental text, and also has some
  45. character encoding functions and other locale stuff. The current user
  46. interface language is instantiated as $wgLang, and the local content
  47. language as $wgContLang; be sure to use the *correct* language object
  48. depending upon the circumstances.
  49. See also language.txt.
  50. Parser
  51. Class used to transform wikitext to html.
  52. LinkCache
  53. Keeps information on existence of articles. See linkcache.txt.
  54. Naming/coding conventions:
  55. These are meant to be descriptive, not dictatorial; I won't presume to tell
  56. you how to program, I'm just describing the methods I chose to use for myself.
  57. If you do choose to follow these guidelines, it will probably be easier for
  58. you to collaborate with others on the project, but if you want to contribute
  59. without bothering, by all means do so (and don't be surprised if I reformat
  60. your code).
  61. - I have the code indented with tabs to save file size and so that users can
  62. set their tab stops to any depth they like. I use 4-space tab stops, which
  63. work well. I also use K&R brace matching style. I know that's a religious
  64. issue for some, so if you want to use a style that puts opening braces on
  65. the next line, that's OK too, but please don't use a style where closing
  66. braces don't align with either the opening brace on its own line or the
  67. statement that opened the block--that's confusing as hell.
  68. - Certain functions and class members are marked with /* private */, rather
  69. than being marked as such. This is a hold-over from PHP 4, which didn't
  70. support proper visibilities. You should not access things marked in this
  71. manner outside the class/inheritance line as this code is subjected to be
  72. updated in a manner that enforces this at some time in the near future, and
  73. things will break. New code should use the standard method of setting
  74. visibilities as normal.
  75. - Globals are particularly evil in PHP; it sets a lot of them automatically
  76. from cookies, query strings, and such, leading to namespace conflicts; when
  77. a variable name is used in a function, it is silently declared as a new
  78. local masking the global, so you'll get weird error because you forgot the
  79. global declaration; lack of static class member variables means you have to
  80. use globals for them, etc. Evil, evil.
  81. I think I've managed to pare down the number of globals we use to a scant
  82. few dozen or so, and I've prefixed them all with "wg" so you can spot errors
  83. better (odds are, if you see a "wg" variable being used in a function that
  84. doesn't declare it global, that's probably an error).
  85. Other conventions: Top-level functions are wfFuncname(), names of session
  86. variables are wsName, cookies wcName, and form field values wpName ("p" for
  87. "POST").