summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/GetUserName/GetUserName.php
blob: c50b2a73a03f5430b36fcc540797ca4805628474 (plain)
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
46
47
48
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
    die( 'This file is a MediaWiki extension and not a valid entry point' );
}

$wgExtensionCredits['parserhook'][] = array(
    'path' => __FILE__,
    '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;
        $username = $wgUser->getName();
        $isip = ip2long($username) !== false;
        if ($isip) {
          return;
        } else {
          return trim( $username );
        }
    }
}