当前位置: 首页>>代码示例>>PHP>>正文


PHP IP::toHex方法代码示例

本文整理汇总了PHP中IP::toHex方法的典型用法代码示例。如果您正苦于以下问题:PHP IP::toHex方法的具体用法?PHP IP::toHex怎么用?PHP IP::toHex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IP的用法示例。


在下文中一共展示了IP::toHex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 public function save()
 {
     wfProfileIn(__METHOD__);
     $action = "";
     if ($this->data['type'] & self::TYPE_USER && User::isIP($this->data['text'])) {
         $this->data['ip_hex'] = IP::toHex($this->data['text']);
     }
     $dbw = wfGetDB(DB_MASTER, array(), $this->wg->ExternalSharedDB);
     if (empty($this->data['id'])) {
         /* add block */
         $dbw->insert($this->db_table, $this->mapToDB(), __METHOD__);
         $action = 'add';
     } else {
         $dbw->update($this->db_table, $this->mapToDB(), array('p_id' => $this->data['id']), __METHOD__);
         $action = 'edit';
     }
     if ($dbw->affectedRows()) {
         if ($action == 'add') {
             $this->data['id'] = $dbw->insertId();
         }
         $this->log($action);
     } else {
         $action = '';
     }
     $dbw->commit();
     wfProfileOut(__METHOD__);
     return $action ? $this->data['id'] : false;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:28,代码来源:Phalanx.class.php

示例2: showList

 function showList()
 {
     global $wgOut, $wgScript;
     $errors = array();
     // Validate search IP
     $ip = $this->mSearchIP;
     if (!IP::isIPAddress($ip) && strlen($ip)) {
         $errors[] = array('globalblocking-list-ipinvalid', $ip);
         $ip = '';
     }
     $wgOut->addWikiMsg('globalblocking-list-intro');
     // Build the search form
     $searchForm = '';
     $searchForm .= Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('globalblocking-search-legend'));
     $searchForm .= Xml::openElement('form', array('method' => 'get', 'action' => $wgScript, 'name' => 'globalblocklist-search'));
     $searchForm .= Html::hidden('title', SpecialPage::getTitleFor('GlobalBlockList')->getPrefixedText());
     if (is_array($errors) && count($errors) > 0) {
         $errorstr = '';
         foreach ($errors as $error) {
             if (is_array($error)) {
                 $msg = array_shift($error);
             } else {
                 $msg = $error;
                 $error = array();
             }
             $errorstr .= Xml::tags('li', null, wfMsgExt($msg, array('parseinline'), $error));
         }
         $wgOut->addWikiMsg('globalblocking-unblock-errors', count($errors));
         $wgOut->addHTML(Xml::tags('ul', array('class' => 'error'), $errorstr));
     }
     $fields = array();
     $fields['globalblocking-search-ip'] = Xml::input('ip', 45, $ip);
     $searchForm .= Xml::buildForm($fields, 'globalblocking-search-submit');
     $searchForm .= Xml::closeElement('form') . Xml::closeElement('fieldset');
     $wgOut->addHTML($searchForm);
     // Build a list of blocks.
     $conds = array();
     if (strlen($ip)) {
         list($range_start, $range_end) = IP::parseRange($ip);
         if ($range_start != $range_end) {
             // They searched for a range. Match that exact range only
             $conds = array('gb_address' => $ip);
         } else {
             // They searched for an IP. Match any range covering that IP
             $hex_ip = IP::toHex($ip);
             $ip_pattern = substr($hex_ip, 0, 4) . '%';
             // Don't bother checking blocks out of this /16.
             $dbr = wfGetDB(DB_SLAVE);
             $conds = array('gb_range_end>=' . $dbr->addQuotes($hex_ip), 'gb_range_start<=' . $dbr->addQuotes($hex_ip), 'gb_range_start like ' . $dbr->addQuotes($ip_pattern), 'gb_expiry>' . $dbr->addQuotes($dbr->timestamp(wfTimestampNow())));
         }
     }
     $pager = new GlobalBlockListPager($this, $conds);
     $body = $pager->getBody();
     if ($body != '') {
         $wgOut->addHTML($pager->getNavigationBar() . Html::rawElement('ul', array(), $body) . $pager->getNavigationBar());
     } else {
         $wgOut->wrapWikiMsg("<div class='mw-globalblocking-noresults'>\n\$1</div>\n", array('globalblocking-list-noresults'));
     }
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:59,代码来源:SpecialGlobalBlockList.php

示例3: efNetworkAuth_checkForNetworkAuthUser

function efNetworkAuth_checkForNetworkAuthUser()
{
    global $wgNetworkAuthUsers;
    $ip = wfGetIP();
    foreach ($wgNetworkAuthUsers as $networkAuthUser) {
        if (isset($networkAuthUser['user'])) {
            if (isset($networkAuthUser['iprange'])) {
                if (is_array($networkAuthUser['iprange'])) {
                    $ranges = $networkAuthUser['iprange'];
                } else {
                    $ranges = explode("\n", $networkAuthUser['iprange']);
                }
                $hex = IP::toHex($ip);
                foreach ($ranges as $range) {
                    $parsedRange = IP::parseRange($range);
                    if ($hex >= $parsedRange[0] && $hex <= $parsedRange[1]) {
                        global $wgNetworkAuthHost;
                        $wgNetworkAuthHost = $ip;
                        return $networkAuthUser['user'];
                    }
                }
            }
            if (isset($networkAuthUser['ippattern'])) {
                if (is_array($networkAuthUser['ippattern'])) {
                    $patterns = $networkAuthUser['ippattern'];
                } else {
                    $patterns = explode("\n", $networkAuthUser['ippattern']);
                }
                foreach ($patterns as $pattern) {
                    if (preg_match($pattern, $ip)) {
                        global $wgNetworkAuthHost;
                        $wgNetworkAuthHost = $ip;
                        return $networkAuthUser['user'];
                    }
                }
            }
            if (isset($networkAuthUser['hostpattern'])) {
                if (is_array($networkAuthUser['hostpattern'])) {
                    $patterns = $networkAuthUser['hostpattern'];
                } else {
                    $patterns = explode("\n", $networkAuthUser['hostpattern']);
                }
                $host = gethostbyaddr($ip);
                foreach ($patterns as $pattern) {
                    if (preg_match($pattern, $host)) {
                        global $wgNetworkAuthHost;
                        $wgNetworkAuthHost = $host;
                        return $networkAuthUser['user'];
                    }
                }
            }
        } else {
            # No user for range - useless.
        }
    }
    return '';
}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:57,代码来源:NetworkAuth.php

示例4: isTrusted

	function isTrusted( $ip ) {
		$cdb = $this->getCdbHandle();
		// Try single host
		$hex = IP::toHex( $ip );
		$data = dba_fetch( $hex, $cdb );
		if ( $data ) {
			return true;
		}
		// TODO: IPv6 prefixes which aren't feasible to expand
		return false;
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:11,代码来源:TrustedXFF.php

示例5: getGlobalBlockingBlock

 /**
  * Get a block
  * @param string $ip The IP address to be checked
  * @param boolean $anon Get anon blocks only
  * @return object The block
  */
 static function getGlobalBlockingBlock($ip, $anon)
 {
     $dbr = GlobalBlocking::getGlobalBlockingSlave();
     $hex_ip = IP::toHex($ip);
     $ip_pattern = substr($hex_ip, 0, 4) . '%';
     // Don't bother checking blocks out of this /16.
     $conds = array('gb_range_end>=' . $dbr->addQuotes($hex_ip), 'gb_range_start<=' . $dbr->addQuotes($hex_ip), 'gb_range_start like ' . $dbr->addQuotes($ip_pattern), 'gb_expiry>' . $dbr->addQuotes($dbr->timestamp(wfTimestampNow())));
     if (!$anon) {
         $conds['gb_anon_only'] = 0;
     }
     // Get the block
     $block = $dbr->selectRow('globalblocks', '*', $conds, __METHOD__);
     return $block;
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:20,代码来源:GlobalBlocking.class.php

示例6: onCheckUserInsertForRecentChange

 public function onCheckUserInsertForRecentChange($rc, &$fields)
 {
     $fields['cuc_ip'] = IP::sanitizeIP($this->ip);
     $fields['cuc_ip_hex'] = $this->ip ? IP::toHex($this->ip) : null;
     $fields['cuc_agent'] = $this->ua;
     if (method_exists('CheckUserHooks', 'getClientIPfromXFF')) {
         list($xff_ip, $isSquidOnly) = CheckUserHooks::getClientIPfromXFF($this->xff);
         $fields['cuc_xff'] = !$isSquidOnly ? $this->xff : '';
         $fields['cuc_xff_hex'] = $xff_ip && !$isSquidOnly ? IP::toHex($xff_ip) : null;
     } else {
         $fields['cuc_xff'] = '';
         $fields['cuc_xff_hex'] = null;
     }
 }
开发者ID:ATCARES,项目名称:mediawiki-moderation,代码行数:14,代码来源:ModerationCheckUserHook.php

示例7: efUpdateCheckUserData

/**
 * Hook function for RecentChange_save
 * Saves user data into the cu_changes table
 */
function efUpdateCheckUserData($rc)
{
    global $wgUser;
    // Extract params
    extract($rc->mAttribs);
    // Get IP
    $ip = wfGetIP();
    // Get XFF header
    $xff = wfGetForwardedFor();
    list($xff_ip, $trusted) = efGetClientIPfromXFF($xff);
    // Our squid XFFs can flood this up sometimes
    $isSquidOnly = efXFFChainIsSquid($xff);
    // Get agent
    $agent = wfGetAgent();
    // Store the log action text for log events
    // $rc_comment should just be the log_comment
    // BC: check if log_type and log_action exists
    // If not, then $rc_comment is the actiontext and comment
    if (isset($rc_log_type) && $rc_type == RC_LOG) {
        $target = Title::makeTitle($rc_namespace, $rc_title);
        $actionText = LogPage::actionText($rc_log_type, $rc_log_action, $target, NULL, explode('\\n', $rc_params));
    } else {
        $actionText = '';
    }
    $dbw = wfGetDB(DB_MASTER);
    $cuc_id = $dbw->nextSequenceValue('cu_changes_cu_id_seq');
    $rcRow = array('cuc_id' => $cuc_id, 'cuc_namespace' => $rc_namespace, 'cuc_title' => $rc_title, 'cuc_minor' => $rc_minor, 'cuc_user' => $rc_user, 'cuc_user_text' => $rc_user_text, 'cuc_actiontext' => $actionText, 'cuc_comment' => $rc_comment, 'cuc_this_oldid' => $rc_this_oldid, 'cuc_last_oldid' => $rc_last_oldid, 'cuc_type' => $rc_type, 'cuc_timestamp' => $rc_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);
    ## On PG, MW unsets cur_id due to schema incompatibilites. So it may not be set!
    if (isset($rc_cur_id)) {
        $rcRow['cuc_page_id'] = $rc_cur_id;
    }
    $dbw->insert('cu_changes', $rcRow, __METHOD__);
    # Every 100th edit, prune the checkuser changes table.
    wfSeedRandom();
    if (0 == mt_rand(0, 99)) {
        # Periodically flush old entries from the recentchanges table.
        global $wgCUDMaxAge;
        $cutoff = $dbw->timestamp(time() - $wgCUDMaxAge);
        $recentchanges = $dbw->tableName('cu_changes');
        $sql = "DELETE FROM {$recentchanges} WHERE cuc_timestamp < '{$cutoff}'";
        $dbw->query($sql);
    }
    return true;
}
开发者ID:ErdemA,项目名称:wikihow,代码行数:48,代码来源:CheckUser.php

示例8: save

 /**
  * save
  *
  * @return boolean: true on success, false on failure
  */
 public static function save($data, $updateCache = true)
 {
     global $wgExternalSharedDB, $wgMemc;
     $result = false;
     wfProfileIn(__METHOD__);
     if ($data['type'] & Phalanx::TYPE_USER && User::isIP($data['text'])) {
         $data['ip_hex'] = IP::toHex($data['text']);
     }
     $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
     $dbw->insert('phalanx', self::convertDataToDB($data), __METHOD__);
     if ($dbw->affectedRows()) {
         $data['id'] = $result = $dbw->insertId();
         $dbw->commit();
         if ($updateCache) {
             self::updateCache(null, $data);
         }
         self::logAdd($data);
         self::reload($data['id']);
     }
     wfProfileOut(__METHOD__);
     return $result;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:27,代码来源:PhalanxHelper.class.php

示例9: execute

 public function execute()
 {
     $params = $this->extractRequestParams();
     $prop = array_flip($params['prop']);
     $fld_id = isset($prop['id']);
     $fld_address = isset($prop['address']);
     $fld_by = isset($prop['by']);
     $fld_timestamp = isset($prop['timestamp']);
     $fld_expiry = isset($prop['expiry']);
     $fld_reason = isset($prop['reason']);
     $fld_range = isset($prop['range']);
     $result = $this->getResult();
     $data = array();
     $this->addTables('globalblocks');
     if ($fld_id) {
         $this->addFields('gb_id');
     }
     if ($fld_address) {
         $this->addFields(array('gb_address', 'gb_anon_only'));
     }
     if ($fld_by) {
         $this->addFields(array('gb_by', 'gb_by_wiki'));
     }
     if ($fld_timestamp) {
         $this->addFields('gb_timestamp');
     }
     if ($fld_expiry) {
         $this->addFields('gb_expiry');
     }
     if ($fld_reason) {
         $this->addFields('gb_reason');
     }
     if ($fld_range) {
         $this->addFields(array('gb_range_start', 'gb_range_end'));
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $this->addWhereRange('gb_timestamp', $params['dir'], $params['start'], $params['end']);
     if (isset($params['ids'])) {
         $this->addWhereFld('gb_id', $params['ids']);
     }
     if (isset($params['addresses'])) {
         $this->addWhereFld('gb_address', $params['addresses']);
     }
     if (isset($params['ip'])) {
         list($ip, $range) = IP::parseCIDR($params['ip']);
         if ($ip && $range) {
             # We got a CIDR range
             if ($range < 16) {
                 $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad');
             }
             $lower = wfBaseConvert($ip, 10, 16, 8, false);
             $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false);
         } else {
             $lower = $upper = IP::toHex($params['ip']);
         }
         $prefix = substr($lower, 0, 4);
         $this->addWhere(array("gb_range_start LIKE '{$prefix}%'", "gb_range_start <= '{$lower}'", "gb_range_end >= '{$upper}'"));
     }
     $res = $this->select(__METHOD__);
     $count = 0;
     foreach ($res as $row) {
         if (++$count > $params['limit']) {
             // We've had enough
             $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->gb_timestamp));
             break;
         }
         $block = array();
         if ($fld_id) {
             $block['id'] = $row->gb_id;
         }
         if ($fld_address) {
             $block['address'] = $row->gb_address;
             if ($row->gb_anon_only) {
                 $block['anononly'] = '';
             }
         }
         if ($fld_by) {
             $block['by'] = $row->gb_by;
             $block['bywiki'] = $row->gb_by_wiki;
         }
         if ($fld_timestamp) {
             $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->gb_timestamp);
         }
         if ($fld_expiry) {
             $block['expiry'] = Block::decodeExpiry($row->gb_expiry, TS_ISO_8601);
         }
         if ($fld_reason) {
             $block['reason'] = $row->gb_reason;
         }
         if ($fld_range) {
             $block['rangestart'] = IP::hexToQuad($row->gb_range_start);
             $block['rangeend'] = IP::hexToQuad($row->gb_range_end);
         }
         $data[] = $block;
     }
     $result->setIndexedTagName($data, 'block');
     $result->addValue('query', $this->getModuleName(), $data);
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:98,代码来源:ApiQueryGlobalBlocks.php

示例10: blockCheckIP

 /**
  * Directly check for IP block which is quicker than looping through all filters as we don't support
  * anything other than exact for IP blocks, and this significantly improves performance
  *
  * @author grunny
  */
 protected static function blockCheckIP(User $user, $text, $writeStats = true)
 {
     global $wgMemc, $wgExternalSharedDB;
     wfProfileIn(__METHOD__);
     PhalanxShadowing::setType(Phalanx::TYPE_USER);
     $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
     $moduleId = Phalanx::TYPE_USER;
     $timestampNow = wfTimestampNow();
     $ipAddr = IP::toHex($text);
     $row = $dbr->selectRow('phalanx', '*', array("p_type & {$moduleId} = {$moduleId}", "p_lang IS NULL", 'p_ip_hex' => $ipAddr, "p_expire IS NULL OR p_expire > {$dbr->addQuotes($timestampNow)}"), __METHOD__);
     if ($row !== false) {
         $blockData = array('id' => $row->p_id, 'author_id' => $row->p_author_id, 'text' => $row->p_text, 'type' => $row->p_type, 'timestamp' => $row->p_timestamp, 'expire' => $row->p_expire, 'exact' => $row->p_exact, 'regex' => $row->p_regex, 'case' => $row->p_case, 'reason' => $row->p_reason, 'lang' => $row->p_lang);
         Wikia::log(__METHOD__, __LINE__, "Block '{$blockData['text']}' blocked '{$text}'.");
         if ($writeStats) {
             Phalanx::addStats($blockData['id'], $blockData['type']);
         }
         self::setUserData($user, $blockData, $text, true);
         $cachedState = array('timestamp' => wfTimestampNow(), 'block' => $blockData, 'return' => false);
         $wgMemc->set(self::getCacheKey($user), $cachedState);
         PhalanxShadowing::check($user->getName(), $blockData['id']);
         wfProfileOut(__METHOD__);
         return false;
     }
     PhalanxShadowing::check($user->getName(), 0);
     wfProfileOut(__METHOD__);
     return true;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:33,代码来源:UserBlock.class.php

示例11: getRangeEnd

 /**
  * Get the IP address at the start of the range in Hex form
  * @return String IP in Hex form
  */
 public function getRangeEnd()
 {
     switch ($this->type) {
         case self::TYPE_USER:
             return '';
         case self::TYPE_IP:
             return IP::toHex($this->target);
         case self::TYPE_RANGE:
             list(, $end) = IP::parseRange($this->target);
             return $end;
         default:
             throw new MWException("Block with invalid type");
     }
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:18,代码来源:Block.php

示例12: wfIsAOLProxy

/**
 * TODO: move this list to the database in a global IP info table incorporating
 * trusted ISP proxies, blocked IP addresses and open proxies.
 */
function wfIsAOLProxy($ip)
{
    $ranges = array('64.12.96.0/19', '149.174.160.0/20', '152.163.240.0/21', '152.163.248.0/22', '152.163.252.0/23', '152.163.96.0/22', '152.163.100.0/23', '195.93.32.0/22', '195.93.48.0/22', '195.93.64.0/19', '195.93.96.0/19', '195.93.16.0/20', '198.81.0.0/22', '198.81.16.0/20', '198.81.8.0/23', '202.67.64.128/25', '205.188.192.0/20', '205.188.208.0/23', '205.188.112.0/20', '205.188.146.144/30', '207.200.112.0/21');
    static $parsedRanges;
    if (is_null($parsedRanges)) {
        $parsedRanges = array();
        foreach ($ranges as $range) {
            $parsedRanges[] = IP::parseRange($range);
        }
    }
    $hex = IP::toHex($ip);
    foreach ($parsedRanges as $range) {
        if ($hex >= $range[0] && $hex <= $range[1]) {
            return true;
        }
    }
    return false;
}
开发者ID:negabaro,项目名称:alfresco,代码行数:22,代码来源:ProxyTools.php

示例13: execute

 public function execute()
 {
     global $wgUser;
     $params = $this->extractRequestParams();
     if (isset($params['users']) && isset($params['ip'])) {
         $this->dieUsage('bkusers and bkip cannot be used together', 'usersandip');
     }
     $prop = array_flip($params['prop']);
     $fld_id = isset($prop['id']);
     $fld_user = isset($prop['user']);
     $fld_by = isset($prop['by']);
     $fld_timestamp = isset($prop['timestamp']);
     $fld_expiry = isset($prop['expiry']);
     $fld_reason = isset($prop['reason']);
     $fld_range = isset($prop['range']);
     $fld_flags = isset($prop['flags']);
     $result = $this->getResult();
     $pageSet = $this->getPageSet();
     $titles = $pageSet->getTitles();
     $data = array();
     $this->addTables('ipblocks');
     if ($fld_id) {
         $this->addFields('ipb_id');
     }
     if ($fld_user) {
         $this->addFields(array('ipb_address', 'ipb_user', 'ipb_auto'));
     }
     if ($fld_by) {
         $this->addTables('user');
         $this->addFields(array('ipb_by', 'user_name'));
         $this->addWhere('user_id = ipb_by');
     }
     if ($fld_timestamp) {
         $this->addFields('ipb_timestamp');
     }
     if ($fld_expiry) {
         $this->addFields('ipb_expiry');
     }
     if ($fld_reason) {
         $this->addFields('ipb_reason');
     }
     if ($fld_range) {
         $this->addFields(array('ipb_range_start', 'ipb_range_end'));
     }
     if ($fld_flags) {
         $this->addFields(array('ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted', 'ipb_allow_usertalk'));
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']);
     if (isset($params['ids'])) {
         $this->addWhereFld('ipb_id', $params['ids']);
     }
     if (isset($params['users'])) {
         foreach ((array) $params['users'] as $u) {
             $this->prepareUsername($u);
         }
         $this->addWhereFld('ipb_address', $this->usernames);
     }
     if (isset($params['ip'])) {
         list($ip, $range) = IP::parseCIDR($params['ip']);
         if ($ip && $range) {
             # We got a CIDR range
             if ($range < 16) {
                 $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad');
             }
             $lower = wfBaseConvert($ip, 10, 16, 8, false);
             $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false);
         } else {
             $lower = $upper = IP::toHex($params['ip']);
         }
         $prefix = substr($lower, 0, 4);
         $this->addWhere(array("ipb_range_start LIKE '{$prefix}%'", "ipb_range_start <= '{$lower}'", "ipb_range_end >= '{$upper}'"));
     }
     if (!$wgUser->isAllowed('suppress')) {
         $this->addWhereFld('ipb_deleted', 0);
     }
     // Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $res = $this->select(__METHOD__);
     $count = 0;
     while ($row = $res->fetchObject()) {
         if (++$count > $params['limit']) {
             // We've had enough
             $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp));
             break;
         }
         $block = array();
         if ($fld_id) {
             $block['id'] = $row->ipb_id;
         }
         if ($fld_user && !$row->ipb_auto) {
             $block['user'] = $row->ipb_address;
         }
         if ($fld_by) {
             $block['by'] = $row->user_name;
         }
         if ($fld_timestamp) {
             $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp);
//.........这里部分代码省略.........
开发者ID:amjadtbssm,项目名称:website,代码行数:101,代码来源:ApiQueryBlocks.php

示例14: wfGetDB

<?php

/**
 * One-off script to populate the new IP column in the Phalanx table
 *
 * @author grunny
 */
require __DIR__ . '/../../../../maintenance/commandLine.inc';
$dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
$dbResult = $dbr->select(array('phalanx'), array('*'), array('p_type & 8 = 8', 'p_lang IS NULL'), __METHOD__);
$toUpdate = array();
while ($row = $dbr->fetchObject($dbResult)) {
    if (User::isIP($row->p_text)) {
        $toUpdate[$row->p_id] = IP::toHex($row->p_text);
    }
}
$dbr->freeResult($dbResult);
$dbr->close();
$dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
$failedFilters = array();
foreach ($toUpdate as $phalId => $ipHex) {
    $res = (bool) $dbw->update('phalanx', array('p_ip_hex' => $ipHex), array('p_id' => $phalId));
    if (!$res) {
        $failedFilters[] = $phalId;
    }
}
$dbw->close();
echo "Done\n";
echo count($failedFilters) . " failed to be updated!\n";
exit(0);
开发者ID:Tjorriemorrie,项目名称:app,代码行数:30,代码来源:populatePhalanxIPColumn.php

示例15: showList

 function showList($msg)
 {
     global $wgOut, $wgUser;
     $wgOut->setPagetitle(wfMsg("ipblocklist"));
     if ("" != $msg) {
         $wgOut->setSubtitle($msg);
     }
     // Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $conds = array();
     $matches = array();
     // Is user allowed to see all the blocks?
     if (!$wgUser->isAllowed('suppress')) {
         $conds['ipb_deleted'] = 0;
     }
     if ($this->ip == '') {
         // No extra conditions
     } elseif (substr($this->ip, 0, 1) == '#') {
         $conds['ipb_id'] = substr($this->ip, 1);
         // Single IPs
     } elseif (IP::isIPAddress($this->ip) && strpos($this->ip, '/') === false) {
         if ($iaddr = IP::toHex($this->ip)) {
             # Only scan ranges which start in this /16, this improves search speed
             # Blocks should not cross a /16 boundary.
             $range = substr($iaddr, 0, 4);
             // Fixme -- encapsulate this sort of query-building.
             $dbr = wfGetDB(DB_SLAVE);
             $encIp = $dbr->addQuotes(IP::sanitizeIP($this->ip));
             $encRange = $dbr->addQuotes("{$range}%");
             $encAddr = $dbr->addQuotes($iaddr);
             $conds[] = "(ipb_address = {$encIp}) OR \n\t\t\t\t\t(ipb_range_start LIKE {$encRange} AND\n\t\t\t\t\tipb_range_start <= {$encAddr}\n\t\t\t\t\tAND ipb_range_end >= {$encAddr})";
         } else {
             $conds['ipb_address'] = IP::sanitizeIP($this->ip);
         }
         $conds['ipb_auto'] = 0;
         // IP range
     } elseif (IP::isIPAddress($this->ip)) {
         $conds['ipb_address'] = Block::normaliseRange($this->ip);
         $conds['ipb_auto'] = 0;
     } else {
         $user = User::newFromName($this->ip);
         if ($user && ($id = $user->getId()) != 0) {
             $conds['ipb_user'] = $id;
         } else {
             // Uh...?
             $conds['ipb_address'] = $this->ip;
             $conds['ipb_auto'] = 0;
         }
     }
     // Apply filters
     if ($this->hideuserblocks) {
         $conds['ipb_user'] = 0;
     }
     if ($this->hidetempblocks) {
         $conds['ipb_expiry'] = 'infinity';
     }
     if ($this->hideaddressblocks) {
         $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
     }
     $pager = new IPBlocklistPager($this, $conds);
     if ($pager->getNumRows()) {
         $wgOut->addHTML($this->searchForm() . $pager->getNavigationBar() . Xml::tags('ul', null, $pager->getBody()) . $pager->getNavigationBar());
     } elseif ($this->ip != '') {
         $wgOut->addHTML($this->searchForm());
         $wgOut->addWikiMsg('ipblocklist-no-results');
     } else {
         $wgOut->addHTML($this->searchForm());
         $wgOut->addWikiMsg('ipblocklist-empty');
     }
 }
开发者ID:amjadtbssm,项目名称:website,代码行数:72,代码来源:SpecialIpblocklist.php


注:本文中的IP::toHex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。