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


PHP IP::sanitizeIP方法代码示例

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


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

示例1: credit

 /**
  *
  * @param string $name
  * @param int $amount
  * @return boolean false if failed
  */
 private function credit($name = null, $amount = 0)
 {
     $output = $this->getOutput();
     $output->addWikiText("=== Credit (name, amount) ===");
     $output->addWikiText("name = {$name}");
     $output->addWikiText("amount = {$amount}");
     $user = User::newFromName($name);
     if (!$user || $user->getId() == 0) {
         $output->addWikiText("=== ERROR: Invalid UserName ===");
         return false;
     }
     $output->addWikiText("=== User ===");
     $output->addWikiText("user_id = " . $user->getId());
     $output->addWikiText("user_name = " . $user->getName());
     $output->addWikiText("user_realname = " . $user->getRealName());
     $output->addWikiText("user_email = " . $user->getEmail());
     $output->addWikiText("=== Transaction ===");
     $output->addWikiText("True balance before = " . TMRecord::getTrueBalanceFromDB($user->getId()));
     if (!is_int($amount) || $amount <= 0 || $amount > 1000) {
         $output->addWikiText("=== ERROR: Invalid Amount ===");
         return false;
     }
     $tmr = array('tmr_type' => TM_REFUND_TYPE, 'tmr_user_id' => $user->getId(), 'tmr_mail' => $user->getEmail(), 'tmr_ip' => IP::sanitizeIP(wfGetIP()), 'tmr_amount' => $amount, 'tmr_currency' => 'EUR', 'tmr_desc' => 'tm-refund', 'tmr_status' => 'OK');
     wfRunHooks('CreateTransaction', array(&$tmr));
     $output->addWikiText("==== DONE ====");
     $output->addWikiText("True balance after = " . TMRecord::getTrueBalanceFromDB($user->getId()));
     $output->addWikiText("== SUCCESS ==");
 }
开发者ID:eFFemeer,项目名称:seizamcore,代码行数:34,代码来源:SpecialTransactionsAdmin.php

