Manual:MediaWiki architecture

From MediaWiki.org

Jump to: navigation, search
Some or all of the information on this page is inconsistent, irrelevant or confusing.
Please help clean it up if you are able.

Because the documentation in the source tree is sparse and the code is scary, here's some info for new developers on generally how the MediaWiki software works.

The database (see also database layout) contains the wikitext of the pages and various auxiliary information about pages, users, etc. It also contains all previous versions of all pages, as the MediaWiki software maintains its own version control system.

When viewing a page, XHTML code may be taken from the cache; if not, first the templates, parser functions and variables are expanded. This gives the expanded wikitext, an intermediate result which can be seen with Special:ExpandTemplates, and depends on:

  • the wikitext
  • the templates directly or indirectly referred to
  • the parser functions directly or indirectly referred to
  • the values of variables directly or indirectly referred to

Next, this expanded wikitext is converted to XHTML code (see also m:XHTML); it is sent to the user, and contains references to CSS, JavaScript, and image files. The user can see this intermediate result by applying the "view source" option of the browser. The XHTML code for a given page depends on:

  • the expanded wikitext
  • the mode, such as viewing or editing (see below).
  • the existence of internally linked pages (gives view or edit link)
  • the skin and other user preferences
  • the user name itself
  • the status of the user (more links if a sysop, etc.)
  • the namespace (determines the link to the Talk page, or in the case of a Talk page, the page concerned)
  • whether the page is watched by the user (gives watch or unwatch link)
  • whether the user's Talk page has been recently edited (gives a message)

Finally, the browser renders the XHTML, using the files it refers to. The result the user sees on the screen depends on:

  • the XHTML code
  • files referred to by the XHTML code, such as embedded images, server-side CSS files, and JavaScript files.
  • the browser and browser settings, including possibly a local CSS file, and the screen resolution.

Example: the wikitext of a page is [[help:l{{tc}}k]], the expanded wikitext is [[help:link]], the XML is <a href="/wiki/Help:Link" title="Help:Link">help:link</a> (and a lot more outside the page body), and the rendering is help:link (ditto).

If JavaScript is responding to an event such as a mouse click, the page on the screen depends also on these events. This applies, for example, in the case of a sortable table.

When the user selects the edit tab, the wikitext itself is sent to them, of the whole page or of one section only. When the user presses Show preview, their new version of the wikitext is sent to the server, which sends the corresponding new version of the XHTML code, which is rendered again and displayed above or below the user's new version of the wikitext (which the server has also returned). After possibly more changes and more previews, the user presses Save page, sending their "final" version to the server, which now records the edit and sends the XHTML of the new version (again). In some cases an automatic conversion of wikitext also takes place in this stage.

See also Differences between wikitext and the webpage.

[edit] General architecture

General architecture
User layer web browser
Network layer Squid
Apache webserver
Logic layer MediaWiki's PHP scripts
PHP
Data layer File system MySQL Database (program and content) Caching system

See also: How to become a MediaWiki hacker

For Wikimedia, see also Wikimedia servers.