예제 #1
0
 /**
  * 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
0
 /**
  * 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
0
 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
0
	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'];
				}

				if ( $row->ipb_block_email ) {
					$properties[] = $msg['emailblock'];
				}

				if ( !$row->ipb_allow_usertalk ) {
					$properties[] = $msg['blocklist-nousertalk'];
				}

				$formatted = $this->getLanguage()->commaList( $properties );
				break;

			default:
				$formatted = "Unable to format $name";
				break;
		}

		return $formatted;
	}
예제 #5
0
 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;
 }