Global variables

From Meta

Jump to: navigation, search

<- MediaWiki architecture < MediaWiki code layout

There are a lot of global variables. Many of them are scary and will try to bite you.

Some of them are set in LocalSettings.php.

Some of them are not. A few of the exciting created ones:

Contents

[edit] wgTitle

This is a Title object representing the current page. The Article object is dependent on this, as is the output probably; someday things should be refactored to take an arbitrary title in the constructor and keep clean.

[edit] wgLinkCache

For checking link status and existence of pages; this is somewhat tied in also with modification of the link tables on page save.

[edit] wgUser

A User object representing the current user. Very clever. Some state as far as what actions are allowed depend on $wgUser, as well as the output style.

[edit] wgLang

An instance of one of the child classes of Language; it knows the names assigned to namespaces and the message strings used in the output, as well as the character encoding to be used by text, whether to display with right-to-left text direction, and how to munge text so it can be used in the search engine.

Output of interface text strings goes through the wfMsg() function, which calls $wgLang->getMessage() for the base string.

It has other things tied into it that it shouldn't probably, such as which special pages are valid and which language codes can be used as interlanguage links.

Someday it would be nice to separate the use of the language objects such that we can use interface strings for one language on a wiki running in another language (or an explicitly multilingual wiki).

[edit] wgOut

A mix of general output management and wiki-to-html conversion. Some things go through a Skin object, which interestingly is not a global object, but is retrieved by asking $wgUser for the user's preferred skin.

There is interesting stuff on wgOut on Writing a new special page, but there are some not covered parts: To not immediatedly return text on the screen but to simply parse wikitext and return html use

global $wgOut;
$output = $wgOut->parse("''italic''");

Notice that it will always wrap it up in <p></p>, so the resulting html of the above would be:

<p>
<i>italic</i>
</p>

To avoid this, do

global $wgOut;
$output = $wgOut->parse("''italic''", false);

and you get the plain html without <p></p>.

[edit] wgArticlePath

This is the path to use when accessing a page in MediaWiki. The path should contain the path to the main script (usually making use of wgScript) and use the $1 placeholder for the article name.

if you are using Apache rewrite rules to create pretty and short URLs, you probably need to adjust wgArticlePath to address the right path. Note that wgArticlePath is used to construct URLs from within MediaWiki. If you make a mistake here, internal links will show up incorrectly while you still may be able to access the main page by specifying the correct URL manually.

Typical values are

"$wgScript/$1" pass the article name with a / separator
"$wgScript?title=$1" pass the article name as a parameter (old style)
"mypath/$1" custom path. Use Apache rewrite rules to convert "mypath" to the proper path accessing the main script

[edit] many more...

$wgArticle, 
$wgDeferredUpdateList,
$wgMemc, $wgMagicWords, $wgMwRedir,
$wgServer,
$wgScriptPath,$wgScript,
$wgRedirectScript,
$wgStyleSheetPath,
$wgStyleSheetDirectory,
$wgArticlePath,$wgUploadPath,
$wgUploadDirectory,
$wgLogo,
$wgMathPath,
$wgMathDirectory,
$wgTmpDirectory,
$wgEmergencyContact,
$wgPasswordSender,
$wgDBserver,
$wgDBname,
$wgDBintlname,
$wgDBconnection,
$wgDBuser,
$wgDBpassword,
$wgDBsqluser,
$wgDBsqlpassword,
$wgDBminWordLen,
$wgDBtransactions,
$wgDBmysql4,
$wgUseMemCached,
$wgMemCachedServers,
$wgMemCachedDebug,
$wgLanguageCode,
$wgInterwikiMagic,
$wgUseNewInterlanguage,
$wgInputEncoding,
$wgOutputEncoding,
$wgEditEncoding,
$wgDocType,
$wgDTD,
$wgUseDynamicDates,
$wgAmericanDates,
$wgLocalInterwiki,
$wgShowIPinHeader,
$wgUseDynamicDates,
$wgReadOnlyFile,
$wgDebugLogFile,
$wgDebugComments,
$wgReadOnly,
$wgSqlLogFile,
$wgLogQueries,
$wgUseBetterLinksUpdate,
$wgSysopUserBans,
$wgIPBlockExpiration,
$wgUserBlockExpiration,
$wgCachePages,
$wgCacheEpoch,
$wgUseFileCache,
$wgFileCacheDirectory,
$wgCookieExpiration,
$wgAllowExternalImages,
$wgMiserMode,
$wgUseTeX,
$wgProfiling,
$wgUseGzip,
$wgPasswordSalt,
$wgNamespacesWithSubpages,
$wgNamespacesToBeSearchedDefault,
$wgNumberOfArticles,
$wgTotalViews,
$wgTotalEdits,
$action, 
$title, 
$search, 
$go, 
$target, 
$printable
$returnto, 
$diff, 
$oldid,
$wgDefaultUserOptionsEn,
$wgBookstoreListEn,
$wgNamespaceNamesEn,
$wgQuickbarSettingsEn,
$wgSkinNamesEn,
$wgMathNamesEn,
$wgDateFormatsEn,
$wgUserTogglesEn,
$wgLanguageNamesEn,
$wgMonthNamesEn,
$wgMonthAbbreviationsEn,
$wgWeekdayNamesEn,
$wgLocalTZoffset,
$wgAllMessagesEn

etc.

See also:

Personal tools