2019-04-29 07:47:31 +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
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
|
|
use MediaWiki\Block\AbstractBlock;
|
|
|
|
|
use MediaWiki\Block\SystemBlock;
|
|
|
|
|
|
2019-04-29 07:47:31 +00:00
|
|
|
/**
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
|
|
|
|
trait ApiBlockInfoTrait {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get basic info about a given block
|
2019-05-14 12:42:50 +00:00
|
|
|
* @param AbstractBlock $block
|
2019-10-20 00:04:00 +00:00
|
|
|
* @param Language|null $language
|
2019-04-29 07:47:31 +00:00
|
|
|
* @return array Array containing several keys:
|
|
|
|
|
* - blockid - ID of the block
|
|
|
|
|
* - blockedby - username of the blocker
|
|
|
|
|
* - blockedbyid - user ID of the blocker
|
|
|
|
|
* - blockreason - reason provided for the block
|
|
|
|
|
* - blockedtimestamp - timestamp for when the block was placed/modified
|
|
|
|
|
* - blockexpiry - expiry time of the block
|
2019-10-03 17:45:58 +00:00
|
|
|
* - blockpartial - block only applies to certain pages, namespaces and/or actions
|
2019-04-29 07:47:31 +00:00
|
|
|
* - systemblocktype - system block type, if any
|
|
|
|
|
*/
|
2019-10-20 00:04:00 +00:00
|
|
|
private function getBlockDetails(
|
|
|
|
|
AbstractBlock $block,
|
|
|
|
|
$language = null
|
|
|
|
|
) {
|
|
|
|
|
if ( $language === null ) {
|
|
|
|
|
$language = $this->getLanguage();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-29 07:47:31 +00:00
|
|
|
$vals = [];
|
|
|
|
|
$vals['blockid'] = $block->getId();
|
|
|
|
|
$vals['blockedby'] = $block->getByName();
|
|
|
|
|
$vals['blockedbyid'] = $block->getBy();
|
2019-10-20 00:04:00 +00:00
|
|
|
$vals['blockreason'] = $block->getReasonComment()
|
|
|
|
|
->message->inLanguage( $language )->plain();
|
2019-04-29 07:47:31 +00:00
|
|
|
$vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() );
|
|
|
|
|
$vals['blockexpiry'] = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
|
|
|
|
|
$vals['blockpartial'] = !$block->isSitewide();
|
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
|
|
|
if ( $block instanceof SystemBlock ) {
|
2019-04-29 07:47:31 +00:00
|
|
|
$vals['systemblocktype'] = $block->getSystemBlockType();
|
|
|
|
|
}
|
|
|
|
|
return $vals;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 00:04:00 +00:00
|
|
|
/**
|
|
|
|
|
* @name Methods required from ApiBase
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** @see IContextSource::getLanguage */
|
|
|
|
|
abstract public function getLanguage();
|
|
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
|
2019-04-29 07:47:31 +00:00
|
|
|
}
|