use IContextSource;
use InvalidArgumentException;
use IP;
+use MediaWiki\MediaWikiServices;
use RequestContext;
use Title;
use User;
* @since 1.34 Factored out from DatabaseBlock (previously Block).
*/
abstract class AbstractBlock {
- /** @var string */
+ /**
+ * @deprecated since 1.34. Use getReason and setReason instead.
+ * @var string
+ */
public $mReason;
- /** @var string */
+ /**
+ * @deprecated since 1.34. Use getTimestamp and setTimestamp instead.
+ * @var string
+ */
public $mTimestamp;
- /** @var string */
+ /**
+ * @deprecated since 1.34. Use getExpiry and setExpiry instead.
+ * @var string
+ */
public $mExpiry = '';
/** @var bool */
/** @var bool */
protected $blockCreateAccount = false;
- /** @var bool */
+ /**
+ * @deprecated since 1.34. Use getHideName and setHideName instead.
+ * @var bool
+ */
public $mHideName = false;
/** @var User|string */
/**
* Create a new block with specified parameters on a user, IP or IP range.
*
- * @param array $options Parameters of the block:
- * address string|User Target user name, User object, IP address or IP range
- * by int User ID of the blocker
- * reason string Reason of the block
- * timestamp string The time at which the block comes into effect
- * byText string Username of the blocker (for foreign users)
+ * @param array $options Parameters of the block, with supported options:
+ * - address: (string|User) Target user name, User object, IP address or IP range
+ * - by: (int) User ID of the blocker
+ * - reason: (string) Reason of the block
+ * - timestamp: (string) The time at which the block comes into effect
+ * - byText: (string) Username of the blocker (for foreign users)
+ * - hideName: (bool) Hide the target user name
*/
- function __construct( $options = [] ) {
+ public function __construct( array $options = [] ) {
$defaults = [
'address' => '',
'by' => null,
'reason' => '',
'timestamp' => '',
'byText' => '',
+ 'hideName' => false,
];
$options += $defaults;
$this->setReason( $options['reason'] );
$this->setTimestamp( wfTimestamp( TS_MW, $options['timestamp'] ) );
+ $this->setHideName( (bool)$options['hideName'] );
}
/**
* may be overridden according to global configs.
*
* @since 1.33
- * @param string $right Right to check
- * @return bool|null null if unrecognized right or unset property
+ * @param string $right
+ * @return bool|null The block applies to the right, or null if
+ * unsure (e.g. unrecognized right or unset property)
*/
public function appliesToRight( $right ) {
$config = RequestContext::getMain()->getConfig();
if ( !$res && $blockDisablesLogin ) {
// If a block would disable login, then it should
// prevent any right that all users cannot do
+ $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
$anon = new User;
- $res = $anon->isAllowed( $right ) ? $res : true;
+ $res = $permissionManager->userHasRight( $anon, $right ) ? $res : true;
}
return $res;
if ( !$res && $blockDisablesLogin ) {
// If a block would disable login, then it should
// prevent any action that all users cannot do
+ $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
$anon = new User;
- $res = $anon->isAllowed( $action ) ? $res : true;
+ $res = $permissionManager->userHasRight( $anon, $action ) ? $res : true;
}
return $res;
* @return array
*/
public function getBlockErrorParams( IContextSource $context ) {
+ $lang = $context->getLanguage();
+
$blocker = $this->getBlocker();
if ( $blocker instanceof User ) { // local user
$blockerUserpage = $blocker->getUserPage();
- $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
+ $blockerText = $lang->embedBidi( $blockerUserpage->getText() );
+ $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerText}]]";
} else { // foreign user
$link = $blocker;
}
/* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
* This could be a username, an IP range, or a single IP. */
- $intended = $this->getTarget();
- $lang = $context->getLanguage();
+ $intended = (string)$this->getTarget();
return [
$link,
$reason,
$context->getRequest()->getIP(),
- $this->getByName(),
+ $lang->embedBidi( $this->getByName() ),
// TODO: SystemBlock replaces this with the system block type. Clean up
// error params so that this is not necessary.
$this->getId(),
$lang->formatExpiry( $this->getExpiry() ),
- (string)$intended,
+ $lang->embedBidi( $intended ),
$lang->userTimeAndDate( $this->getTimestamp(), $context->getUser() ),
];
}