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


PHP Block::insert方法代码示例

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


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

示例1: test_delete_block

 public function test_delete_block()
 {
     $params = array('title' => $this->title, 'type' => $this->type);
     $block = new Block($params);
     $block->insert();
     $count = DB::get_value('SELECT count(*) FROM {blocks}');
     $block->delete();
     $this->assert_equal($count - 1, DB::get_value('SELECT count(*) FROM {blocks}'), 'Count of blocks should decrease by one');
 }
开发者ID:habari,项目名称:tests,代码行数:9,代码来源:test_block.php

示例2: addDBData

 public function addDBData()
 {
     for ($i = 1; $i <= 4; $i++) {
         $this->localUsers[] = $this->getMutableTestUser()->getUser();
     }
     $sysop = static::getTestSysop()->getUser();
     $block = new Block(['address' => $this->localUsers[2]->getName(), 'by' => $sysop->getId(), 'reason' => __METHOD__, 'expiry' => '1 day', 'hideName' => false]);
     $block->insert();
     $block = new Block(['address' => $this->localUsers[3]->getName(), 'by' => $sysop->getId(), 'reason' => __METHOD__, 'expiry' => '1 day', 'hideName' => true]);
     $block->insert();
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:11,代码来源:LocalIdLookupTest.php

示例3: addDBData

 public function addDBData()
 {
     for ($i = 1; $i <= 4; $i++) {
         $user = User::newFromName("UTLocalIdLookup{$i}");
         if ($user->getId() == 0) {
             $user->addToDatabase();
         }
         $this->localUsers["UTLocalIdLookup{$i}"] = $user->getId();
     }
     User::newFromName('UTLocalIdLookup1')->addGroup('local-id-lookup-test');
     $block = new Block(array('address' => 'UTLocalIdLookup3', 'by' => User::idFromName('UTSysop'), 'reason' => __METHOD__, 'expiry' => '1 day', 'hideName' => false));
     $block->insert();
     $block = new Block(array('address' => 'UTLocalIdLookup4', 'by' => User::idFromName('UTSysop'), 'reason' => __METHOD__, 'expiry' => '1 day', 'hideName' => true));
     $block->insert();
 }
开发者ID:Acidburn0zzz,项目名称:mediawiki,代码行数:15,代码来源:LocalIdLookupTest.php

示例4: execute

 function execute($par)
 {
     global $wgRequest, $wgOut, $wgBlockOpenProxies, $wgProxyKey;
     $this->setHeaders();
     $this->outputHeader();
     $ip = wfGetIP();
     if (!$wgBlockOpenProxies || $wgRequest->getText('ip') != md5($ip . $wgProxyKey)) {
         $wgOut->addWikiMsg('proxyblocker-disabled');
         return;
     }
     $user = User::newFromName(wfMsgForContent('proxyblocker'));
     if (!$user->isLoggedIn()) {
         $user->addToDatabase();
     }
     $id = $user->getId();
     $reason = wfMsg('proxyblockreason');
     $block = new Block($ip, 0, $id, $reason, wfTimestampNow());
     $block->insert();
     $wgOut->addWikiMsg('proxyblocksuccess');
 }
开发者ID:GodelDesign,项目名称:Godel,代码行数:20,代码来源:SpecialBlockme.php

示例5: execute

 function execute($par)
 {
     global $wgBlockOpenProxies, $wgProxyKey;
     $this->setHeaders();
     $this->outputHeader();
     $ip = $this->getRequest()->getIP();
     if (!$wgBlockOpenProxies || $this->getRequest()->getText('ip') != md5($ip . $wgProxyKey)) {
         $this->getOutput()->addWikiMsg('proxyblocker-disabled');
         return;
     }
     $user = User::newFromName($this->msg('proxyblocker')->inContentLanguage()->text());
     # FIXME: newFromName could return false on a badly configured wiki.
     if (!$user->isLoggedIn()) {
         $user->addToDatabase();
     }
     $block = new Block();
     $block->setTarget($ip);
     $block->setBlocker($user);
     $block->mReason = $this->msg('proxyblockreason')->inContentLanguage()->text();
     $block->insert();
     $this->getOutput()->addWikiMsg('proxyblocksuccess');
 }
开发者ID:Grprashanthkumar,项目名称:ColfusionWeb,代码行数:22,代码来源:SpecialBlockme.php

示例6: wfSpecialBlockme

/**
 *
 */
function wfSpecialBlockme()
{
    global $wgIP, $wgBlockOpenProxies, $wgOut, $wgProxyKey;
    if (!$wgBlockOpenProxies || $_REQUEST['ip'] != md5($wgIP . $wgProxyKey)) {
        $wgOut->addWikiText(wfMsg("disabled"));
        return;
    }
    $blockerName = wfMsg("proxyblocker");
    $reason = wfMsg("proxyblockreason");
    $success = wfMsg("proxyblocksuccess");
    $u = User::newFromName($blockerName);
    $id = $u->idForName();
    if (!$id) {
        $u = User::newFromName($blockerName);
        $u->addToDatabase();
        $u->setPassword(bin2hex(mt_rand(0, 0x7fffffff)));
        $u->saveSettings();
        $id = $u->getID();
    }
    $block = new Block($wgIP, 0, $id, $reason, wfTimestampNow());
    $block->insert();
    $wgOut->addWikiText($success);
}
开发者ID:BackupTheBerlios,项目名称:openzaurus-svn,代码行数:26,代码来源:SpecialBlockme.php

示例7: wfSpecialBlockme

/**
 *
 */
function wfSpecialBlockme()
{
    global $wgRequest, $wgBlockOpenProxies, $wgOut, $wgProxyKey;
    $ip = wfGetIP();
    if (!$wgBlockOpenProxies || $wgRequest->getText('ip') != md5($ip . $wgProxyKey)) {
        $wgOut->addWikiMsg('proxyblocker-disabled');
        return;
    }
    $blockerName = wfMsg("proxyblocker");
    $reason = wfMsg("proxyblockreason");
    $u = User::newFromName($blockerName);
    $id = $u->idForName();
    if (!$id) {
        $u = User::newFromName($blockerName);
        $u->addToDatabase();
        $u->setPassword(bin2hex(mt_rand(0, 0x7fffffff)));
        $u->saveSettings();
        $id = $u->getID();
    }
    $block = new Block($ip, 0, $id, $reason, wfTimestampNow());
    $block->insert();
    $wgOut->addWikiMsg("proxyblocksuccess");
}
开发者ID:amjadtbssm,项目名称:website,代码行数:26,代码来源:SpecialBlockme.php

示例8: doMassUserBlock

 /**
  * Block a list of selected users
  * @param array $users
  * @param string $reason
  * @param string $tag replaces user pages
  * @param string $talkTag replaces user talk pages
  * @returns array, list of html-safe usernames
  */
 public static function doMassUserBlock($users, $reason = '', $tag = '', $talkTag = '')
 {
     global $wgUser;
     $counter = $blockSize = 0;
     $safeUsers = array();
     $log = new LogPage('block');
     foreach ($users as $name) {
         # Enforce limits
         $counter++;
         $blockSize++;
         # Lets not go *too* fast
         if ($blockSize >= 20) {
             $blockSize = 0;
             wfWaitForSlaves(5);
         }
         $u = User::newFromName($name, false);
         // If user doesn't exist, it ought to be an IP then
         if (is_null($u) || !$u->getId() && !IP::isIPAddress($u->getName())) {
             continue;
         }
         $userTitle = $u->getUserPage();
         $userTalkTitle = $u->getTalkPage();
         $userpage = new Article($userTitle);
         $usertalk = new Article($userTalkTitle);
         $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]';
         $expirestr = $u->getId() ? 'indefinite' : '1 week';
         $expiry = Block::parseExpiryInput($expirestr);
         $anonOnly = IP::isIPAddress($u->getName()) ? 1 : 0;
         // Create the block
         $block = new Block($u->getName(), $u->getId(), $wgUser->getId(), $reason, wfTimestampNow(), 0, $expiry, $anonOnly, 1, 1, 0, 0);
         $oldblock = Block::newFromDB($u->getName(), $u->getId());
         if (!$oldblock) {
             $block->insert();
             # Prepare log parameters
             $logParams = array();
             $logParams[] = $expirestr;
             if ($anonOnly) {
                 $logParams[] = 'anononly';
             }
             $logParams[] = 'nocreate';
             # Add log entry
             $log->addEntry('block', $userTitle, $reason, $logParams);
         }
         # Tag userpage! (check length to avoid mistakes)
         if (strlen($tag) > 2) {
             $userpage->doEdit($tag, $reason, EDIT_MINOR);
         }
         if (strlen($talkTag) > 2) {
             $usertalk->doEdit($talkTag, $reason, EDIT_MINOR);
         }
     }
     return $safeUsers;
 }
