-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetUsername.php
45 lines (38 loc) · 1.09 KB
/
GetUsername.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
if (!defined('MEDIAWIKI')) {
die('This file is a MediaWiki extension, it is not a valid entry point');
}
$wgExtensionCredits['parserhook'][] = array(
'name' => 'GetUserName',
'version' => '1.0',
'url' => 'https://www.mediawiki.org/wiki/Extension:GetUserName',
'author' => 'Ejcaputo',
'description' => "Allows the current user's name to be put in a page"
);
$wgHooks['ParserFirstCallInit'][] = "ExtGetUserName::setup";
$wgHooks['LanguageGetMagic'][] = 'ExtGetUserName::languageGetMagic';
class ExtGetUserName
{
private static $parserFunctions = array(
'USERNAME' => 'getUserName',
);
public static function setup(&$parser)
{
// register each hook
foreach (self::$parserFunctions as $hook => $function)
$parser->setFunctionHook($hook,
array(__CLASS__, $function), SFH_OBJECT_ARGS);
return true;
}
public static function languageGetMagic(&$magicWords, $langCode)
{
$magicWords['USERNAME'] = array(0, 'USERNAME');
return true;
}
public static function getUserName(&$parser, $frame, $args)
{
$parser->disableCache();
global $wgUser;
return trim($wgUser->getName());
}
}