本文整理汇总了PHP中Block::parseTarget方法的典型用法代码示例。如果您正苦于以下问题:PHP Block::parseTarget方法的具体用法?PHP Block::parseTarget怎么用?PHP Block::parseTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Block
的用法示例。
在下文中一共展示了Block::parseTarget方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getBlockListPager
/**
* Setup a new BlockListPager instance.
* @return BlockListPager
*/
protected function getBlockListPager()
{
$conds = [];
# Is the user allowed to see hidden blocks?
if (!$this->getUser()->isAllowed('hideuser')) {
$conds['ipb_deleted'] = 0;
}
if ($this->target !== '') {
list($target, $type) = Block::parseTarget($this->target);
switch ($type) {
case Block::TYPE_ID:
case Block::TYPE_AUTO:
$conds['ipb_id'] = $target;
break;
case Block::TYPE_IP:
case Block::TYPE_RANGE:
list($start, $end) = IP::parseRange($target);
$conds[] = wfGetDB(DB_REPLICA)->makeList(['ipb_address' => $target, Block::getRangeCond($start, $end)], LIST_OR);
$conds['ipb_auto'] = 0;
break;
case Block::TYPE_USER:
$conds['ipb_address'] = $target->getName();
$conds['ipb_auto'] = 0;
break;
}
}
# Apply filters
if (in_array('userblocks', $this->options)) {
$conds['ipb_user'] = 0;
}
if (in_array('tempblocks', $this->options)) {
$conds['ipb_expiry'] = 'infinity';
}
if (in_array('addressblocks', $this->options)) {
$conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
}
if (in_array('rangeblocks', $this->options)) {
$conds[] = "ipb_range_end = ipb_range_start";
}
return new BlockListPager($this, $conds);
}
示例2: getTargetAndType
/**
* Determine the target of the block, and the type of target
* TODO: should be in Block.php?
* @param $par String subpage parameter passed to setup, or data value from
* the HTMLForm
* @param $request WebRequest optionally try and get data from a request too
* @return array( User|string|null, Block::TYPE_ constant|null )
*/
public static function getTargetAndType($par, WebRequest $request = null)
{
$i = 0;
$target = null;
while (true) {
switch ($i++) {
case 0:
# The HTMLForm will check wpTarget first and only if it doesn't get
# a value use the default, which will be generated from the options
# below; so this has to have a higher precedence here than $par, or
# we could end up with different values in $this->target and the HTMLForm!
if ($request instanceof WebRequest) {
$target = $request->getText('wpTarget', null);
}
break;
case 1:
$target = $par;
break;
case 2:
if ($request instanceof WebRequest) {
$target = $request->getText('ip', null);
}
break;
case 3:
# B/C @since 1.18
if ($request instanceof WebRequest) {
$target = $request->getText('wpBlockAddress', null);
}
break;
case 4:
break 2;
}
list($target, $type) = Block::parseTarget($target);
if ($type !== null) {
return array($target, $type);
}
}
return array(null, null);
}
示例3: formatValue
function formatValue($name, $value)
{
static $msg = null;
if ($msg === null) {
$keys = ['anononlyblock', 'createaccountblock', 'noautoblockblock', 'emailblock', 'blocklist-nousertalk', 'unblocklink', 'change-blocklink'];
foreach ($keys as $key) {
$msg[$key] = $this->msg($key)->escaped();
}
}
/** @var $row object */
$row = $this->mCurrentRow;
$language = $this->getLanguage();
$formatted = '';
switch ($name) {
case 'ipb_timestamp':
$formatted = htmlspecialchars($language->userTimeAndDate($value, $this->getUser()));
break;
case 'ipb_target':
if ($row->ipb_auto) {
$formatted = $this->msg('autoblockid', $row->ipb_id)->parse();
} else {
list($target, $type) = Block::parseTarget($row->ipb_address);
switch ($type) {
case Block::TYPE_USER:
case Block::TYPE_IP:
$formatted = Linker::userLink($target->getId(), $target);
$formatted .= Linker::userToolLinks($target->getId(), $target, false, Linker::TOOL_LINKS_NOBLOCK);
break;
case Block::TYPE_RANGE:
$formatted = htmlspecialchars($target);
}
}
break;
case 'ipb_expiry':
$formatted = htmlspecialchars($language->formatExpiry($value, true));
if ($this->getUser()->isAllowed('block')) {
if ($row->ipb_auto) {
$links[] = Linker::linkKnown(SpecialPage::getTitleFor('Unblock'), $msg['unblocklink'], [], ['wpTarget' => "#{$row->ipb_id}"]);
} else {
$links[] = Linker::linkKnown(SpecialPage::getTitleFor('Unblock', $row->ipb_address), $msg['unblocklink']);
$links[] = Linker::linkKnown(SpecialPage::getTitleFor('Block', $row->ipb_address), $msg['change-blocklink']);
}
$formatted .= ' ' . Html::rawElement('span', ['class' => 'mw-blocklist-actions'], $this->msg('parentheses')->rawParams($language->pipeList($links))->escaped());
}
if ($value !== 'infinity') {
$timestamp = new MWTimestamp($value);
$formatted .= '<br />' . $this->msg('ipb-blocklist-duration-left', $language->formatDuration($timestamp->getTimestamp() - time(), ['minutes', 'hours', 'days', 'years']))->escaped();
}
break;
case 'ipb_by':
if (isset($row->by_user_name)) {
$formatted = Linker::userLink($value, $row->by_user_name);
$formatted .= Linker::userToolLinks($value, $row->by_user_name);
} else {
$formatted = htmlspecialchars($row->ipb_by_text);
// foreign user?
}
break;
case 'ipb_reason':
$formatted = Linker::formatComment($value);
break;
case 'ipb_params':
$properties = [];
if ($row->ipb_anon_only) {
$properties[] = $msg['anononlyblock'];
}
if ($row->ipb_create_account) {
$properties[] = $msg['createaccountblock'];
}
if ($row->ipb_user && !$row->ipb_enable_autoblock) {
$properties[] = $msg['noautoblockblock'];
}
if ($row->ipb_block_email) {
$properties[] = $msg['emailblock'];
}
if (!$row->ipb_allow_usertalk) {
$properties[] = $msg['blocklist-nousertalk'];
}
$formatted = $language->commaList($properties);
break;
default:
$formatted = "Unable to format {$name}";
break;
}
return $formatted;
}
示例4: formatValue
function formatValue( $name, $value ) {
static $msg = null;
if ( $msg === null ) {
$msg = array(
'anononlyblock',
'createaccountblock',
'noautoblockblock',
'emailblock',
'blocklist-nousertalk',
'unblocklink',
'change-blocklink',
'infiniteblock',
);
$msg = array_combine( $msg, array_map( array( $this, 'msg' ), $msg ) );
}
/** @var $row object */
$row = $this->mCurrentRow;
$formatted = '';
switch ( $name ) {
case 'ipb_timestamp':
$formatted = $this->getLanguage()->userTimeAndDate( $value, $this->getUser() );
break;
case 'ipb_target':
if ( $row->ipb_auto ) {
$formatted = $this->msg( 'autoblockid', $row->ipb_id )->parse();
} else {
list( $target, $type ) = Block::parseTarget( $row->ipb_address );
switch ( $type ) {
case Block::TYPE_USER:
case Block::TYPE_IP:
$formatted = Linker::userLink( $target->getId(), $target );
$formatted .= Linker::userToolLinks(
$target->getId(),
$target,
false,
Linker::TOOL_LINKS_NOBLOCK
);
break;
case Block::TYPE_RANGE:
$formatted = htmlspecialchars( $target );
}
}
break;
case 'ipb_expiry':
$formatted = $this->getLanguage()->formatExpiry( $value, /* User preference timezone */true );
if ( $this->getUser()->isAllowed( 'block' ) ) {
if ( $row->ipb_auto ) {
$links[] = Linker::linkKnown(
SpecialPage::getTitleFor( 'Unblock' ),
$msg['unblocklink'],
array(),
array( 'wpTarget' => "#{$row->ipb_id}" )
);
} else {
$links[] = Linker::linkKnown(
SpecialPage::getTitleFor( 'Unblock', $row->ipb_address ),
$msg['unblocklink']
);
$links[] = Linker::linkKnown(
SpecialPage::getTitleFor( 'Block', $row->ipb_address ),
$msg['change-blocklink']
);
}
$formatted .= ' ' . Html::rawElement(
'span',
array( 'class' => 'mw-blocklist-actions' ),
$this->msg( 'parentheses' )->rawParams(
$this->getLanguage()->pipeList( $links ) )->escaped()
);
}
break;
case 'ipb_by':
if ( isset( $row->by_user_name ) ) {
$formatted = Linker::userLink( $value, $row->by_user_name );
$formatted .= Linker::userToolLinks( $value, $row->by_user_name );
} else {
$formatted = htmlspecialchars( $row->ipb_by_text ); // foreign user?
}
break;
case 'ipb_reason':
$formatted = Linker::formatComment( $value );
break;
case 'ipb_params':
$properties = array();
if ( $row->ipb_anon_only ) {
$properties[] = $msg['anononlyblock'];
}
if ( $row->ipb_create_account ) {
$properties[] = $msg['createaccountblock'];
}
if ( $row->ipb_user && !$row->ipb_enable_autoblock ) {
$properties[] = $msg['noautoblockblock'];
//.........这里部分代码省略.........
示例5: formatValue
function formatValue($name, $value)
{
global $wgLang, $wgUser;
static $sk, $msg;
if (empty($sk)) {
$sk = $this->getSkin();
$msg = array('anononlyblock', 'createaccountblock', 'noautoblockblock', 'emailblock', 'blocklist-nousertalk', 'unblocklink', 'change-blocklink', 'infiniteblock');
$msg = array_combine($msg, array_map('wfMessage', $msg));
}
$row = $this->mCurrentRow;
$formatted = '';
switch ($name) {
case 'ipb_timestamp':
$formatted = $wgLang->timeanddate($value, true);
break;
case 'ipb_target':
if ($row->ipb_auto) {
$formatted = wfMessage('autoblockid', $row->ipb_id)->parse();
} else {
list($target, $type) = Block::parseTarget($row->ipb_address);
switch ($type) {
case Block::TYPE_USER:
case Block::TYPE_IP:
$formatted = $sk->userLink($target->getId(), $target);
$formatted .= $sk->userToolLinks($target->getId(), $target, false, Linker::TOOL_LINKS_NOBLOCK);
break;
case Block::TYPE_RANGE:
$formatted = htmlspecialchars($target);
}
}
break;
case 'ipb_expiry':
$formatted = $wgLang->formatExpiry($value, true);
if ($wgUser->isAllowed('block')) {
if ($row->ipb_auto) {
$links[] = $sk->linkKnown(SpecialPage::getTitleFor('Unblock'), $msg['unblocklink'], array(), array('wpTarget' => "#{$row->ipb_id}"));
} else {
$links[] = $sk->linkKnown(SpecialPage::getTitleFor('Unblock', $row->ipb_address), $msg['unblocklink']);
$links[] = $sk->linkKnown(SpecialPage::getTitleFor('Block', $row->ipb_address), $msg['change-blocklink']);
}
$formatted .= ' ' . Html::rawElement('span', array('class' => 'mw-blocklist-actions'), wfMsg('parentheses', $wgLang->pipeList($links)));
}
break;
case 'ipb_by':
$user = User::newFromId($value);
if ($user instanceof User) {
$formatted = $sk->userLink($user->getId(), $user->getName());
$formatted .= $sk->userToolLinks($user->getId(), $user->getName());
}
break;
case 'ipb_reason':
$formatted = $sk->commentBlock($value);
break;
case 'ipb_params':
$properties = array();
if ($row->ipb_anon_only) {
$properties[] = $msg['anononlyblock'];
}
if ($row->ipb_create_account) {
$properties[] = $msg['createaccountblock'];
}
if ($row->ipb_user && !$row->ipb_enable_autoblock) {
$properties[] = $msg['noautoblockblock'];
}
if ($row->ipb_block_email) {
$properties[] = $msg['emailblock'];
}
if (!$row->ipb_allow_usertalk) {
$properties[] = $msg['blocklist-nousertalk'];
}
$formatted = $wgLang->commaList($properties);
break;
default:
$formatted = "Unable to format {$name}";
break;
}
return $formatted;
}