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
|
|
|
/**
|
2022-08-17 20:07:25 +00:00
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getShortDescription( string $path = '' ): string {
|
|
|
|
switch ( $path ) {
|
|
|
|
case 'AbuseFilter':
|
|
|
|
return $this->msg( 'abusefilter-topnav-home' )->text();
|
|
|
|
case 'AbuseFilter/history':
|
|
|
|
return $this->msg( 'abusefilter-topnav-recentchanges' )->text();
|
|
|
|
case 'AbuseFilter/examine':
|
|
|
|
return $this->msg( 'abusefilter-topnav-examine' )->text();
|
|
|
|
case 'AbuseFilter/test':
|
|
|
|
return $this->msg( 'abusefilter-topnav-test' )->text();
|
|
|
|
case 'AbuseFilter/tools':
|
|
|
|
return $this->msg( 'abusefilter-topnav-tools' )->text();
|
|
|
|
default:
|
|
|
|
return parent::getShortDescription( $path );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get topbar navigation links definitions
|
2019-02-08 17:45:25 +00:00
|
|
|
*
|
2022-08-17 20:07:25 +00:00
|
|
|
* @return array
|
2019-02-08 17:45:25 +00:00
|
|
|
*/
|
2022-08-17 20:07:25 +00:00
|
|
|
private function getNavigationLinksInternal(): array {
|
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
|
|
|
}
|
|
|
|
|
2022-08-17 20:07:25 +00:00
|
|
|
return $linkDefs;
|
|
|
|
}
|
2019-02-08 17:45:25 +00:00
|
|
|
|
2022-08-17 20:07:25 +00:00
|
|
|
/**
|
|
|
|
* Return an array of strings representing page titles that are discoverable to end users via UI.
|
|
|
|
*
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getAssociatedNavigationLinks(): array {
|
|
|
|
$links = $this->getNavigationLinksInternal();
|
|
|
|
return array_map( static function ( $name ) {
|
|
|
|
return 'Special:' . $name;
|
|
|
|
}, array_values( $links ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add topbar navigation links
|
|
|
|
*
|
|
|
|
* @param string $pageType
|
|
|
|
*/
|
|
|
|
protected function addNavigationLinks( $pageType ) {
|
|
|
|
// If the current skin supports sub menus nothing to do here.
|
|
|
|
if ( $this->getSkin()->supportsMenu( 'associated-pages' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$linkDefs = $this->getNavigationLinksInternal();
|
|
|
|
$links = [];
|
2019-02-08 17:45:25 +00:00
|
|
|
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 ) )
|
2023-10-05 20:51:21 +00:00
|
|
|
->escaped();
|
2019-02-08 17:45:25 +00:00
|
|
|
$linkStr = $this->msg( 'abusefilter-topnav' )->parse() . " $linkStr";
|
|
|
|
|
|
|
|
$linkStr = Xml::tags( 'div', [ 'class' => 'mw-abusefilter-navigation' ], $linkStr );
|
|
|
|
|
|
|
|
$this->getOutput()->setSubtitle( $linkStr );
|
|
|
|
}
|
|
|
|
}
|