2019-02-08 17:45:25 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-01 17:28:36 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Special;
|
|
|
|
|
|
|
|
use HtmlArmor;
|
2021-01-02 09:52:35 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
|
2021-01-01 17:28:36 +00:00
|
|
|
use SpecialPage;
|
2021-02-19 18:00:01 +00:00
|
|
|
use TitleValue;
|
2021-01-01 17:28:36 +00:00
|
|
|
use Xml;
|
2019-09-18 21:48:40 +00:00
|
|
|
|
2019-02-08 17:45:25 +00:00
|
|
|
/**
|
|
|
|
* Parent class for AbuseFilter special pages.
|
|
|
|
*/
|
|
|
|
abstract class AbuseFilterSpecialPage extends SpecialPage {
|
2021-01-02 09:52:35 +00:00
|
|
|
|
|
|
|
/** @var AbuseFilterPermissionManager */
|
|
|
|
protected $afPermissionManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param string $restriction
|
|
|
|
* @param AbuseFilterPermissionManager $afPermissionManager
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
$name,
|
|
|
|
$restriction,
|
|
|
|
AbuseFilterPermissionManager $afPermissionManager
|
|
|
|
) {
|
|
|
|
parent::__construct( $name, $restriction );
|
|
|
|
$this->afPermissionManager = $afPermissionManager;
|
|
|
|
}
|
|
|
|
|
2019-02-08 17:45:25 +00:00
|
|
|
/**
|
|
|
|
* Add topbar navigation links
|
|
|
|
*
|
|
|
|
* @param string $pageType
|
|
|
|
*/
|
|
|
|
protected function addNavigationLinks( $pageType ) {
|
2022-07-02 13:35:00 +00:00
|
|
|
$performer = $this->getAuthority();
|
2019-08-27 10:08:17 +00:00
|
|
|
|
2019-02-08 17:45:25 +00:00
|
|
|
$linkDefs = [
|
2021-02-19 18:00:01 +00:00
|
|
|
'home' => 'AbuseFilter',
|
|
|
|
'recentchanges' => 'AbuseFilter/history',
|
|
|
|
'examine' => 'AbuseFilter/examine',
|
2019-02-08 17:45:25 +00:00
|
|
|
];
|
|
|
|
|
2022-07-02 13:35:00 +00:00
|
|
|
if ( $this->afPermissionManager->canViewAbuseLog( $performer ) ) {
|
2021-02-19 18:00:01 +00:00
|
|
|
$linkDefs += [
|
|
|
|
'log' => 'AbuseLog'
|
|
|
|
];
|
2019-02-08 17:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-07-02 13:35:00 +00:00
|
|
|
if ( $this->afPermissionManager->canUseTestTools( $performer ) ) {
|
2021-02-19 18:00:01 +00:00
|
|
|
$linkDefs += [
|
|
|
|
'test' => 'AbuseFilter/test',
|
|
|
|
'tools' => 'AbuseFilter/tools'
|
|
|
|
];
|
2019-02-08 17:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$links = [];
|
|
|
|
|
|
|
|
foreach ( $linkDefs as $name => $page ) {
|
|
|
|
// Give grep a chance to find the usages:
|
|
|
|
// abusefilter-topnav-home, abusefilter-topnav-recentchanges, abusefilter-topnav-test,
|
2019-03-25 18:37:59 +00:00
|
|
|
// abusefilter-topnav-log, abusefilter-topnav-tools, abusefilter-topnav-examine
|
2019-02-08 17:45:25 +00:00
|
|
|
$msgName = "abusefilter-topnav-$name";
|
|
|
|
|
|
|
|
$msg = $this->msg( $msgName )->parse();
|
|
|
|
|
|
|
|
if ( $name === $pageType ) {
|
|
|
|
$links[] = Xml::tags( 'strong', null, $msg );
|
|
|
|
} else {
|
2021-02-19 18:00:01 +00:00
|
|
|
$links[] = $this->getLinkRenderer()->makeLink(
|
|
|
|
new TitleValue( NS_SPECIAL, $page ),
|
|
|
|
new HtmlArmor( $msg )
|
|
|
|
);
|
2019-02-08 17:45:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$linkStr = $this->msg( 'parentheses' )
|
|
|
|
->rawParams( $this->getLanguage()->pipeList( $links ) )
|
|
|
|
->text();
|
|
|
|
$linkStr = $this->msg( 'abusefilter-topnav' )->parse() . " $linkStr";
|
|
|
|
|
|
|
|
$linkStr = Xml::tags( 'div', [ 'class' => 'mw-abusefilter-navigation' ], $linkStr );
|
|
|
|
|
|
|
|
$this->getOutput()->setSubtitle( $linkStr );
|
|
|
|
}
|
|
|
|
}
|