diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/GetUserName/GetUserName.php |
first commit
Diffstat (limited to 'www/wiki/extensions/GetUserName/GetUserName.php')
-rw-r--r-- | www/wiki/extensions/GetUserName/GetUserName.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/www/wiki/extensions/GetUserName/GetUserName.php b/www/wiki/extensions/GetUserName/GetUserName.php new file mode 100644 index 00000000..c50b2a73 --- /dev/null +++ b/www/wiki/extensions/GetUserName/GetUserName.php @@ -0,0 +1,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 ); + } + } +} |