1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
<?php
namespace MediaWiki\Extension\AbuseFilter\Special;
use HtmlArmor;
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
use MediaWiki\Html\Html;
use MediaWiki\SpecialPage\SpecialPage;
use MediaWiki\Title\TitleValue;
/**
* Parent class for AbuseFilter special pages.
*/
abstract class AbuseFilterSpecialPage extends SpecialPage {
/** @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;
}
/**
* @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
*
* @return array
*/
private function getNavigationLinksInternal(): array {
$performer = $this->getAuthority();
$linkDefs = [
'home' => 'AbuseFilter',
'recentchanges' => 'AbuseFilter/history',
'examine' => 'AbuseFilter/examine',
];
if ( $this->afPermissionManager->canViewAbuseLog( $performer ) ) {
$linkDefs += [
'log' => 'AbuseLog'
];
}
if ( $this->afPermissionManager->canUseTestTools( $performer ) ) {
$linkDefs += [
'test' => 'AbuseFilter/test',
'tools' => 'AbuseFilter/tools'
];
}
return $linkDefs;
}
/**
* 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 = [];
foreach ( $linkDefs as $name => $page ) {
// Give grep a chance to find the usages:
// abusefilter-topnav-home, abusefilter-topnav-recentchanges, abusefilter-topnav-test,
// abusefilter-topnav-log, abusefilter-topnav-tools, abusefilter-topnav-examine
$msgName = "abusefilter-topnav-$name";
$msg = $this->msg( $msgName )->parse();
if ( $name === $pageType ) {
$links[] = Html::rawElement( 'strong', [], $msg );
} else {
$links[] = $this->getLinkRenderer()->makeLink(
new TitleValue( NS_SPECIAL, $page ),
new HtmlArmor( $msg )
);
}
}
$linkStr = $this->msg( 'parentheses' )
->rawParams( $this->getLanguage()->pipeList( $links ) )
->escaped();
$linkStr = $this->msg( 'abusefilter-topnav' )->parse() . " $linkStr";
$linkStr = Html::rawElement( 'div', [ 'class' => 'mw-abusefilter-navigation' ], $linkStr );
$this->getOutput()->setSubtitle( $linkStr );
}
}
|