/** * @param Row $row * @param string $reason * @return a streamlined recent changes line with IP data */ protected function CUChangesLine($row, $reason) { global $wgLang; static $cuTitle, $flagCache; $cuTitle = SpecialPage::getTitleFor('CheckUser'); # Add date headers as needed $date = $wgLang->date(wfTimestamp(TS_MW, $row->cuc_timestamp), true, true); if (!isset($this->lastdate)) { $this->lastdate = $date; $line = "\n<h4>{$date}</h4>\n<ul class=\"special\">"; } elseif ($date != $this->lastdate) { $line = "</ul>\n<h4>{$date}</h4>\n<ul class=\"special\">"; $this->lastdate = $date; } else { $line = ''; } $line .= '<li>'; # Create diff/hist/page links $line .= $this->getLinksFromRow($row); # Show date $line .= ' . . ' . $wgLang->time(wfTimestamp(TS_MW, $row->cuc_timestamp), true, true) . ' . . '; # Userlinks $line .= $this->sk->userLink($row->cuc_user, $row->cuc_user_text); $line .= $this->sk->userToolLinks($row->cuc_user, $row->cuc_user_text); # Get block info if (isset($flagCache[$row->cuc_user_text])) { $flags = $flagCache[$row->cuc_user_text]; } else { $user = User::newFromName($row->cuc_user_text, false); $ip = IP::isIPAddress($row->cuc_user_text) ? $row->cuc_user_text : ''; $flags = $this->userBlockFlags($ip, $row->cuc_user, $user); $flagCache[$row->cuc_user_text] = $flags; } # Add any block information if (count($flags)) { $line .= ' ' . implode(' ', $flags); } # Action text, hackish ... if ($row->cuc_actiontext) { $line .= ' ' . $this->sk->formatComment($row->cuc_actiontext) . ' '; } # Comment $line .= $this->sk->commentBlock($row->cuc_comment); $line .= '<br />        <small>'; # IP $line .= ' <strong>IP</strong>: ' . $this->sk->makeKnownLinkObj($cuTitle, htmlspecialchars($row->cuc_ip), 'user='******'&reason=' . urlencode($reason)); # XFF if ($row->cuc_xff != null) { # Flag our trusted proxies list($client, $trusted) = IP::getClientIPfromXFF($row->cuc_xff, $row->cuc_ip); $c = $trusted ? '#F0FFF0' : '#FFFFCC'; $line .= '   <span class="mw-checkuser-xff" style="background-color: ' . $c . '">' . '<strong>XFF</strong>: '; $line .= $this->sk->makeKnownLinkObj($cuTitle, htmlspecialchars($row->cuc_xff), 'user='******'/xff&reason=' . urlencode($reason)) . '</span>'; } # User agent $line .= '   <span class="mw-checkuser-agent" style="color:#888;">' . htmlspecialchars($row->cuc_agent) . '</span>'; $line .= "</small></li>\n"; return $line; }
/** * Handler for non-standard (edit/log) entries that need IP data * * @param $context IContextSource * @param $data Array * @return bool */ protected static function onLoggableUserIPData(IContextSource $context, array $data) { $user = $context->getUser(); $request = $context->getRequest(); // Get IP address $ip = $request->getIP(); // Get XFF header $xff = $request->getHeader('X-Forwarded-For'); list($xff_ip, $isSquidOnly) = IP::getClientIPfromXFF($xff); // Get agent $agent = $request->getHeader('User-Agent'); $dbw = wfGetDB(DB_MASTER); $cuc_id = $dbw->nextSequenceValue('cu_changes_cu_id_seq'); $rcRow = array('cuc_id' => $cuc_id, 'cuc_page_id' => $data['pageid'], 'cuc_namespace' => $data['namespace'], 'cuc_title' => $data['title'], 'cuc_minor' => 0, 'cuc_user' => $user->getId(), 'cuc_user_text' => $user->getName(), 'cuc_actiontext' => $data['action'], 'cuc_comment' => $data['comment'], 'cuc_this_oldid' => 0, 'cuc_last_oldid' => 0, 'cuc_type' => RC_LOG, 'cuc_timestamp' => $dbw->timestamp($data['timestamp']), 'cuc_ip' => IP::sanitizeIP($ip), 'cuc_ip_hex' => $ip ? IP::toHex($ip) : null, 'cuc_xff' => !$isSquidOnly ? $xff : '', 'cuc_xff_hex' => $xff_ip && !$isSquidOnly ? IP::toHex($xff_ip) : null, 'cuc_agent' => $agent); $dbw->insert('cu_changes', $rcRow, __METHOD__); return true; }
/** * @desc Add Chat log entry to "Special:Log" and Special:CheckUser; * otherwise to giving a chat moderator or banning this method isn't called via AJAX, * therefore we have to insert all information manually into DB table */ public static function addConnectionLogEntry() { $wg = F::app()->wg; // record the IP of the connecting user. // use memcache so we order only one (user, ip) pair 3 min to avoid flooding the log $ip = $wg->Request->getIP(); $memcKey = self::getUserIPMemcKey($wg->User->getID(), $ip); $entry = $wg->Memc->get($memcKey); if (empty($entry)) { $wg->Memc->set($memcKey, true, 60 * 3); $log = new LogPage('chatconnect', false, false); $log->addEntry('chatconnect', SpecialPage::getTitleFor('Chat'), '', [$ip], $wg->User); $xff = $wg->Request->getHeader(self::HTTP_HEADER_XFF); list($xff_ip, $isSquidOnly) = IP::getClientIPfromXFF($xff); $userAgent = $wg->Request->getHeader(self::HTTP_HEADER_USER_AGENT); $dbw = wfGetDB(DB_MASTER); $cuc_id = $dbw->nextSequenceValue('cu_changes_cu_id_seq'); $rcRow = ['cuc_id' => $cuc_id, 'cuc_namespace' => NS_SPECIAL, 'cuc_title' => 'Chat', 'cuc_minor' => 0, 'cuc_user' => $wg->User->getID(), 'cuc_user_text' => $wg->User->getName(), 'cuc_actiontext' => wfMessage('chat-checkuser-join-action')->inContentLanguage()->text(), 'cuc_comment' => '', 'cuc_this_oldid' => 0, 'cuc_last_oldid' => 0, 'cuc_type' => CUC_TYPE_CHAT, 'cuc_timestamp' => $dbw->timestamp(), 'cuc_ip' => IP::sanitizeIP($ip), 'cuc_ip_hex' => $ip ? IP::toHex($ip) : null, 'cuc_xff' => !$isSquidOnly ? $xff : '', 'cuc_xff_hex' => $xff_ip && !$isSquidOnly ? IP::toHex($xff_ip) : null, 'cuc_agent' => $userAgent === false ? null : $userAgent]; $dbw->insert('cu_changes', $rcRow, __METHOD__); $dbw->commit(); } }