__FILE__, 'name' => 'UntrustedLinksLogger', 'author' => 'James Paige and Laird Shaw', 'url' => 'https://www.mediawiki.org/wiki/Extension:NotEvil', 'descriptionmsg' => 'untrustedlinkslogger-desc', 'version' => '1.0', ); class UntrustedLinksLogger { static function OnUntrustedLinkAttempt($EditPage, $addedUrls, $newText, &$errorMessage) { global $wgUser, $wgRequest, $wgUntrustedLinkAttemptsLogFile, $wgUntrustedLinkAttemptEmail, $wgUntrustedLinkAttemptEmailSubject; $doLog = !empty($wgUntrustedLinkAttemptsLogFile) && (is_writable($wgUntrustedLinkAttemptsLogFile) || touch($wgUntrustedLinkAttemptsLogFile) && is_writable($wgUntrustedLinkAttemptsLogFile)); $doEmail = !empty($wgUntrustedLinkAttemptEmail) && filter_var($wgUntrustedLinkAttemptEmail, FILTER_VALIDATE_EMAIL); if ($doLog || $doEmail) { if (function_exists('wfGetIP')) $ip_address = wfGetIP(); else { $request = method_exists($wgUser, 'getRequest') ? $wgUser->getRequest() : $wgRequest; $ip_address = method_exists($request, 'getIP') ? $request>getIP() : $_SERVER['REMOTE_ADDR']; } $userName = $wgUser->getName(); $timestamp = date('Y-m-d H:i:s'); $titleText = $EditPage->getArticle()->getTitle()->getText(); $urlsStr = implode(' ', $addedUrls); } if ($doLog) { $fh = fopen($wgUntrustedLinkAttemptsLogFile, 'a'); if ($fh !== false) { fwrite($fh, "$timestamp\t$ip_address\t$userName\t$titleText\t$urlsStr\n"); fclose($fh); } } if ($doEmail) { if (isset($wgUntrustedLinkAttemptEmailSubject)) { $subject = $wgUntrustedLinkAttemptEmailSubject; } else { if (function_exists('wfLoadExtensionMessages')) { wfLoadExtensionMessages('UntrustedLinksLogger'); } $wfMsgFunc = function_exists('wfMessage') ? 'wfMessage' : 'wfMsg'; $subject = $wfMsgFunc('untrustedlinkslogger-default-email-subject'); } mail($wgUntrustedLinkAttemptEmail, $subject, "IP: $ip_address\nUsername: $userName\nArticle: $titleText\nAttempted URLs: $urlsStr\n"); } return true; } } ?>