Manual:GlobalFunctions.php

From Linux Web Expert

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

GlobalFunctions.php is a file that contains global functions, including such important functions as wfMessage, which is used for internationalisation .

  • wfMessage (replaces the now deprecated wfMsg and wfMsgExt)

wfFindFile()

<td class="mw-version-versionbox" title="<translate nowrap> MediaWiki <tvar name=1>1.38</tvar> is unsupported version</translate>">
<translate> ≤</translate> 1.38
<translate> MediaWiki version:</translate>

<translate> (deprecated in <tvar name=2>1.34</tvar>)</translate> <translate> (removed in <tvar name=2>1.39</tvar>)</translate> Use MediaWikiServices::getInstance()->getRepoGroup()->findFile() instead.

Passing a string (with a file name) or a Title object, returns a File object, or false if the file does not exist. It's a shortcut for RepoGroup::singleton()->findFile(). Use RepoGroup::singleton()->getLocalRepo()->findFile() if you need to get files only from the local repository.

wfRunHooks()

<td class="mw-version-versionbox" title="<translate nowrap> MediaWiki <tvar name=1>1.32</tvar> is unsupported version</translate>">
<translate> ≤</translate> 1.32
<translate> MediaWiki version:</translate>

<translate> (removed in <tvar name=2>1.32</tvar>)</translate>

wfRunHooks() example usage, from WikiPage:doEditContent() :

$hook_args = array( &$this, &$user, $content, $summary,
	$flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId );
ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $hook_args );
wfRunHooks( 'PageContentSaveComplete', $hook_args );

wfRandom()

wfRandom() is used to populate page.page_random.

wfBaseConvert()

<translate> (deprecated in <tvar name=2>1.27</tvar>)</translate> <translate> (removed in <tvar name=2>1.31</tvar>)</translate> Use Wikimedia\base_convert() directly. The function used to generate the base-36 SHA-1 text content hash in revision.rev_sha1 is wfBaseConvert( sha1( $text ), 16, 36, 31 ). API modules like ApiQueryRevisions use wfBaseConvert( $revision->getSha1(), 36, 16, 40 ).

wfTempDir()

This function attempts to get the system directory for temporary files.

wfIsCLI()

<td class="mw-version-versionbox" title="<translate nowrap> The latest stable version is <tvar name=1>1.41</tvar></translate>">
<translate> ≥</translate> 1.31
Gerrit change 401682
<translate> MediaWiki version:</translate>

Returns true if the code is being run from the command line.

Zobacz też