Manual:Code

This page describes the primary source files (classes) / objects of the MediaWiki code.

Index.php
on SVN (main directory)

Main script. It creates the necessary global objects and parses the URL to determine what to do, which it then generally passes off to scripts in other files (depending on the action to be taken).

It applies inclusion to WebStart.php (SVN), which in turn applies inclusion to LocalSettings.php.

Next it defines class MediaWiki through inclusion of Wiki.php, and creates an object $mediaWiki which is an instance of that class.

It calls function checkInitialQueries in Wiki.php, which calls function newFromURL in Title.php (see below) to extract the title and action from the URL.

Many functions do their job by sending content to the $wgOut object. It is created by function initialize (where the name $output is used), and flushed out by function finalCleanup, both in Title.php (see below), which flushes that out. If there are any changes that need to be made to the database that can be deferred until after page display, those happen at the end.

Note that the order in the includes is touchy; Language uses some global functions, etc. Likewise with the creation of the global variables. Don't move them around without some forethought.

Wiki.php
on SVN (directory "includes")

This file consists of the definition of the class MediaWiki. Among other things this class contains:
 * function performAction which performs most actions, including creating the HTML. For example, in the case of viewing a page, function "view" in Article.php is called.
 * function finalCleanup (called by index.php) which calls function output in Output.php, which flushes out all HTML.

Setup.php
on SVN (directory "includes")

This file contains, among other things: With or without using function StubObject in StubObject.php, this creates an instance $wgOut of class OutputPage in OutputPage.php, etc.

User.php
on SVN (directory "includes")

Encapsulates the state of the user viewing/using the site. Can be queried for things like the user's settings, name, etc. Handles the details of getting and saving to the user table of the database, and dealing with sessions and cookies.

OutputPage.php
on SVN (directory "includes")

This file contains function addPrimaryWikiText which:
 * applies function parse in Parser.php to the wikitext $text, resulting in the HTML text $text
 * applies function addParserOutput to the HTML text $text, which:
 * applies function addHTML to $text, which appends $text to $mBodytext.

Contains:
 * function output, called from function finalCleanup in Wiki.php. It calls function outputPage in Skin.php.
 * function out, called from function outputPage in Skin.php a number of times, to send the HTML to the user: $mBodytext and HTML before and after it.

Parser.php
on SVN (directory "includes")

This file defines the parser object used to convert a string $text from wikitext to HTML. It contains function parse, which performs the parsing in several stages:
 * 1) It calls function strip, which strips and renders nowiki, pre, math, and hiero. This function is preceded by the ParserBeforeStrip hook and followed by the ParserAfterStrip hook.
 * 2) It calls function internalParse, which converts the string $text from wikitext to HTML. It expands variables and templates, replaces wiki markup such as header codes and double and triple quotation marks with their HTML equivalents, converts double-bracketed phrases into A HREF links to internal wiki pages, and converts single-bracketed URLs into A HREF links to external pages.
 * 3) It calls function tidy, which does some HTML cleanup. This function is preceded by the ParserBeforeTidy hook and followed by the ParserAfterTidy hook.

Title.php
on SVN (directory "includes") Represents the title of an article, and does all the work of translating among various forms such as plain text, URL, database key, etc. For convenience, and for historical reasons, it also represents a few features of articles that don't involve their text, such as access rights.

Article.php
on SVN (directory "includes")

Calls function parse in wgParse, which is an instance of class Parser in Parser.php.

Encapsulates access to the revision table etc. of the database. The object represents an article, and maintains state such as text (in wikitext format), flags, etc.

Skin.php
on SVN (directory "includes")

Encapsulates a "look and feel" for the wiki. All of the functions that render HTML, and make choices about how to render it, are here, and called from various other places when needed.

Contains function outputPage, called from function output in OutputPage.php. Function outputPage calls function out in OutputPage.php a number of times, to send the HTML to the user: $mBodytext and HTML before and after it.

The StandardSkin object is a complete implementation, and is meant to be subclassed with other skins that may override some of its functions. The User object contains a reference to a skin (according to that user's preference), and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser->getSkin.

Language.php
on SVN (directory "languages")

Represents the language used for incidental text, and also has some character encoding functions and other locale stuff. A global one is allocated in $wgLang.

See also internationalisation.

LinkCache.php
on SVN (directory "includes")

Keeps information on existence of articles. See LINKCACHE.TXT.

API
The api code has an external access point /api.php, but can also be used internally by other code. See api page for in depth description.