示例2: execute

 public function execute($subpage)
 {
     global $wgRequest, $wgOut;
     $this->checkPermissions();
     $this->setHeaders();
     $user = $wgRequest->getText('user') ? $wgRequest->getText('user') : $wgRequest->getText('ip');
     $user = trim($user);
     $reason = $wgRequest->getText('reason');
     $blockreason = $wgRequest->getText('blockreason');
     $checktype = $wgRequest->getVal('checktype');
     $period = $wgRequest->getInt('period');
     $users = $wgRequest->getArray('users');
     $tag = $wgRequest->getBool('usetag') ? trim($wgRequest->getVal('tag')) : '';
     $talkTag = $wgRequest->getBool('usettag') ? trim($wgRequest->getVal('talktag')) : '';
     $m = array();
     # An IPv4? An IPv6? CIDR included?
     if (IP::isIPAddress($user)) {
         $ip = IP::sanitizeIP($user);
         $name = '';
         $xff = '';
         # An IPv4/IPv6 XFF string? CIDR included?
     } elseif (preg_match('/^(.+)\\/xff$/', $user, $m) && IP::isIPAddress($m[1])) {
         $ip = '';
         $name = '';
         $xff = IP::sanitizeIP($m[1]);
         # A user?
     } else {
         $ip = '';
         $name = $user;
         $xff = '';
     }
     $this->showForm($user, $reason, $checktype, $ip, $xff, $name, $period);
     # Perform one of the various submit operations...
     if ($wgRequest->wasPosted()) {
         if (!$this->getUser()->matchEditToken($wgRequest->getVal('wpEditToken'))) {
             $wgOut->wrapWikiMsg('<div class="error">$1</div>', 'checkuser-token-fail');
         } elseif ($wgRequest->getVal('action') === 'block') {
             $this->doMassUserBlock($users, $blockreason, $tag, $talkTag);
         } elseif (!$this->checkReason($reason)) {
             $wgOut->addWikiMsg('checkuser-noreason');
         } elseif ($checktype == 'subuserips') {
             $this->doUserIPsRequest($name, $reason, $period);
         } elseif ($xff && $checktype == 'subedits') {
             $this->doIPEditsRequest($xff, true, $reason, $period);
         } elseif ($ip && $checktype == 'subedits') {
             $this->doIPEditsRequest($ip, false, $reason, $period);
         } elseif ($name && $checktype == 'subedits') {
             $this->doUserEditsRequest($user, $reason, $period);
         } elseif ($xff && $checktype == 'subipusers') {
             $this->doIPUsersRequest($xff, true, $reason, $period, $tag, $talkTag);
         } elseif ($checktype == 'subipusers') {
             $this->doIPUsersRequest($ip, false, $reason, $period, $tag, $talkTag);
         }
     }
     # Add CIDR calculation convenience form
     $this->addJsCIDRForm();
     $wgOut->addModules('ext.checkUser');
     // JS
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:59,代码来源:CheckUser_body.php

示例3: onRecentChange_save

 public function onRecentChange_save(&$rc)
 {
     global $wgPutIPinRC;
     if (!$wgPutIPinRC) {
         return;
     }
     $dbw = wfGetDB(DB_MASTER);
     $dbw->update('recentchanges', array('rc_ip' => IP::sanitizeIP($this->ip)), array('rc_id' => $rc->mAttribs['rc_id']), __METHOD__);
 }
开发者ID:ATCARES,项目名称:mediawiki-moderation,代码行数:9,代码来源:ModerationCheckUserHook.php

示例4: 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

示例5: index

 public function index()
 {
     wfProfileIn(__METHOD__);
     if (!$this->getUser()->isAllowed('coppatool')) {
         wfProfileOut(__METHOD__);
         $this->displayRestrictionError();
         return false;
     }
     $this->specialPage->setHeaders();
     $this->response->setTemplateEngine(WikiaResponse::TEMPLATE_ENGINE_MUSTACHE);
     $this->userName = trim($this->getVal('username', $this->getPar()));
     $this->isIP = false;
     $this->validUser = false;
     if (IP::isIPAddress($this->userName)) {
         $this->userName = IP::sanitizeIP($this->userName);
         $this->isIP = true;
         $this->validUser = true;
     } else {
         $userObj = User::newFromName($this->userName);
         if (!$userObj || $userObj->getId() === 0) {
             $this->validUser = false;
         } else {
             $this->userName = $userObj->getName();
             $this->validUser = true;
         }
     }
     $this->userForm = $this->app->renderView('WikiaStyleGuideForm', 'index', ['form' => ['isInvalid' => $this->validUser || $this->userName === '' ? false : true, 'errorMsg' => $this->validUser || $this->userName === '' ? '' : $this->msg('coppatool-nosuchuser', $this->userName)->escaped(), 'inputs' => [['type' => 'text', 'name' => 'username', 'isRequired' => true, 'label' => $this->msg('coppatool-label-username')->escaped(), 'value' => Sanitizer::encodeAttribute($this->userName)], ['type' => 'submit', 'value' => $this->msg('coppatool-submit')->escaped()]], 'method' => 'GET', 'action' => $this->getTitle()->getLocalUrl()]]);
     if ($this->validUser) {
         $this->getOutput()->addModules('ext.coppaTool');
         $this->buttons = [];
         $this->blankImgUrl = wfBlankImgUrl();
         $this->formHeading = $this->msg('coppatool-form-header')->escaped();
         if (!$this->isIP) {
             $this->buttons[] = ['buttonAction' => 'disable-account', 'buttonLink' => Html::element('a', ['href' => '#'], $this->msg('coppatool-disable')->escaped()), 'done' => $userObj->getGlobalFlag('disabled', false)];
             $this->buttons[] = ['buttonAction' => 'blank-profile', 'buttonLink' => Html::element('a', ['href' => '#'], $this->msg('coppatool-blank-user-profile')->escaped())];
             $this->buttons[] = ['buttonAction' => 'delete-userpages', 'buttonLink' => Html::element('a', ['href' => '#'], $this->msg('coppatool-delete-user-pages')->escaped())];
             $this->buttons[] = ['buttonAction' => 'coppa-imagereview', 'buttonLink' => Linker::link(Title::newFromText('CoppaImageReview', NS_SPECIAL), $this->msg('coppatool-imagereview')->escaped(), ['target' => '_blank'], ['username' => $this->userName], ['known', 'noclasses'])];
         } else {
             $this->buttons[] = ['buttonAction' => 'phalanx-ip', 'buttonLink' => Linker::link(Title::newFromText('Phalanx', NS_SPECIAL), $this->msg('coppatool-phalanx-ip')->escaped(), ['target' => '_blank'], ['type' => Phalanx::TYPE_USER, 'wpPhalanxCheckBlocker' => $this->userName, 'target' => $this->userName], ['known', 'noclasses'])];
             $this->buttons[] = ['buttonAction' => 'rename-ip', 'buttonLink' => Html::element('a', ['href' => '#'], $this->msg('coppatool-rename-ip')->escaped())];
         }
     }
     wfProfileOut(__METHOD__);
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:44,代码来源:CoppaToolSpecialController.class.php

示例6: fnGetGeoIP

function fnGetGeoIP($ip_address = null)
{
    if (!isset($ip_address)) {
        $ip_address = IP::sanitizeIP(wfGetIP());
    }
    if (isset($_GET['ip'])) {
        $ip_address = IP::sanitizeIP($_GET['ip']);
    }
    if (!IP::isIPv4($ip_address)) {
        throw new UnsupportedGeoIP('Only IPv4 addresses are supported.');
    }
    $dbr = wfGetDB(DB_SLAVE);
    $long_ip = IP::toUnsigned($ip_address);
    $conditions = array('begin_ip_long <= ' . $long_ip, $long_ip . ' <= end_ip_long');
    $country_code = $dbr->selectField('geoip', 'country_code', $conditions, __METHOD__);
    if (!$country_code) {
        throw new NotFoundGeoIP('Could not identify the country for the provided IP address.');
    }
    return $country_code;
}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:20,代码来源:GeoIP.php

示例7: __construct

 function __construct($address = '', $user = 0, $by = 0, $reason = '', $timestamp = '', $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0, $hideName = 0, $blockEmail = 0)
 {
     $this->mId = 0;
     # Expand valid IPv6 addresses
     $address = IP::sanitizeIP($address);
     $this->mAddress = $address;
     $this->mUser = $user;
     $this->mBy = $by;
     $this->mReason = $reason;
     $this->mTimestamp = wfTimestamp(TS_MW, $timestamp);
     $this->mAuto = $auto;
     $this->mAnonOnly = $anonOnly;
     $this->mCreateAccount = $createAccount;
     $this->mExpiry = self::decodeExpiry($expiry);
     $this->mEnableAutoblock = $enableAutoblock;
     $this->mHideName = $hideName;
     $this->mBlockEmail = $blockEmail;
     $this->mForUpdate = false;
     $this->mFromMaster = false;
     $this->mByName = false;
     $this->initialiseRange();
 }
开发者ID:BackupTheBerlios,项目名称:shoutwiki-svn,代码行数:22,代码来源:Block.php

示例8: loadParameters

 function loadParameters()
 {
     global $wgAbuseFilterIsCentral;
     $request = $this->getRequest();
     $this->mSearchUser = trim($request->getText('wpSearchUser'));
     if ($wgAbuseFilterIsCentral) {
         $this->mSearchWiki = $request->getText('wpSearchWiki');
     }
     $u = User::newFromName($this->mSearchUser);
     if ($u) {
         $this->mSearchUser = $u->getName();
         // Username normalisation
     } elseif (IP::isIPAddress($this->mSearchUser)) {
         // It's an IP
         $this->mSearchUser = IP::sanitizeIP($this->mSearchUser);
     } else {
         $this->mSearchUser = null;
     }
     $this->mSearchTitle = $request->getText('wpSearchTitle');
     $this->mSearchFilter = null;
     if (self::canSeeDetails()) {
         $this->mSearchFilter = $request->getText('wpSearchFilter');
     }
 }
开发者ID:aahashderuffy,项目名称:extensions,代码行数:24,代码来源:SpecialAbuseLog.php

示例9: secureAndSplit


//.........这里部分代码省略.........
                     } elseif (Interwiki::isValidInterwiki($x[1])) {
                         # Disallow Talk:Interwiki:x type titles...
                         return false;
                     }
                 }
             } elseif (Interwiki::isValidInterwiki($p)) {
                 if (!$firstPass) {
                     # Can't make a local interwiki link to an interwiki link.
                     # That's just crazy!
                     return false;
                 }
                 # Interwiki link
                 $dbkey = $m[2];
                 $this->mInterwiki = $wgContLang->lc($p);
                 # Redundant interwiki prefix to the local wiki
                 if ($wgLocalInterwiki !== false && 0 == strcasecmp($this->mInterwiki, $wgLocalInterwiki)) {
                     if ($dbkey == '') {
                         # Can't have an empty self-link
                         return false;
                     }
                     $this->mInterwiki = '';
                     $firstPass = false;
                     # Do another namespace split...
                     continue;
                 }
                 # If there's an initial colon after the interwiki, that also
                 # resets the default namespace
                 if ($dbkey !== '' && $dbkey[0] == ':') {
                     $this->mNamespace = NS_MAIN;
                     $dbkey = substr($dbkey, 1);
                 }
             }
             # If there's no recognized interwiki or namespace,
             # then let the colon expression be part of the title.
         }
         break;
     } while (true);
     # We already know that some pages won't be in the database!
     if ($this->mInterwiki != '' || NS_SPECIAL == $this->mNamespace) {
         $this->mArticleID = 0;
     }
     $fragment = strstr($dbkey, '#');
     if (false !== $fragment) {
         $this->setFragment($fragment);
         $dbkey = substr($dbkey, 0, strlen($dbkey) - strlen($fragment));
         # remove whitespace again: prevents "Foo_bar_#"
         # becoming "Foo_bar_"
         $dbkey = preg_replace('/_*$/', '', $dbkey);
     }
     # Reject illegal characters.
     $rxTc = self::getTitleInvalidRegex();
     if (preg_match($rxTc, $dbkey)) {
         return false;
     }
     # Pages with "/./" or "/../" appearing in the URLs will often be un-
     # reachable due to the way web browsers deal with 'relative' URLs.
     # Also, they conflict with subpage syntax.  Forbid them explicitly.
     if (strpos($dbkey, '.') !== false && ($dbkey === '.' || $dbkey === '..' || strpos($dbkey, './') === 0 || strpos($dbkey, '../') === 0 || strpos($dbkey, '/./') !== false || strpos($dbkey, '/../') !== false || substr($dbkey, -2) == '/.' || substr($dbkey, -3) == '/..')) {
         return false;
     }
     # Magic tilde sequences? Nu-uh!
     if (strpos($dbkey, '~~~') !== false) {
         return false;
     }
     # Limit the size of titles to 255 bytes. This is typically the size of the
     # underlying database field. We make an exception for special pages, which
     # don't need to be stored in the database, and may edge over 255 bytes due
     # to subpage syntax for long titles, e.g. [[Special:Block/Long name]]
     if ($this->mNamespace != NS_SPECIAL && strlen($dbkey) > 255 || strlen($dbkey) > 512) {
         return false;
     }
     # Normally, all wiki links are forced to have an initial capital letter so [[foo]]
     # and [[Foo]] point to the same place.  Don't force it for interwikis, since the
     # other site might be case-sensitive.
     $this->mUserCaseDBKey = $dbkey;
     if ($this->mInterwiki == '') {
         $dbkey = self::capitalize($dbkey, $this->mNamespace);
     }
     # Can't make a link to a namespace alone... "empty" local links can only be
     # self-links with a fragment identifier.
     if ($dbkey == '' && $this->mInterwiki == '' && $this->mNamespace != NS_MAIN) {
         return false;
     }
     // Allow IPv6 usernames to start with '::' by canonicalizing IPv6 titles.
     // IP names are not allowed for accounts, and can only be referring to
     // edits from the IP. Given '::' abbreviations and caps/lowercaps,
     // there are numerous ways to present the same IP. Having sp:contribs scan
     // them all is silly and having some show the edits and others not is
     // inconsistent. Same for talk/userpages. Keep them normalized instead.
     $dbkey = $this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK ? IP::sanitizeIP($dbkey) : $dbkey;
     // Any remaining initial :s are illegal.
     if ($dbkey !== '' && ':' == $dbkey[0]) {
         return false;
     }
     # Fill fields
     $this->mDbkeyform = $dbkey;
     $this->mUrlform = wfUrlencode($dbkey);
     $this->mTextform = str_replace('_', ' ', $dbkey);
     return true;
 }
