2014-02-24 20:13:49 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2021-04-16 12:55:24 +00:00
|
|
|
use MediaWiki\Block\Block;
|
2024-02-08 14:56:54 +00:00
|
|
|
use MediaWiki\Context\RequestContext;
|
2023-12-11 15:05:02 +00:00
|
|
|
use MediaWiki\Language\RawMessage;
|
2019-09-20 15:03:48 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-03-17 02:58:43 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
Separate Block into AbstractBlock, Block and SystemBlock
This commit splits the existing Block class into AbstractBlock, Block
and SystemBlock.
Before this patch, the Block class represents several types of
blocks, which can be separated into blocks stored in the database,
and temporary blocks created by the system. These are now
represented by Block and SystemBlock, which inherit from
AbstractBlock.
This lays the foundations for:
* enforcing block parameters from multiple blocks that apply to a
user/IP address
* improvements to the Block API, including the addition of services
Breaking changes: functions expecting a Block object should still
expect a Block object if it came from the database, but other
functions may now need to expect an AbstractBlock or SystemBlock
object. (Note that an alternative naming scheme, in which the
abstract class is called Block and the subclasses are DatabaseBlock
and SystemBlock, avoids this breakage. However, it introduces more
breakages to calls to static Block methods and new Block
instantiations.)
Changes to tests: system blocks don't set the $blockCreateAccount or
$mExipry block properties, so remove/change any tests that assume
they do.
Bug: T222737
Change-Id: I83bceb5e5049e254c90ace060f8f8fad44696c67
2019-03-18 22:09:49 +00:00
|
|
|
|
2014-02-24 20:13:49 +00:00
|
|
|
/**
|
|
|
|
|
* Show an error when the user tries to do something whilst blocked.
|
|
|
|
|
*
|
2020-07-10 12:11:14 +00:00
|
|
|
* @newable
|
2014-02-24 20:13:49 +00:00
|
|
|
* @since 1.18
|
|
|
|
|
* @ingroup Exception
|
|
|
|
|
*/
|
|
|
|
|
class UserBlockedError extends ErrorPageError {
|
2019-09-20 15:03:48 +00:00
|
|
|
/**
|
2020-07-13 08:53:06 +00:00
|
|
|
* @stable to call
|
2021-04-16 12:55:24 +00:00
|
|
|
* @param Block $block
|
2021-03-17 02:58:43 +00:00
|
|
|
* @param UserIdentity|null $user
|
2023-10-01 12:03:37 +00:00
|
|
|
* @param mixed $language Unused since 1.42
|
2019-09-21 15:05:57 +00:00
|
|
|
* @param string|null $ip
|
2019-09-20 15:03:48 +00:00
|
|
|
*/
|
2019-09-21 15:05:57 +00:00
|
|
|
public function __construct(
|
2021-04-16 12:55:24 +00:00
|
|
|
Block $block,
|
2021-03-17 02:58:43 +00:00
|
|
|
UserIdentity $user = null,
|
2023-10-01 12:03:37 +00:00
|
|
|
$language = null,
|
2019-09-21 15:05:57 +00:00
|
|
|
$ip = null
|
|
|
|
|
) {
|
2023-10-01 12:03:37 +00:00
|
|
|
$context = RequestContext::getMain();
|
|
|
|
|
if ( $user === null || $ip === null ) {
|
2019-09-21 15:05:57 +00:00
|
|
|
// If any of these are not passed in, use the global context
|
|
|
|
|
$user = $context->getUser();
|
2019-11-04 01:10:23 +00:00
|
|
|
$ip = $context->getRequest()->getIP();
|
2019-09-21 15:05:57 +00:00
|
|
|
}
|
2019-09-20 15:03:48 +00:00
|
|
|
|
2019-09-21 15:05:57 +00:00
|
|
|
// @todo This should be passed in via the constructor
|
2023-10-01 12:03:37 +00:00
|
|
|
$messages = MediaWikiServices::getInstance()->getFormatterFactory()
|
|
|
|
|
->getBlockErrorFormatter( $context )
|
|
|
|
|
->getMessages( $block, $user, $ip );
|
|
|
|
|
|
2023-10-26 14:49:35 +00:00
|
|
|
if ( count( $messages ) === 1 ) {
|
|
|
|
|
$message = $messages[0];
|
|
|
|
|
} else {
|
|
|
|
|
$message = new RawMessage( '* $' . implode( "\n* \$", range( 1, count( $messages ) ) ) );
|
|
|
|
|
$message->params( $messages )->parse();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-20 15:03:48 +00:00
|
|
|
parent::__construct( 'blockedtitle', $message );
|
2014-02-24 20:13:49 +00:00
|
|
|
}
|
|
|
|
|
}
|