MediaWiki source code details

From HTYP, the free directory anyone can edit

Jump to: navigation, search

Contents

[edit] Navbar

computing: software: MediaWiki: code details

[edit] Notes

[edit] Some significant globals

Note: In PHP, you have to declare a global variable before you can use it; otherwise PHP will assume you want a new local variable by the same name.

  • $wgUser is the user object, defined in User.php (declare it like this: global $wgUser;)
    • $wgUser->getGroups() returns an array of strings where each string is a group to which the user belongs, e.g. for a sysop/bureaucrat, $groups[0] would be "bureaucrat" if you did this: $groups = $wguser->getGroups();
    • If you need to know membership in implicit groups such as "user" and "*", use $wgUser->getEffectiveGroups()
    • Use $wgUser->isAllowed(action) to find out if the user has permission for a particular action. Default permissions are in DefaultSettings.php, overridable in LocalSettings.php, and documented here

The function outputPage in SkinTemplate.php references a large number of globals, many of which may be significant.

[edit] Where the Nav Links Come From

In SkinTemplate.php, function outputPage seems to be building a massive hierarchical array ($tpl) of all the various components needed to display a wiki page, which is then converted to HTML (etc.) by the code in the applicable (skin name).php file. Significant lines for generating the navigation links would appear to be these:

$tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
$tpl->set( 'nav_urls', $this->buildNavUrls() );

Both of these return arrays which are added to the $tpl array. Function buildNavigationUrls() uses $wgNavigationLinks as a source for its list of links. Function buildNavUrls(), however, has a hard-coded list; it's not clear what the relationship is between those two.

$wgNavigationLinks is defined in DefaultSettings.php, and presumably can be redefined in LocalSettings.php (if, say, you wanted to add more lines to the "navigation" linkbox):

$wgNavigationLinks = array ( array( 'text'=>'mainpage',
'href'=>'mainpage' ), array( 'text'=>'portal',
'href'=>'portal-url' ), array( 'text'=>'currentevents',
'href'=>'currentevents-url' ), array( 'text'=>'recentchanges',
'href'=>'recentchanges-url' ), array( 'text'=>'randompage',
'href'=>'randompage-url' ), array( 'text'=>'help',
'href'=>'helppage' ), array( 'text'=>'sitesupport',
'href'=>'sitesupport-url' ),
);

Each of the strings (except "text" and "href") refers to a value which is settable via the wiki, e.g. the value of "mainpage" can be set by editing the contents of MediaWiki:Mainpage. From there, I was able to figure out how to Add a New Navigation Box.

[edit] How A Page is Built

(From Woozle 21:59, 15 Jun 2005 (EDT).)

  • Everything obviously starts with index.php
  • For the purpose of displaying a page (not saving changes or doing anything else), this calls $wgArticle->view(), in Article.php (line 699)
  • $wgArticle->view() appears to be able to provide a few other formats besides the regular view (including difference engine and displaying redirections as subtitles), but I'm ignoring that for now
  • $wgOut seems to be the object which accumulates text to be output. It is created in Setup.php:
    • $wgOut = new OutputPage();
  • OutputPage() is defined in OutputPage.php
  • After being created, $wgOut accumulates output via various class methods:
  • ...and then it does these two lines:
    • $this->viewUpdates(); (found at line 1926 -- doesn't do much)
    • wfProfileOut( $fname );
  • It's not clear whether the navbar has already been pulled in by the time we hit viewUpdates -- possibly transformBuffer does it? The comment makes it sound like that, but the name "transformBuffer" in that case is not very descriptive. The code in there should probably be examined.
Personal tools