开发者ID:namrenni,项目名称:mediawiki,代码行数:101,代码来源:Title.php

示例10: secureAndSplit


//.........这里部分代码省略.........
                     $this->mInterwiki = '';
                     $firstPass = false;
                     # Do another namespace split...
                     continue;
                 }
                 # If there's an initial colon after the interwiki, that also
                 # resets the default namespace
                 if ($dbkey !== '' && $dbkey[0] == ':') {
                     $this->mNamespace = NS_MAIN;
                     $dbkey = substr($dbkey, 1);
                 }
             }
             # If there's no recognized interwiki or namespace,
             # then let the colon expression be part of the title.
         }
         break;
     } while (true);
     # We already know that some pages won't be in the database!
     #
     if ('' != $this->mInterwiki || NS_SPECIAL == $this->mNamespace) {
         $this->mArticleID = 0;
     }
     $fragment = strstr($dbkey, '#');
     if (false !== $fragment) {
         $this->setFragment($fragment);
         $dbkey = substr($dbkey, 0, strlen($dbkey) - strlen($fragment));
         # remove whitespace again: prevents "Foo_bar_#"
         # becoming "Foo_bar_"
         $dbkey = preg_replace('/_*$/', '', $dbkey);
     }
     # Reject illegal characters.
     #
     if (preg_match($rxTc, $dbkey)) {
         return false;
     }
     /**
      * Pages with "/./" or "/../" appearing in the URLs will
      * often be unreachable due to the way web browsers deal
      * with 'relative' URLs. Forbid them explicitly.
      */
     if (strpos($dbkey, '.') !== false && ($dbkey === '.' || $dbkey === '..' || strpos($dbkey, './') === 0 || strpos($dbkey, '../') === 0 || strpos($dbkey, '/./') !== false || strpos($dbkey, '/../') !== false || substr($dbkey, -2) == '/.' || substr($dbkey, -3) == '/..')) {
         return false;
     }
     /**
      * Magic tilde sequences? Nu-uh!
      */
     if (strpos($dbkey, '~~~') !== false) {
         return false;
     }
     /**
      * Limit the size of titles to 255 bytes.
      * This is typically the size of the underlying database field.
      * We make an exception for special pages, which don't need to be stored
      * in the database, and may edge over 255 bytes due to subpage syntax 
      * for long titles, e.g. [[Special:Block/Long name]]
      */
     if ($this->mNamespace != NS_SPECIAL && strlen($dbkey) > 255 || strlen($dbkey) > 512) {
         return false;
     }
     /**
      * Normally, all wiki links are forced to have
      * an initial capital letter so [[foo]] and [[Foo]]
      * point to the same place.
      *
      * Don't force it for interwikis, since the other
      * site might be case-sensitive.
      */
     $this->mUserCaseDBKey = $dbkey;
     // INTL: By default, capitalize first letter of titles with namespace of NS_MEDIAWIKI.  A little bit of a hack
     // to get around the fact that we set wgCapitalLinks to false to international sites.  We do this because not all
     // languages capitalize the first letter of a title
     if ($this->mNamespace == NS_MEDIAWIKI || $wgCapitalLinks && $this->mInterwiki == '') {
         $dbkey = $wgContLang->ucfirst($dbkey);
     }
     /**
      * Can't make a link to a namespace alone...
      * "empty" local links can only be self-links
      * with a fragment identifier.
      */
     if ($dbkey == '' && $this->mInterwiki == '' && $this->mNamespace != NS_MAIN) {
         return false;
     }
     // Allow IPv6 usernames to start with '::' by canonicalizing IPv6 titles.
     // IP names are not allowed for accounts, and can only be referring to
     // edits from the IP. Given '::' abbreviations and caps/lowercaps,
     // there are numerous ways to present the same IP. Having sp:contribs scan
     // them all is silly and having some show the edits and others not is
     // inconsistent. Same for talk/userpages. Keep them normalized instead.
     $dbkey = $this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK ? IP::sanitizeIP($dbkey) : $dbkey;
     // Any remaining initial :s are illegal.
     if ($dbkey !== '' && ':' == $dbkey[0]) {
         return false;
     }
     # Fill fields
     $this->mDbkeyform = $dbkey;
     $this->mUrlform = wfUrlencode($dbkey);
     //XXCHANGED
     $this->mTextform = str_replace('-', ' ', $dbkey);
     return true;
 }
