/** * Construct an IP address representation. * @param string $address The textual representation of an IP address or CIDR range. */ public function __construct($address) { // analyze address format $this->is_valid = IP::isIPAddress($address); if (!$this->is_valid) { return; } $this->is_ipv4 = IP::isIPv4($address); $this->is_ipv6 = !$this->is_ipv4 && IP::isIPv6($address); // analyze address range $this->is_range = IP::isValidBlock($address); $this->encoded_range = IP::parseRange($address); $this->range = array(IP::prettifyIP(IP::formatHex($this->encoded_range[self::START])), IP::prettifyIP(IP::formatHex($this->encoded_range[self::END]))); }
/** * Render the contribution of the pagerevision (time, bytes added/deleted, pagename comment) * @param Revision $rev */ protected function showContributionsRow(Revision $rev) { $user = $this->getUser(); $userId = $rev->getUser(Revision::FOR_THIS_USER, $user); if ($userId === 0) { $username = IP::prettifyIP($rev->getUserText(Revision::RAW)); $isAnon = true; } else { $username = $rev->getUserText(Revision::FOR_THIS_USER, $user); $isAnon = false; } // FIXME: Style differently user comment when this is the case if ($rev->userCan(Revision::DELETED_COMMENT, $user)) { $comment = $rev->getComment(Revision::FOR_THIS_USER, $user); $comment = $this->formatComment($comment, $this->title); } else { $comment = $this->msg('rev-deleted-comment')->plain(); } $ts = $rev->getTimestamp(); $this->renderListHeaderWhereNeeded($this->getLanguage()->userDate($ts, $this->getUser())); $ts = new MWTimestamp($ts); if ($rev->userCan(Revision::DELETED_TEXT, $user)) { $diffLink = SpecialPage::getTitleFor('MobileDiff', $rev->getId())->getLocalUrl(); } else { $diffLink = false; } // FIXME: Style differently user comment when this is the case if (!$rev->userCan(Revision::DELETED_USER, $user)) { $username = $this->msg('rev-deleted-user')->plain(); } $bytes = null; if (isset($this->prevLengths[$rev->getParentId()])) { $bytes = $rev->getSize() - $this->prevLengths[$rev->getParentId()]; } $isMinor = $rev->isMinor(); $this->renderFeedItemHtml($ts, $diffLink, $username, $comment, $rev->getTitle(), $isAnon, $bytes, $isMinor); }
/** * Show a row in history, including: * time of edit * changed bytes * name of editor * comment of edit * @param Revision $rev Revision id of the row wants to show * @param Revision|null $prev Revision id of previous Revision to display the difference */ protected function showRow(Revision $rev, $prev) { $user = $this->getUser(); $userId = $rev->getUser(Revision::FOR_THIS_USER, $user); if ($userId === 0) { $username = IP::prettifyIP($rev->getUserText(Revision::RAW)); $isAnon = true; } else { $username = $rev->getUserText(Revision::FOR_THIS_USER, $user); $isAnon = false; } // FIXME: Style differently user comment when this is the case if ($rev->userCan(Revision::DELETED_COMMENT, $user)) { $comment = $rev->getComment(Revision::FOR_THIS_USER, $user); $comment = $this->formatComment($comment, $this->title); } else { $comment = $this->msg('rev-deleted-comment')->plain(); } $ts = $rev->getTimestamp(); $this->renderListHeaderWhereNeeded($this->getLanguage()->userDate($ts, $this->getUser())); $ts = new MWTimestamp($ts); $canSeeText = $rev->userCan(Revision::DELETED_TEXT, $user); if ($canSeeText && $prev && $prev->userCan(Revision::DELETED_TEXT, $user)) { $diffLink = SpecialPage::getTitleFor('MobileDiff', $rev->getId())->getLocalUrl(); } elseif ($canSeeText && $rev->getTitle() !== null) { $diffLink = $rev->getTitle()->getLocalUrl(array('oldid' => $rev->getId())); } else { $diffLink = false; } // FIXME: Style differently user comment when this is the case if (!$rev->userCan(Revision::DELETED_USER, $user)) { $username = $this->msg('rev-deleted-user')->plain(); } // When the page is named there is no need to print it in output if ($this->title) { $title = null; } else { $title = $rev->getTitle(); } $bytes = $rev->getSize(); if ($prev) { $bytes -= $prev->getSize(); } $isMinor = $rev->isMinor(); $this->renderFeedItemHtml($ts, $diffLink, $username, $comment, $title, $isAnon, $bytes, $isMinor); }
/** * Render a result row in feed view * @param object $row a row of db result */ protected function showFeedResultRow($row) { if ($row->rc_deleted) { return; } $user = $this->getUser(); $lang = $this->getLanguage(); $date = $lang->userDate($row->rc_timestamp, $user); $this->renderListHeaderWhereNeeded($date); $title = Title::makeTitle($row->rc_namespace, $row->rc_title); $comment = $this->formatComment($row->rc_comment, $title); $ts = new MWTimestamp($row->rc_timestamp); $username = $row->rc_user != 0 ? htmlspecialchars($row->rc_user_text) : IP::prettifyIP($row->rc_user_text); $revId = $row->rc_this_oldid; $bytes = $row->rc_new_len - $row->rc_old_len; $isAnon = $row->rc_user == 0; $isMinor = $row->rc_minor != 0; if ($revId) { $diffTitle = SpecialPage::getTitleFor('MobileDiff', $revId); $diffLink = $diffTitle->getLocalUrl(); } else { // hack -- use full log entry display $diffLink = Title::makeTitle($row->rc_namespace, $row->rc_title)->getLocalUrl(); } $this->renderFeedItemHtml($ts, $diffLink, $username, $comment, $title, $isAnon, $bytes, $isMinor); }
/** * Make user link (or user contributions for unregistered users) * @param int $userId User id in database. * @param string $userName User name in database. * @param string $altUserName Text to display instead of the user name (optional) * @return string HTML fragment * @since 1.19 Method exists for a long time. $altUserName was added in 1.19. */ public static function userLink($userId, $userName, $altUserName = false) { $classes = 'mw-userlink'; if ($userId == 0) { $page = SpecialPage::getTitleFor('Contributions', $userName); if ($altUserName === false) { $altUserName = IP::prettifyIP($userName); } $classes .= ' mw-anonuserlink'; // Separate link class for anons (bug 43179) } else { $page = Title::makeTitle(NS_USER, $userName); } return self::link($page, htmlspecialchars($altUserName !== false ? $altUserName : $userName), array('class' => $classes)); }
/** * Test for IP::prettifyIP() * @dataProvider provideIPsToPrettify */ public function testPrettifyIP($ip, $prettified) { $this->assertEquals($prettified, IP::prettifyIP($ip), "Prettify of {$ip}"); }
/** * Make user link (or user contributions for unregistered users) * @param $userId Integer: user id in database. * @param string $userName user name in database. * @param string $altUserName text to display instead of the user name (optional) * @return String: HTML fragment * @since 1.19 Method exists for a long time. $altUserName was added in 1.19. */ public static function userLink($userId, $userName, $altUserName = false) { if ($userId == 0) { $page = SpecialPage::getTitleFor('Contributions', $userName); if ($altUserName === false) { $altUserName = IP::prettifyIP($userName); } } else { $page = Title::makeTitle(NS_USER, $userName); } return self::link($page, htmlspecialchars($altUserName !== false ? $altUserName : $userName), array('class' => 'mw-userlink')); }
/** * Make user link (or user contributions for unregistered users) * @param int $userId User id in database. * @param string $userName User name in database. * @param string $altUserName Text to display instead of the user name (optional) * @return string HTML fragment * @since 1.16.3. $altUserName was added in 1.19. */ public static function userLink($userId, $userName, $altUserName = false) { $classes = 'mw-userlink'; if ($userId == 0) { $page = SpecialPage::getTitleFor('Contributions', $userName); if ($altUserName === false) { $altUserName = IP::prettifyIP($userName); } $classes .= ' mw-anonuserlink'; // Separate link class for anons (bug 43179) } else { $page = Title::makeTitle(NS_USER, $userName); } // Wrap the output with <bdi> tags for directionality isolation return self::link($page, '<bdi>' . htmlspecialchars($altUserName !== false ? $altUserName : $userName) . '</bdi>', ['class' => $classes]); }