开发者ID:rocLv,项目名称:conference,代码行数:61,代码来源:SpecialBlockip.php

示例9: testCheckAccountCreatePermissions

 public function testCheckAccountCreatePermissions()
 {
     global $wgGroupPermissions;
     $this->stashMwGlobals(['wgGroupPermissions']);
     $this->initializeManager(true);
     $wgGroupPermissions['*']['createaccount'] = true;
     $this->assertEquals(\Status::newGood(), $this->manager->checkAccountCreatePermissions(new \User()));
     $this->setMwGlobals(['wgReadOnly' => 'Because']);
     $this->assertEquals(\Status::newFatal('readonlytext', 'Because'), $this->manager->checkAccountCreatePermissions(new \User()));
     $this->setMwGlobals(['wgReadOnly' => false]);
     $wgGroupPermissions['*']['createaccount'] = false;
     $status = $this->manager->checkAccountCreatePermissions(new \User());
     $this->assertFalse($status->isOK());
     $this->assertTrue($status->hasMessage('badaccess-groups'));
     $wgGroupPermissions['*']['createaccount'] = true;
     $user = \User::newFromName('UTBlockee');
     if ($user->getID() == 0) {
         $user->addToDatabase();
         \TestUser::setPasswordForUser($user, 'UTBlockeePassword');
         $user->saveSettings();
     }
     $oldBlock = \Block::newFromTarget('UTBlockee');
     if ($oldBlock) {
         // An old block will prevent our new one from saving.
         $oldBlock->delete();
     }
     $blockOptions = ['address' => 'UTBlockee', 'user' => $user->getID(), 'reason' => __METHOD__, 'expiry' => time() + 100500, 'createAccount' => true];
     $block = new \Block($blockOptions);
     $block->insert();
     $status = $this->manager->checkAccountCreatePermissions($user);
     $this->assertFalse($status->isOK());
     $this->assertTrue($status->hasMessage('cantcreateaccount-text'));
     $blockOptions = ['address' => '127.0.0.0/24', 'reason' => __METHOD__, 'expiry' => time() + 100500, 'createAccount' => true];
     $block = new \Block($blockOptions);
     $block->insert();
     $scopeVariable = new \ScopedCallback([$block, 'delete']);
     $status = $this->manager->checkAccountCreatePermissions(new \User());
     $this->assertFalse($status->isOK());
     $this->assertTrue($status->hasMessage('cantcreateaccount-range-text'));
     \ScopedCallback::consume($scopeVariable);
     $this->setMwGlobals(['wgEnableDnsBlacklist' => true, 'wgDnsBlacklistUrls' => ['local.wmftest.net'], 'wgProxyWhitelist' => []]);
     $status = $this->manager->checkAccountCreatePermissions(new \User());
     $this->assertFalse($status->isOK());
     $this->assertTrue($status->hasMessage('sorbs_create_account_reason'));
     $this->setMwGlobals('wgProxyWhitelist', ['127.0.0.1']);
     $status = $this->manager->checkAccountCreatePermissions(new \User());
     $this->assertTrue($status->isGood());
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:48,代码来源:AuthManagerTest.php

示例10: testRangeBlock

 public function testRangeBlock()
 {
     $blockOptions = ['address' => '127.0.0.0/24', 'reason' => __METHOD__, 'expiry' => time() + 100500, 'createAccount' => true];
     $block = new \Block($blockOptions);
     $block->insert();
     $scopeVariable = new \Wikimedia\ScopedCallback([$block, 'delete']);
     $user = \User::newFromName('UTNormalUser');
     if ($user->getID() == 0) {
         $user->addToDatabase();
         \TestUser::setPasswordForUser($user, 'UTNormalUserPassword');
         $user->saveSettings();
     }
     $this->setMwGlobals(['wgUser' => $user]);
     $newuser = \User::newFromName('RandomUser');
     $provider = new CheckBlocksSecondaryAuthenticationProvider(['blockDisablesLogin' => true]);
     $provider->setLogger(new \Psr\Log\NullLogger());
     $provider->setConfig(new \HashConfig());
     $provider->setManager(AuthManager::singleton());
     $ret = $provider->beginSecondaryAuthentication($user, []);
     $this->assertEquals(AuthenticationResponse::FAIL, $ret->status);
     $status = $provider->testUserForCreation($newuser, AuthManager::AUTOCREATE_SOURCE_SESSION);
     $this->assertInstanceOf('StatusValue', $status);
     $this->assertFalse($status->isOK());
     $this->assertTrue($status->hasMessage('cantcreateaccount-range-text'));
     $status = $provider->testUserForCreation($newuser, false);
     $this->assertInstanceOf('StatusValue', $status);
     $this->assertFalse($status->isOK());
     $this->assertTrue($status->hasMessage('cantcreateaccount-range-text'));
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:29,代码来源:CheckBlocksSecondaryAuthenticationProviderTest.php

示例11: doLocalSuppression

 /**
  * Suppresses a local account of a user.
  *
  * @param $suppress Bool
  * @param $wiki String
  * @param $by String
  * @param $reason String
  * @return Array|null Error array on failure
  */
 public function doLocalSuppression($suppress, $wiki, $by, $reason)
 {
     global $wgConf;
     $lb = wfGetLB($wiki);
     $dbw = $lb->getConnection(DB_MASTER, array(), $wiki);
     $data = $this->localUserData($wiki);
     if ($suppress) {
         list(, $lang) = $wgConf->siteFromDB($wiki);
         $langNames = Language::fetchLanguageNames();
         $lang = isset($langNames[$lang]) ? $lang : 'en';
         $blockReason = wfMessage('centralauth-admin-suppressreason', $by, $reason)->inLanguage($lang)->text();
         $block = new Block(array('address' => $this->mName, 'user' => $data['id'], 'reason' => $blockReason, 'timestamp' => wfTimestampNow(), 'expiry' => $dbw->getInfinity(), 'createAccount' => true, 'enableAutoblock' => true, 'hideName' => true, 'blockEmail' => true, 'byText' => $by));
         # On normal block, BlockIp hook would be run here, but doing
         # that from CentralAuth doesn't seem a good idea...
         if (!$block->insert($dbw)) {
             return array('ipb_already_blocked');
         }
         # Ditto for BlockIpComplete hook.
         RevisionDeleteUser::suppressUserName($this->mName, $data['id'], $dbw);
         # Locally log to suppress ?
     } else {
         $dbw->delete('ipblocks', array('ipb_user' => $data['id'], 'ipb_by' => 0, 'ipb_deleted' => true), __METHOD__);
         // Unsuppress only if unblocked
         if ($dbw->affectedRows()) {
             RevisionDeleteUser::unsuppressUserName($this->mName, $data['id'], $dbw);
         }
     }
     return null;
 }
开发者ID:NDKilla,项目名称:mediawiki-extensions-CentralAuth,代码行数:38,代码来源:CentralAuthUser.php

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

示例13: processForm

 /**
  * Given the form data, actually implement a block
  * @param  $data Array
  * @param  $context IContextSource
  * @return Bool|String
  */
 public static function processForm(array $data, IContextSource $context)
 {
     global $wgBlockAllowsUTEdit;
     $performer = $context->getUser();
     // Handled by field validator callback
     // self::validateTargetField( $data['Target'] );
     # This might have been a hidden field or a checkbox, so interesting data
     # can come from it
     $data['Confirm'] = !in_array($data['Confirm'], array('', '0', null, false), true);
     list($target, $type) = self::getTargetAndType($data['Target']);
     if ($type == Block::TYPE_USER) {
         $user = $target;
         $target = $user->getName();
         $userId = $user->getId();
         # Give admins a heads-up before they go and block themselves.  Much messier
         # to do this for IPs, but it's pretty unlikely they'd ever get the 'block'
         # permission anyway, although the code does allow for it.
         # Note: Important to use $target instead of $data['Target']
         # since both $data['PreviousTarget'] and $target are normalized
         # but $data['target'] gets overriden by (non-normalized) request variable
         # from previous request.
         if ($target === $performer->getName() && ($data['PreviousTarget'] !== $target || !$data['Confirm'])) {
             return array('ipb-blockingself');
         }
     } elseif ($type == Block::TYPE_RANGE) {
         $userId = 0;
     } elseif ($type == Block::TYPE_IP) {
         $target = $target->getName();
         $userId = 0;
     } else {
         # This should have been caught in the form field validation
         return array('badipaddress');
     }
     if (strlen($data['Expiry']) == 0 || strlen($data['Expiry']) > 50 || !self::parseExpiryInput($data['Expiry'])) {
         return array('ipb_expiry_invalid');
     }
     if (!isset($data['DisableEmail'])) {
         $data['DisableEmail'] = false;
     }
     # If the user has done the form 'properly', they won't even have been given the
     # option to suppress-block unless they have the 'hideuser' permission
     if (!isset($data['HideUser'])) {
         $data['HideUser'] = false;
     }
     if ($data['HideUser']) {
         if (!$performer->isAllowed('hideuser')) {
             # this codepath is unreachable except by a malicious user spoofing forms,
             # or by race conditions (user has oversight and sysop, loads block form,
             # and is de-oversighted before submission); so need to fail completely
             # rather than just silently disable hiding
             return array('badaccess-group0');
         }
         # Recheck params here...
         if ($type != Block::TYPE_USER) {
             $data['HideUser'] = false;
             # IP users should not be hidden
         } elseif (!in_array($data['Expiry'], array('infinite', 'infinity', 'indefinite'))) {
             # Bad expiry.
             return array('ipb_expiry_temp');
         } elseif ($user->getEditCount() > self::HIDEUSER_CONTRIBLIMIT) {
             # Typically, the user should have a handful of edits.
             # Disallow hiding users with many edits for performance.
             return array('ipb_hide_invalid');
         } elseif (!$data['Confirm']) {
             return array('ipb-confirmhideuser');
         }
     }
     # Create block object.
     $block = new Block();
     $block->setTarget($target);
     $block->setBlocker($performer);
     $block->mReason = $data['Reason'][0];
     $block->mExpiry = self::parseExpiryInput($data['Expiry']);
     $block->prevents('createaccount', $data['CreateAccount']);
     $block->prevents('editownusertalk', !$wgBlockAllowsUTEdit || $data['DisableUTEdit']);
     $block->prevents('sendemail', $data['DisableEmail']);
     $block->isHardblock($data['HardBlock']);
     $block->isAutoblocking($data['AutoBlock']);
     $block->mHideName = $data['HideUser'];
     if (!wfRunHooks('BlockIp', array(&$block, &$performer))) {
         return array('hookaborted');
     }
     # Try to insert block. Is there a conflicting block?
     $status = $block->insert();
     if (!$status) {
         # Show form unless the user is already aware of this...
         if (!$data['Confirm'] || array_key_exists('PreviousTarget', $data) && $data['PreviousTarget'] !== $target) {
             return array(array('ipb_already_blocked', $block->getTarget()));
             # Otherwise, try to update the block...
         } else {
             # This returns direct blocks before autoblocks/rangeblocks, since we should
             # be sure the user is blocked by now it should work for our purposes
             $currentBlock = Block::newFromTarget($target);
             if ($block->equals($currentBlock)) {
//.........这里部分代码省略.........
开发者ID:Tjorriemorrie,项目名称:app,代码行数:101,代码来源:SpecialBlock.php

示例14: doBlock

 /**
  * Backend block code.
  * $userID and $expiry will be filled accordingly
  * @return array(message key, arguments) on failure, empty array on success
  */
 function doBlock(&$userId = null, &$expiry = null)
 {
     global $wgUser, $wgSysopUserBans, $wgSysopRangeBans;
     $userId = 0;
     # Expand valid IPv6 addresses, usernames are left as is
     $this->BlockAddress = IP::sanitizeIP($this->BlockAddress);
     # isIPv4() and IPv6() are used for final validation
     $rxIP4 = '\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}';
     $rxIP6 = '\\w{1,4}:\\w{1,4}:\\w{1,4}:\\w{1,4}:\\w{1,4}:\\w{1,4}:\\w{1,4}:\\w{1,4}';
     $rxIP = "({$rxIP4}|{$rxIP6})";
     # Check for invalid specifications
     if (!preg_match("/^{$rxIP}\$/", $this->BlockAddress)) {
         $matches = array();
         if (preg_match("/^({$rxIP4})\\/(\\d{1,2})\$/", $this->BlockAddress, $matches)) {
             # IPv4
             if ($wgSysopRangeBans) {
                 if (!IP::isIPv4($this->BlockAddress) || $matches[2] < 16 || $matches[2] > 32) {
                     return array('ip_range_invalid');
                 }
                 $this->BlockAddress = Block::normaliseRange($this->BlockAddress);
             } else {
                 # Range block illegal
                 return array('range_block_disabled');
             }
         } else {
             if (preg_match("/^({$rxIP6})\\/(\\d{1,3})\$/", $this->BlockAddress, $matches)) {
                 # IPv6
                 if ($wgSysopRangeBans) {
                     if (!IP::isIPv6($this->BlockAddress) || $matches[2] < 64 || $matches[2] > 128) {
                         return array('ip_range_invalid');
                     }
                     $this->BlockAddress = Block::normaliseRange($this->BlockAddress);
                 } else {
                     # Range block illegal
                     return array('range_block_disabled');
                 }
             } else {
                 # Username block
                 if ($wgSysopUserBans) {
                     $user = User::newFromName($this->BlockAddress);
                     if (!is_null($user) && $user->getID()) {
                         # Use canonical name
                         $userId = $user->getID();
                         $this->BlockAddress = $user->getName();
                     } else {
                         return array('nosuchusershort', htmlspecialchars($user ? $user->getName() : $this->BlockAddress));
                     }
                 } else {
                     return array('badipaddress');
                 }
             }
         }
     }
     $reasonstr = $this->BlockReasonList;
     if ($reasonstr != 'other' && $this->BlockReason != '') {
         // Entry from drop down menu + additional comment
         $reasonstr .= ': ' . $this->BlockReason;
     } elseif ($reasonstr == 'other') {
         $reasonstr = $this->BlockReason;
     }
     $expirestr = $this->BlockExpiry;
     if ($expirestr == 'other') {
         $expirestr = $this->BlockOther;
     }
     if (strlen($expirestr) == 0) {
         return array('ipb_expiry_invalid');
     }
     if ($expirestr == 'infinite' || $expirestr == 'indefinite') {
         $expiry = Block::infinity();
     } else {
         # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1
         $expiry = strtotime($expirestr);
         if ($expiry < 0 || $expiry === false) {
             return array('ipb_expiry_invalid');
         }
         $expiry = wfTimestamp(TS_MW, $expiry);
     }
     # Create block
     # Note: for a user block, ipb_address is only for display purposes
     $block = new Block($this->BlockAddress, $userId, $wgUser->getID(), $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly, $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName, $this->BlockEmail);
     if (wfRunHooks('BlockIp', array(&$block, &$wgUser))) {
         if (!$block->insert()) {
             return array('ipb_already_blocked', htmlspecialchars($this->BlockAddress));
         }
         wfRunHooks('BlockIpComplete', array($block, $wgUser));
         # Prepare log parameters
         $logParams = array();
         $logParams[] = $expirestr;
         $logParams[] = $this->blockLogFlags();
         # Make log entry, if the name is hidden, put it in the oversight log
         $log_type = $this->BlockHideName ? 'oversight' : 'block';
         $log = new LogPage($log_type);
         $log->addEntry('block', Title::makeTitle(NS_USER, $this->BlockAddress), $reasonstr, $logParams);
         # Report to the user
         return array();
//.........这里部分代码省略.........
开发者ID:ErdemA,项目名称:wikihow,代码行数:101,代码来源:SpecialBlockip.php

示例15: doAutoblock

 /**
  * Autoblocks the given IP, referring to this Block.
  *
  * @param $autoblockIP String: the IP to autoblock.
  * @param $justInserted Boolean: the main block was just inserted
  * @return Boolean: whether or not an autoblock was inserted.
  */
 public function doAutoblock($autoblockIP, $justInserted = false)
 {
     # If autoblocks are disabled, go away.
     if (!$this->mEnableAutoblock) {
         return;
     }
     # Check for presence on the autoblock whitelist
     if (Block::isWhitelistedFromAutoblocks($autoblockIP)) {
         return;
     }
     ## Allow hooks to cancel the autoblock.
     if (!wfRunHooks('AbortAutoblock', array($autoblockIP, &$this))) {
         wfDebug("Autoblock aborted by hook.\n");
         return false;
     }
     # It's okay to autoblock. Go ahead and create/insert the block.
     $ipblock = Block::newFromDB($autoblockIP);
     if ($ipblock) {
         # If the user is already blocked. Then check if the autoblock would
         # exceed the user block. If it would exceed, then do nothing, else
         # prolong block time
         if ($this->mExpiry && $this->mExpiry < Block::getAutoblockExpiry($ipblock->mTimestamp)) {
             return;
         }
         # Just update the timestamp
         if (!$justInserted) {
             $ipblock->updateTimestamp();
         }
         return;
     } else {
         $ipblock = new Block();
     }
     # Make a new block object with the desired properties
     wfDebug("Autoblocking {$this->mAddress}@" . $autoblockIP . "\n");
     $ipblock->mAddress = $autoblockIP;
     $ipblock->mUser = 0;
     $ipblock->mBy = $this->mBy;
     $ipblock->mByName = $this->mByName;
     $ipblock->mReason = wfMsgForContent('autoblocker', $this->mAddress, $this->mReason);
     $ipblock->mTimestamp = wfTimestampNow();
     $ipblock->mAuto = 1;
     $ipblock->mCreateAccount = $this->mCreateAccount;
     # Continue suppressing the name if needed
     $ipblock->mHideName = $this->mHideName;
     $ipblock->mAllowUsertalk = $this->mAllowUsertalk;
     # If the user is already blocked with an expiry date, we don't
     # want to pile on top of that!
     if ($this->mExpiry) {
         $ipblock->mExpiry = min($this->mExpiry, Block::getAutoblockExpiry($this->mTimestamp));
     } else {
         $ipblock->mExpiry = Block::getAutoblockExpiry($this->mTimestamp);
     }
     # Insert it
     return $ipblock->insert();
 }
开发者ID:ruizrube,项目名称:spdef,代码行数:62,代码来源:Block.php


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