开发者ID:ErdemA,项目名称:wikihow,代码行数:101,代码来源:Title.php

示例11: getName

 /**
  * Get the user name, or the IP for anons
  */
 function getName()
 {
     if (!$this->mDataLoaded && $this->mFrom == 'name') {
         # Special case optimisation
         return $this->mName;
     } else {
         $this->load();
         if ($this->mName === false) {
             # Clean up IPs
             $this->mName = IP::sanitizeIP(wfGetIP());
         }
         return $this->mName;
     }
 }
开发者ID:BackupTheBerlios,项目名称:shoutwiki-svn,代码行数:17,代码来源:User.php

示例12: parseTarget

 /**
  * From an existing Block, get the target and the type of target.
  * Note that, except for null, it is always safe to treat the target
  * as a string; for User objects this will return User::__toString()
  * which in turn gives User::getName().
  *
  * @param string|int|User|null $target
  * @return array( User|String|null, Block::TYPE_ constant|null )
  */
 public static function parseTarget($target)
 {
     # We may have been through this before
     if ($target instanceof User) {
         if (IP::isValid($target->getName())) {
             return array($target, self::TYPE_IP);
         } else {
             return array($target, self::TYPE_USER);
         }
     } elseif ($target === null) {
         return array(null, null);
     }
     $target = trim($target);
     if (IP::isValid($target)) {
         # We can still create a User if it's an IP address, but we need to turn
         # off validation checking (which would exclude IP addresses)
         return array(User::newFromName(IP::sanitizeIP($target), false), Block::TYPE_IP);
     } elseif (IP::isValidBlock($target)) {
         # Can't create a User from an IP range
         return array(IP::sanitizeRange($target), Block::TYPE_RANGE);
     }
     # Consider the possibility that this is not a username at all
     # but actually an old subpage (bug #29797)
     if (strpos($target, '/') !== false) {
         # An old subpage, drill down to the user behind it
         $parts = explode('/', $target);
         $target = $parts[0];
     }
     $userObj = User::newFromName($target);
     if ($userObj instanceof User) {
         # Note that since numbers are valid usernames, a $target of "12345" will be
         # considered a User.  If you want to pass a block ID, prepend a hash "#12345",
         # since hash characters are not valid in usernames or titles generally.
         return array($userObj, Block::TYPE_USER);
     } elseif (preg_match('/^#\\d+$/', $target)) {
         # Autoblock reference in the form "#12345"
         return array(substr($target, 1), Block::TYPE_AUTO);
     } else {
         # WTF?
         return array(null, null);
     }
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:51,代码来源:Block.php

示例13: processImportForm

 /**
  *
  * @global OutputPage $wgOut
  * @param string $action
  * @param PonyDocsProduct $product
  * @param mixed $manual PonyDocsManual or NULL
  */
 private function processImportForm($action, $product, $manual)
 {
     global $wgOut, $wgUser;
     $importer = new PonyDocsStaticDocImporter(PONYDOCS_STATIC_DIR);
     if (isset($_POST['version']) && isset($_POST['product']) && (is_null($manual) || isset($_POST['manual']))) {
         switch ($action) {
             case "add":
                 if (PonyDocsProductVersion::IsVersion($_POST['product'], $_POST['version'])) {
                     $wgOut->addHTML('<h3>Results of Import</h3>');
                     // Okay, let's make sure we have file provided
                     if (!isset($_FILES['archivefile']) || $_FILES['archivefile']['error'] != 0) {
                         $wgOut->addHTML('There was a problem using your uploaded file. Make sure you uploaded a file and try again.');
                     } else {
                         try {
                             if (is_null($manual)) {
                                 $importer->importFile($_FILES['archivefile']['tmp_name'], $_POST['product'], $_POST['version']);
                                 $wgOut->addHTML("Success: imported archive for {$_POST['product']} version {$_POST['version']}");
                             } else {
                                 $importer->importFile($_FILES['archivefile']['tmp_name'], $_POST['product'], $_POST['version'], $_POST['manual']);
                                 $wgOut->addHTML("Success: imported archive for {$_POST['product']} version {$_POST['version']}" . " manual {$_POST['manual']}");
                             }
                         } catch (Exception $e) {
                             $wgOut->addHTML('Error: ' . $e->getMessage());
                             error_log('WARNING [ponydocs] [staticdocs] [' . __METHOD__ . '] action="add" status="error"' . ' message="' . addcslashes($e->getMessage(), '"') . '"');
                         }
                     }
                 }
                 break;
             case "remove":
                 //Loading product versions for WEB-10732
                 PonyDocsProductVersion::LoadVersionsForProduct($_POST['product']);
                 if (PonyDocsProductVersion::IsVersion($_POST['product'], $_POST['version'])) {
                     $wgOut->addHTML('<h3>Results of Deletion</h3>');
                     try {
                         if (is_null($manual)) {
                             $importer->removeVersion($_POST['product'], $_POST['version']);
                             $wgOut->addHTML("Successfully deleted {$_POST['product']} version {$_POST['version']}");
                         } else {
                             $importer->removeVersion($_POST['product'], $_POST['version'], $_POST['manual']);
                             $wgOut->addHTML("Successfully deleted {$_POST['product']} version {$_POST['version']}" . " manual {$_POST['manual']}");
                         }
                     } catch (Exception $e) {
                         $wgOut->addHTML('Error: ' . $e->getMessage());
                         error_log('WARNING [ponydocs] [staticdocs] [' . __METHOD__ . '] action="remove" status="error"' . ' message="' . addcslashes($e->getMessage(), '"') . '"');
                     }
                 } else {
                     $wgOut->addHTML("Error: Version {$_POST['version']} does not exist, or is not accessible");
                     error_log('WARNING [ponydocs] [staticdocs] [' . __METHOD__ . '] action="remove" status="error"' . ' message="version ' . $_POST['version'] . ' does not exist, or is not accessible"' . ' username="' . $wgUser->getName() . '"' . ' ip="' . IP::sanitizeIP(wfGetIP()) . '"');
                 }
                 break;
         }
         $this->clearProductCache($_POST['product'], $_POST['version']);
     }
 }
开发者ID:Velody,项目名称:ponydocs,代码行数:61,代码来源:SpecialStaticDocImport.php

示例14: addXffBlocks

 protected function addXffBlocks()
 {
     static $inited = false;
     if ($inited) {
         return;
     }
     $inited = true;
     $blockList = array(array('target' => '70.2.0.0/16', 'type' => Block::TYPE_RANGE, 'desc' => 'Range Hardblock', 'ACDisable' => false, 'isHardblock' => true, 'isAutoBlocking' => false), array('target' => '2001:4860:4001::/48', 'type' => Block::TYPE_RANGE, 'desc' => 'Range6 Hardblock', 'ACDisable' => false, 'isHardblock' => true, 'isAutoBlocking' => false), array('target' => '60.2.0.0/16', 'type' => Block::TYPE_RANGE, 'desc' => 'Range Softblock with AC Disabled', 'ACDisable' => true, 'isHardblock' => false, 'isAutoBlocking' => false), array('target' => '50.2.0.0/16', 'type' => Block::TYPE_RANGE, 'desc' => 'Range Softblock', 'ACDisable' => false, 'isHardblock' => false, 'isAutoBlocking' => false), array('target' => '50.1.1.1', 'type' => Block::TYPE_IP, 'desc' => 'Exact Softblock', 'ACDisable' => false, 'isHardblock' => false, 'isAutoBlocking' => false));
     foreach ($blockList as $insBlock) {
         $target = $insBlock['target'];
         if ($insBlock['type'] === Block::TYPE_IP) {
             $target = User::newFromName(IP::sanitizeIP($target), false)->getName();
         } elseif ($insBlock['type'] === Block::TYPE_RANGE) {
             $target = IP::sanitizeRange($target);
         }
         $block = new Block();
         $block->setTarget($target);
         $block->setBlocker('testblocker@global');
         $block->mReason = $insBlock['desc'];
         $block->mExpiry = 'infinity';
         $block->prevents('createaccount', $insBlock['ACDisable']);
         $block->isHardblock($insBlock['isHardblock']);
         $block->isAutoblocking($insBlock['isAutoBlocking']);
         $block->insert();
     }
 }
开发者ID:Habatchii,项目名称:wikibase-for-mediawiki,代码行数:26,代码来源:BlockTest.php

示例15: renameIPAddress

 public function renameIPAddress()
 {
     wfProfileIn(__METHOD__);
     if (!$this->checkRequest()) {
         wfProfileOut(__METHOD__);
         return;
     }
     $ipAddr = $this->request->getVal('user');
     if (!IP::isIPAddress($ipAddr)) {
         $this->response->setVal('success', false);
         $this->response->setVal('errorMsg', wfMessage('coppatool-invalid-ip')->plain());
         wfProfileOut(__METHOD__);
         return;
     }
     $ipAddr = IP::sanitizeIP($ipAddr);
     $newIpAddr = '0.0.0.0';
     $wikiIDs = RenameUserHelper::lookupIPActivity($ipAddr);
     $taskParams = ['requestor_id' => $this->wg->User->getID(), 'requestor_name' => $this->wg->User->getName(), 'rename_user_id' => 0, 'rename_old_name' => $ipAddr, 'rename_new_name' => $newIpAddr, 'rename_ip' => true, 'notify_renamed' => false, 'reason' => wfMessage('coppatool-reason')->plain()];
     $task = (new UserRenameTask())->setPriority(\Wikia\Tasks\Queues\PriorityQueue::NAME);
     $task->call('renameUser', $wikiIDs, $taskParams);
     $taskID = $task->queue();
     $this->response->setVal('success', true);
     $this->response->setVal('resultMsg', wfMessage('coppatool-rename-ip-success', $taskID)->plain());
     wfProfileOut(__METHOD__);
 }
开发者ID:yusufchang,项目名称:app,代码行数:25,代码来源:CoppaToolController.class.php


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