本文整理汇总了PHP中Block::newFromTarget方法的典型用法代码示例。如果您正苦于以下问题:PHP Block::newFromTarget方法的具体用法?PHP Block::newFromTarget怎么用?PHP Block::newFromTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Block
的用法示例。
在下文中一共展示了Block::newFromTarget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Unblocks the specified user or provides the reason the unblock failed.
*/
public function execute()
{
$user = $this->getUser();
$params = $this->extractRequestParams();
if (is_null($params['id']) && is_null($params['user'])) {
$this->dieUsageMsg('unblock-notarget');
}
if (!is_null($params['id']) && !is_null($params['user'])) {
$this->dieUsageMsg('unblock-idanduser');
}
if (!$user->isAllowed('block')) {
$this->dieUsageMsg('cantunblock');
}
# bug 15810: blocked admins should have limited access here
if ($user->isBlocked()) {
$status = SpecialBlock::checkUnblockSelf($params['user'], $user);
if ($status !== true) {
$this->dieUsageMsg($status);
}
}
$data = array('Target' => is_null($params['id']) ? $params['user'] : "#{$params['id']}", 'Reason' => $params['reason']);
$block = Block::newFromTarget($data['Target']);
$retval = SpecialUnblock::processUnblock($data, $this->getContext());
if ($retval !== true) {
$this->dieUsageMsg($retval[0]);
}
$res['id'] = $block->getId();
$target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
$res['user'] = $target instanceof User ? $target->getName() : $target;
$res['userid'] = $target instanceof User ? $target->getId() : 0;
$res['reason'] = $params['reason'];
$this->getResult()->addValue(null, $this->getModuleName(), $res);
}
示例2: execute
/**
* Blocks the user specified in the parameters for the given expiry, with the
* given reason, and with all other settings provided in the params. If the block
* succeeds, produces a result containing the details of the block and notice
* of success. If it fails, the result will specify the nature of the error.
*/
public function execute()
{
global $wgContLang;
$user = $this->getUser();
$params = $this->extractRequestParams();
if (!$user->isAllowed('block')) {
$this->dieUsageMsg('cantblock');
}
# bug 15810: blocked admins should have limited access here
if ($user->isBlocked()) {
$status = SpecialBlock::checkUnblockSelf($params['user'], $user);
if ($status !== true) {
$msg = $this->parseMsg($status);
$this->dieUsage($msg['info'], $msg['code'], 0, ['blockinfo' => ApiQueryUserInfo::getBlockInfo($user->getBlock())]);
}
}
$target = User::newFromName($params['user']);
// Bug 38633 - if the target is a user (not an IP address), but it
// doesn't exist or is unusable, error.
if ($target instanceof User && ($target->isAnon() || !User::isUsableName($target->getName()))) {
$this->dieUsageMsg(['nosuchuser', $params['user']]);
}
if ($params['hidename'] && !$user->isAllowed('hideuser')) {
$this->dieUsageMsg('canthide');
}
if ($params['noemail'] && !SpecialBlock::canBlockEmail($user)) {
$this->dieUsageMsg('cantblock-email');
}
$data = ['PreviousTarget' => $params['user'], 'Target' => $params['user'], 'Reason' => [$params['reason'], 'other', $params['reason']], 'Expiry' => $params['expiry'], 'HardBlock' => !$params['anononly'], 'CreateAccount' => $params['nocreate'], 'AutoBlock' => $params['autoblock'], 'DisableEmail' => $params['noemail'], 'HideUser' => $params['hidename'], 'DisableUTEdit' => !$params['allowusertalk'], 'Reblock' => $params['reblock'], 'Watch' => $params['watchuser'], 'Confirm' => true];
$retval = SpecialBlock::processForm($data, $this->getContext());
if ($retval !== true) {
// We don't care about multiple errors, just report one of them
$this->dieUsageMsg($retval);
}
list($target, ) = SpecialBlock::getTargetAndType($params['user']);
$res['user'] = $params['user'];
$res['userID'] = $target instanceof User ? $target->getId() : 0;
$block = Block::newFromTarget($target, null, true);
if ($block instanceof Block) {
$res['expiry'] = $wgContLang->formatExpiry($block->mExpiry, TS_ISO_8601, 'infinite');
$res['id'] = $block->getId();
} else {
# should be unreachable
$res['expiry'] = '';
$res['id'] = '';
}
$res['reason'] = $params['reason'];
$res['anononly'] = $params['anononly'];
$res['nocreate'] = $params['nocreate'];
$res['autoblock'] = $params['autoblock'];
$res['noemail'] = $params['noemail'];
$res['hidename'] = $params['hidename'];
$res['allowusertalk'] = $params['allowusertalk'];
$res['watchuser'] = $params['watchuser'];
$this->getResult()->addValue(null, $this->getModuleName(), $res);
}
示例3: testMakeNormalBlock
/**
* This test has probably always been broken and use an invalid token
* Bug tracking brokenness is https://phabricator.wikimedia.org/T37646
*
* Root cause is https://gerrit.wikimedia.org/r/3434
* Which made the Block/Unblock API to actually verify the token
* previously always considered valid (T36212).
*/
public function testMakeNormalBlock()
{
$tokens = $this->getTokens();
$user = User::newFromName('UTApiBlockee');
if (!$user->getId()) {
$this->markTestIncomplete("The user UTApiBlockee does not exist");
}
if (!array_key_exists('blocktoken', $tokens)) {
$this->markTestIncomplete("No block token found");
}
$this->doApiRequest(array('action' => 'block', 'user' => 'UTApiBlockee', 'reason' => 'Some reason', 'token' => $tokens['blocktoken']), null, false, self::$users['sysop']->getUser());
$block = Block::newFromTarget('UTApiBlockee');
$this->assertTrue(!is_null($block), 'Block is valid');
$this->assertEquals('UTApiBlockee', (string) $block->getTarget());
$this->assertEquals('Some reason', $block->mReason);
$this->assertEquals('infinity', $block->mExpiry);
}
示例4: getBlockedUser
private function getBlockedUser()
{
$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();
return $user;
}
示例5: testMakeNormalBlock
/**
* This test has probably always been broken and use an invalid token
* Bug tracking brokenness is https://bugzilla.wikimedia.org/35646
*
* Root cause is https://gerrit.wikimedia.org/r/3434
* Which made the Block/Unblock API to actually verify the token
* previously always considered valid (bug 34212).
*/
function testMakeNormalBlock()
{
$data = $this->getTokens();
$user = User::newFromName('UTApiBlockee');
if (!$user->getId()) {
$this->markTestIncomplete("The user UTApiBlockee does not exist");
}
if (!isset($data[0]['query']['pages'])) {
$this->markTestIncomplete("No block token found");
}
$keys = array_keys($data[0]['query']['pages']);
$key = array_pop($keys);
$pageinfo = $data[0]['query']['pages'][$key];
$this->doApiRequest(array('action' => 'block', 'user' => 'UTApiBlockee', 'reason' => 'Some reason', 'token' => $pageinfo['blocktoken']), null, false, self::$users['sysop']->user);
$block = Block::newFromTarget('UTApiBlockee');
$this->assertTrue(!is_null($block), 'Block is valid');
$this->assertEquals('UTApiBlockee', (string) $block->getTarget());
$this->assertEquals('Some reason', $block->mReason);
$this->assertEquals('infinity', $block->mExpiry);
}
示例6: execute
/**
* Unblocks the specified user or provides the reason the unblock failed.
*/
public function execute()
{
$user = $this->getUser();
$params = $this->extractRequestParams();
if (is_null($params['id']) && is_null($params['user'])) {
$this->dieUsageMsg('unblock-notarget');
}
if (!is_null($params['id']) && !is_null($params['user'])) {
$this->dieUsageMsg('unblock-idanduser');
}
if (!$user->isAllowed('block')) {
$this->dieUsageMsg('cantunblock');
}
# bug 15810: blocked admins should have limited access here
if ($user->isBlocked()) {
$status = SpecialBlock::checkUnblockSelf($params['user'], $user);
if ($status !== true) {
$msg = $this->parseMsg($status);
$this->dieUsage($msg['info'], $msg['code'], 0, ['blockinfo' => ApiQueryUserInfo::getBlockInfo($user->getBlock())]);
}
}
// Check if user can add tags
if (!is_null($params['tags'])) {
$ableToTag = ChangeTags::canAddTagsAccompanyingChange($params['tags'], $user);
if (!$ableToTag->isOK()) {
$this->dieStatus($ableToTag);
}
}
$data = ['Target' => is_null($params['id']) ? $params['user'] : "#{$params['id']}", 'Reason' => $params['reason'], 'Tags' => $params['tags']];
$block = Block::newFromTarget($data['Target']);
$retval = SpecialUnblock::processUnblock($data, $this->getContext());
if ($retval !== true) {
$this->dieUsageMsg($retval[0]);
}
$res['id'] = $block->getId();
$target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
$res['user'] = $target instanceof User ? $target->getName() : $target;
$res['userid'] = $target instanceof User ? $target->getId() : 0;
$res['reason'] = $params['reason'];
$this->getResult()->addValue(null, $this->getModuleName(), $res);
}
示例7: execute
/**
* Unblocks the specified user or provides the reason the unblock failed.
*/
public function execute()
{
$user = $this->getUser();
$params = $this->extractRequestParams();
if ($params['gettoken']) {
// If we're in JSON callback mode, no tokens can be obtained
if (!is_null($this->getMain()->getRequest()->getVal('callback'))) {
$this->dieUsage('Cannot get token when using a callback', 'aborted');
}
$res['unblocktoken'] = $user->getEditToken('', $this->getMain()->getRequest());
$this->getResult()->addValue(null, $this->getModuleName(), $res);
return;
}
if (is_null($params['id']) && is_null($params['user'])) {
$this->dieUsageMsg('unblock-notarget');
}
if (!is_null($params['id']) && !is_null($params['user'])) {
$this->dieUsageMsg('unblock-idanduser');
}
if (!$user->isAllowed('block')) {
$this->dieUsageMsg('cantunblock');
}
# bug 15810: blocked admins should have limited access here
if ($user->isBlocked()) {
$status = SpecialBlock::checkUnblockSelf($params['user'], $user);
if ($status !== true) {
$this->dieUsageMsg($status);
}
}
$data = array('Target' => is_null($params['id']) ? $params['user'] : "#{$params['id']}", 'Reason' => is_null($params['reason']) ? '' : $params['reason']);
$block = Block::newFromTarget($data['Target']);
$retval = SpecialUnblock::processUnblock($data, $this->getContext());
if ($retval !== true) {
$this->dieUsageMsg($retval[0]);
}
$res['id'] = $block->getId();
$target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
$res['user'] = $target instanceof User ? $target->getName() : $target;
$res['reason'] = $params['reason'];
$this->getResult()->addValue(null, $this->getModuleName(), $res);
}
示例8: execute
/**
* Unblocks the specified user or provides the reason the unblock failed.
*/
public function execute()
{
global $wgUser;
$params = $this->extractRequestParams();
if ($params['gettoken']) {
$res['unblocktoken'] = $wgUser->editToken('', $this->getMain()->getRequest());
$this->getResult()->addValue(null, $this->getModuleName(), $res);
return;
}
if (is_null($params['id']) && is_null($params['user'])) {
$this->dieUsageMsg('unblock-notarget');
}
if (!is_null($params['id']) && !is_null($params['user'])) {
$this->dieUsageMsg('unblock-idanduser');
}
if (!$wgUser->isAllowed('block')) {
$this->dieUsageMsg('cantunblock');
}
# bug 15810: blocked admins should have limited access here
if ($wgUser->isBlocked()) {
$status = SpecialBlock::checkUnblockSelf($params['user']);
if ($status !== true) {
$this->dieUsageMsg($status);
}
}
$data = array('Target' => is_null($params['id']) ? $params['user'] : "#{$params['id']}", 'Reason' => is_null($params['reason']) ? '' : $params['reason']);
$block = Block::newFromTarget($data['Target']);
$retval = SpecialUnblock::processUnblock($data);
if ($retval !== true) {
$this->dieUsageMsg($retval[0]);
}
$res['id'] = $block->getId();
$res['user'] = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
$res['reason'] = $params['reason'];
$this->getResult()->addValue(null, $this->getModuleName(), $res);
}
示例9: getSubTitle
/**
* Generates the subheading with links
* @param User $userObj User object for the target
* @return string Appropriately-escaped HTML to be output literally
*/
function getSubTitle($userObj)
{
$linkRenderer = $this->getLinkRenderer();
if ($userObj->isAnon()) {
$user = htmlspecialchars($userObj->getName());
} else {
$user = $linkRenderer->makeLink($userObj->getUserPage(), $userObj->getName());
}
$links = '';
$nt = $userObj->getUserPage();
$talk = $nt->getTalkPage();
if ($talk) {
$tools = SpecialContributions::getUserLinks($this, $userObj);
# Link to contributions
$insert['contribs'] = $linkRenderer->makeKnownLink(SpecialPage::getTitleFor('Contributions', $nt->getDBkey()), $this->msg('sp-deletedcontributions-contribs')->text());
// Swap out the deletedcontribs link for our contribs one
$tools = wfArrayInsertAfter($tools, $insert, 'deletedcontribs');
unset($tools['deletedcontribs']);
$links = $this->getLanguage()->pipeList($tools);
// Show a note if the user is blocked and display the last block log entry.
$block = Block::newFromTarget($userObj, $userObj);
if (!is_null($block) && $block->getType() != Block::TYPE_AUTO) {
if ($block->getType() == Block::TYPE_RANGE) {
$nt = MWNamespace::getCanonicalName(NS_USER) . ':' . $block->getTarget();
}
// LogEventsList::showLogExtract() wants the first parameter by ref
$out = $this->getOutput();
LogEventsList::showLogExtract($out, 'block', $nt, '', ['lim' => 1, 'showIfEmpty' => false, 'msgKey' => ['sp-contributions-blocked-notice', $userObj->getName()], 'offset' => '']);
}
}
return $this->msg('contribsub2')->rawParams($user, $links)->params($userObj->getName());
}
示例10: processUnblock
/**
* Process the form
* @return Array( Array(message key, parameters) ) on failure, True on success
*/
public static function processUnblock(array $data)
{
global $wgUser;
$target = $data['Target'];
$block = Block::newFromTarget($data['Target']);
if (!$block instanceof Block) {
return array(array('ipb_cant_unblock', $target));
}
# If the specified IP is a single address, and the block is a range block, don't
# unblock the whole range.
list($target, $type) = SpecialBlock::getTargetAndType($target);
if ($block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP) {
$range = $block->getTarget();
return array(array('ipb_blocked_as_range', $target, $range));
}
# If the name was hidden and the blocking user cannot hide
# names, then don't allow any block removals...
if (!$wgUser->isAllowed('hideuser') && $block->mHideName) {
return array('unblock-hideuser');
}
# Delete block
if (!$block->delete()) {
return array('ipb_cant_unblock', htmlspecialchars($block->getTarget()));
}
# Unset _deleted fields as needed
if ($block->mHideName) {
# Something is deeply FUBAR if this is not a User object, but who knows?
$id = $block->getTarget() instanceof User ? $block->getTarget()->getID() : User::idFromName($block->getTarget());
RevisionDeleteUser::unsuppressUserName($block->getTarget(), $id);
}
# Redact the name (IP address) for autoblocks
if ($block->getType() == Block::TYPE_AUTO) {
$page = Title::makeTitle(NS_USER, '#' . $block->getId());
} else {
$page = $block->getTarget() instanceof User ? $block->getTarget()->getUserpage() : Title::makeTitle(NS_USER, $block->getTarget());
}
# Make log entry
$log = new LogPage('block');
$log->addEntry('unblock', $page, $data['Reason']);
return true;
}
示例11: showMissingArticle
/**
* Show the error text for a missing article. For articles in the MediaWiki
* namespace, show the default message text. To be called from Article::view().
*/
public function showMissingArticle()
{
global $wgSend404Code;
$outputPage = $this->getContext()->getOutput();
// Whether the page is a root user page of an existing user (but not a subpage)
$validUserPage = false;
$title = $this->getTitle();
# Show info in user (talk) namespace. Does the user exist? Is he blocked?
if ($title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK) {
$parts = explode('/', $title->getText());
$rootPart = $parts[0];
$user = User::newFromName($rootPart, false);
$ip = User::isIP($rootPart);
$block = Block::newFromTarget($user, $user);
if (!($user && $user->isLoggedIn()) && !$ip) {
# User does not exist
$outputPage->wrapWikiMsg("<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>", array('userpage-userdoesnotexist-view', wfEscapeWikiText($rootPart)));
} elseif (!is_null($block) && $block->getType() != Block::TYPE_AUTO) {
# Show log extract if the user is currently blocked
LogEventsList::showLogExtract($outputPage, 'block', MWNamespace::getCanonicalName(NS_USER) . ':' . $block->getTarget(), '', array('lim' => 1, 'showIfEmpty' => false, 'msgKey' => array('blocked-notice-logextract', $user->getName())));
$validUserPage = !$title->isSubpage();
} else {
$validUserPage = !$title->isSubpage();
}
}
Hooks::run('ShowMissingArticle', array($this));
# Show delete and move logs if there were any such events.
# The logging query can DOS the site when bots/crawlers cause 404 floods,
# so be careful showing this. 404 pages must be cheap as they are hard to cache.
$cache = ObjectCache::getMainStashInstance();
$key = wfMemcKey('page-recent-delete', md5($title->getPrefixedText()));
$loggedIn = $this->getContext()->getUser()->isLoggedIn();
if ($loggedIn || $cache->get($key)) {
$logTypes = array('delete', 'move');
$conds = array("log_action != 'revision'");
// Give extensions a chance to hide their (unrelated) log entries
Hooks::run('Article::MissingArticleConditions', array(&$conds, $logTypes));
LogEventsList::showLogExtract($outputPage, $logTypes, $title, '', array('lim' => 10, 'conds' => $conds, 'showIfEmpty' => false, 'msgKey' => array($loggedIn ? 'moveddeleted-notice' : 'moveddeleted-notice-recent')));
}
if (!$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage) {
// If there's no backing content, send a 404 Not Found
// for better machine handling of broken links.
$this->getContext()->getRequest()->response()->statusHeader(404);
}
// Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
$policy = $this->getRobotPolicy('view');
$outputPage->setIndexPolicy($policy['index']);
$outputPage->setFollowPolicy($policy['follow']);
$hookResult = Hooks::run('BeforeDisplayNoArticleText', array($this));
if (!$hookResult) {
return;
}
# Show error message
$oldid = $this->getOldID();
if (!$oldid && $title->getNamespace() === NS_MEDIAWIKI && $title->hasSourceText()) {
$outputPage->addParserOutput($this->getContentObject()->getParserOutput($title));
} else {
if ($oldid) {
$text = wfMessage('missing-revision', $oldid)->plain();
} elseif ($title->quickUserCan('create', $this->getContext()->getUser()) && $title->quickUserCan('edit', $this->getContext()->getUser())) {
$message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
$text = wfMessage($message)->plain();
} else {
$text = wfMessage('noarticletext-nopermission')->plain();
}
$dir = $this->getContext()->getLanguage()->getDir();
$lang = $this->getContext()->getLanguage()->getCode();
$outputPage->addWikiText(Xml::openElement('div', array('class' => "noarticletext mw-content-{$dir}", 'dir' => $dir, 'lang' => $lang)) . "\n{$text}\n</div>");
}
}
示例12: processUnblock
/**
* Process the form
*
* @param $data Array
* @param $context IContextSource
* @throws ErrorPageError
* @return Array( Array(message key, parameters) ) on failure, True on success
*/
public static function processUnblock(array $data, IContextSource $context)
{
$performer = $context->getUser();
$target = $data['Target'];
$block = Block::newFromTarget($data['Target']);
if (!$block instanceof Block) {
return array(array('ipb_cant_unblock', $target));
}
# bug 15810: blocked admins should have limited access here. This
# won't allow sysops to remove autoblocks on themselves, but they
# should have ipblock-exempt anyway
$status = SpecialBlock::checkUnblockSelf($target, $performer);
if ($status !== true) {
throw new ErrorPageError('badaccess', $status);
}
# If the specified IP is a single address, and the block is a range block, don't
# unblock the whole range.
list($target, $type) = SpecialBlock::getTargetAndType($target);
if ($block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP) {
$range = $block->getTarget();
return array(array('ipb_blocked_as_range', $target, $range));
}
# If the name was hidden and the blocking user cannot hide
# names, then don't allow any block removals...
if (!$performer->isAllowed('hideuser') && $block->mHideName) {
return array('unblock-hideuser');
}
# Delete block
if (!$block->delete()) {
return array('ipb_cant_unblock', htmlspecialchars($block->getTarget()));
}
# Unset _deleted fields as needed
if ($block->mHideName) {
# Something is deeply FUBAR if this is not a User object, but who knows?
$id = $block->getTarget() instanceof User ? $block->getTarget()->getID() : User::idFromName($block->getTarget());
RevisionDeleteUser::unsuppressUserName($block->getTarget(), $id);
}
# Redact the name (IP address) for autoblocks
if ($block->getType() == Block::TYPE_AUTO) {
$page = Title::makeTitle(NS_USER, '#' . $block->getId());
} else {
$page = $block->getTarget() instanceof User ? $block->getTarget()->getUserpage() : Title::makeTitle(NS_USER, $block->getTarget());
}
# Make log entry
$log = new LogPage('block');
$log->addEntry('unblock', $page, $data['Reason'], array(), $performer);
return true;
}
示例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)) {
//.........这里部分代码省略.........
示例14: contributionsSub
/**
* Generates the subheading with links
* @param User $userObj User object for the target
* @return string Appropriately-escaped HTML to be output literally
* @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
* Could be combined.
*/
protected function contributionsSub($userObj)
{
if ($userObj->isAnon()) {
// Show a warning message that the user being searched for doesn't exists
if (!User::isIP($userObj->getName())) {
$this->getOutput()->wrapWikiMsg("<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>", ['contributions-userdoesnotexist', wfEscapeWikiText($userObj->getName())]);
if (!$this->including()) {
$this->getOutput()->setStatusCode(404);
}
}
$user = htmlspecialchars($userObj->getName());
} else {
$user = $this->getLinkRenderer()->makeLink($userObj->getUserPage(), $userObj->getName());
}
$nt = $userObj->getUserPage();
$talk = $userObj->getTalkPage();
$links = '';
if ($talk) {
$tools = self::getUserLinks($this, $userObj);
$links = $this->getLanguage()->pipeList($tools);
// Show a note if the user is blocked and display the last block log entry.
// Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
// and also this will display a totally irrelevant log entry as a current block.
if (!$this->including()) {
$block = Block::newFromTarget($userObj, $userObj);
if (!is_null($block) && $block->getType() != Block::TYPE_AUTO) {
if ($block->getType() == Block::TYPE_RANGE) {
$nt = MWNamespace::getCanonicalName(NS_USER) . ':' . $block->getTarget();
}
$out = $this->getOutput();
// showLogExtract() wants first parameter by reference
LogEventsList::showLogExtract($out, 'block', $nt, '', ['lim' => 1, 'showIfEmpty' => false, 'msgKey' => [$userObj->isAnon() ? 'sp-contributions-blocked-notice-anon' : 'sp-contributions-blocked-notice', $userObj->getName()], 'offset' => '']);
}
}
}
return $this->msg('contribsub2')->rawParams($user, $links)->params($userObj->getName());
}
示例15: testDeprecatedConstructor
public function testDeprecatedConstructor()
{
$this->hideDeprecated('Block::__construct with multiple arguments');
$username = 'UnthinkablySecretRandomUsername';
$reason = 'being irrational';
# Set up the target
$u = User::newFromName($username);
if ($u->getID() == 0) {
$u->addToDatabase();
TestUser::setPasswordForUser($u, 'TotallyObvious');
}
unset($u);
# Make sure the user isn't blocked
$this->assertNull(Block::newFromTarget($username), "{$username} should not be blocked");
# Perform the block
$block = new Block($username, 0, 0, $reason, 0, false, 0);
$block->insert();
# Check target
$this->assertEquals($block->getTarget()->getName(), $username, "Target should be set properly");
# Check supplied parameter
$this->assertEquals($block->mReason, $reason, "Reason should be non-default");
# Check default parameter
$this->assertFalse((bool) $block->prevents('createaccount'), "Account creation should not be blocked by default");
}