Debian Codegraph @

extensions/AbuseFilter/includes/Special/AbuseFilterSpecialPage.php

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