Dateien hochladen nach ''
This commit is contained in:
60
IPInfo.php
Normal file
60
IPInfo.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
if( !defined( 'MEDIAWIKI' ) ) {
|
||||
echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
|
||||
die( -1 );
|
||||
}
|
||||
|
||||
// Extension credits that will show up on Special:Version
|
||||
$wgExtensionCredits['parserhook'][] = array(
|
||||
'path' => __FILE__,
|
||||
'name' => 'IPInfo',
|
||||
'version' => '1.0',
|
||||
'author' => 'Bernhard Linz',
|
||||
'url' => 'https://www.mediawiki.org/wiki/Extension:MyExtension',
|
||||
'descriptionmsg' => 'ipinfo-desc', // Message key in i18n file.
|
||||
'description' => 'Add Tags for Client IP, Type and DNS-Name'
|
||||
);
|
||||
|
||||
$wgExtensionMessagesFiles['IPInfo'] = dirname( __FILE__ ) . '/' . '/IPInfo.i18n.php';
|
||||
|
||||
$wgHooks['ParserFirstCallInit'][] = 'IPInfoExtension::onParserSetup';
|
||||
|
||||
class IPInfoExtension {
|
||||
// Register any render callbacks with the parser
|
||||
public static function onParserSetup( Parser $parser ) {
|
||||
// When the parser sees the <sample> tag, it executes renderTagSample (see below)
|
||||
$parser->setHook( 'ClientIP', 'IPInfoExtension::ClientIP' );
|
||||
$parser->setHook( 'IPv4orv6', 'IPInfoExtension::IPv4orv6' );
|
||||
$parser->setHook( 'ClientName', 'IPInfoExtension::ClientName' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Render <ClientIP>
|
||||
public static function ClientIP( $input, array $args, Parser $parser, PPFrame $frame ) {
|
||||
$input = getenv("REMOTE_ADDR");
|
||||
return htmlspecialchars( $input );
|
||||
}
|
||||
// Render <ClientName>
|
||||
public static function ClientName( $input, array $args, Parser $parser, PPFrame $frame ) {
|
||||
$input = gethostbyaddr(getenv("REMOTE_ADDR"));
|
||||
return htmlspecialchars( $input );
|
||||
}
|
||||
|
||||
// Render <IPv4orv6>
|
||||
public static function IPv4orv6( $input, array $args, Parser $parser, PPFrame $frame ) {
|
||||
if (strpos(getenv("REMOTE_ADDR"), ":") == false)
|
||||
{
|
||||
$input = "IPv4";
|
||||
} else {
|
||||
$input = "IPv6";
|
||||
};
|
||||
return htmlspecialchars( $input );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user