*/
use MediaWiki\Block\BlockRestriction;
use MediaWiki\Block\Restriction\Restriction;
+use MediaWiki\Block\Restriction\PageRestriction;
+use MediaWiki\Block\Restriction\NamespaceRestriction;
use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IResultWrapper;
class BlockListPager extends TablePager {
protected $conds;
- protected $page;
/**
* Array of restrictions.
* @param SpecialPage $page
* @param array $conds
*/
- function __construct( $page, $conds ) {
- $this->page = $page;
+ public function __construct( $page, $conds ) {
$this->conds = $conds;
$this->mDefaultDirection = IndexPager::DIR_DESCENDING;
parent::__construct( $page->getContext() );
$formatted .= '<br />' . $this->msg(
'ipb-blocklist-duration-left',
$language->formatDuration(
- $timestamp->getTimestamp() - time(),
+ $timestamp->getTimestamp() - MWTimestamp::time(),
// reasonable output
[
'minutes',
}
if ( !$row->ipb_sitewide && $this->restrictions ) {
- $list = $this->getRestrictionListHTML( $this->restrictions, $row );
- $properties[] = htmlspecialchars( $msg['blocklist-editing'] ) . $list;
+ $list = $this->getRestrictionListHTML( $row );
+ if ( $list ) {
+ $properties[] = htmlspecialchars( $msg['blocklist-editing'] ) . $list;
+ }
}
if ( $row->ipb_anon_only ) {
'ul',
[],
implode( '', array_map( function ( $prop ) {
- return HTML::rawElement(
+ return Html::rawElement(
'li',
[],
$prop
/**
* Get Restriction List HTML
*
- * @param Restriction[] $restrictions
* @param stdClass $row
*
* @return string
*/
- private static function getRestrictionListHTML(
- array $restrictions,
- stdClass $row
- ) {
+ private function getRestrictionListHTML( stdClass $row ) {
$items = [];
- foreach ( $restrictions as $restriction ) {
+ foreach ( $this->restrictions as $restriction ) {
if ( $restriction->getBlockId() !== (int)$row->ipb_id ) {
continue;
}
- if ( $restriction->getType() !== 'page' ) {
- continue;
+ switch ( $restriction->getType() ) {
+ case PageRestriction::TYPE:
+ if ( $restriction->getTitle() ) {
+ $items[$restriction->getType()][] = Html::rawElement(
+ 'li',
+ [],
+ Linker::link( $restriction->getTitle() )
+ );
+ }
+ break;
+ case NamespaceRestriction::TYPE:
+ $text = $restriction->getValue() === NS_MAIN
+ ? $this->msg( 'blanknamespace' )
+ : $this->getLanguage()->getFormattedNsText(
+ $restriction->getValue()
+ );
+ $items[$restriction->getType()][] = Html::rawElement(
+ 'li',
+ [],
+ Linker::link(
+ SpecialPage::getTitleValueFor( 'Allpages' ),
+ $text,
+ [],
+ [
+ 'namespace' => $restriction->getValue()
+ ]
+ )
+ );
+ break;
}
-
- $items[] = HTML::rawElement(
- 'li',
- [],
- Linker::link( $restriction->getTitle() )
- );
}
if ( empty( $items ) ) {
return '';
}
+ $sets = [];
+ foreach ( $items as $key => $value ) {
+ $sets[] = Html::rawElement(
+ 'li',
+ [],
+ $this->msg( 'blocklist-editing-' . $key ) . Html::rawElement(
+ 'ul',
+ [],
+ implode( '', $value )
+ )
+ );
+ }
+
return Html::rawElement(
'ul',
[],
- implode( '', $items )
+ implode( '', $sets )
);
}