Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
7.87% |
7 / 89 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
AbuseFilterViewHistory | |
7.87% |
7 / 89 |
|
50.00% |
1 / 2 |
216.22 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
show | |
0.00% |
0 / 82 |
|
0.00% |
0 / 1 |
240 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\AbuseFilter\View; |
4 | |
5 | use MediaWiki\Cache\LinkBatchFactory; |
6 | use MediaWiki\Context\IContextSource; |
7 | use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager; |
8 | use MediaWiki\Extension\AbuseFilter\Filter\FilterNotFoundException; |
9 | use MediaWiki\Extension\AbuseFilter\FilterLookup; |
10 | use MediaWiki\Extension\AbuseFilter\Pager\AbuseFilterHistoryPager; |
11 | use MediaWiki\Extension\AbuseFilter\SpecsFormatter; |
12 | use MediaWiki\HTMLForm\HTMLForm; |
13 | use MediaWiki\Linker\Linker; |
14 | use MediaWiki\Linker\LinkRenderer; |
15 | use MediaWiki\User\UserNameUtils; |
16 | use OOUI; |
17 | |
18 | class AbuseFilterViewHistory extends AbuseFilterView { |
19 | |
20 | /** @var int|null */ |
21 | private $filter; |
22 | |
23 | /** @var FilterLookup */ |
24 | private $filterLookup; |
25 | |
26 | /** @var SpecsFormatter */ |
27 | private $specsFormatter; |
28 | |
29 | /** @var UserNameUtils */ |
30 | private $userNameUtils; |
31 | |
32 | /** @var LinkBatchFactory */ |
33 | private $linkBatchFactory; |
34 | |
35 | /** |
36 | * @param UserNameUtils $userNameUtils |
37 | * @param LinkBatchFactory $linkBatchFactory |
38 | * @param AbuseFilterPermissionManager $afPermManager |
39 | * @param FilterLookup $filterLookup |
40 | * @param SpecsFormatter $specsFormatter |
41 | * @param IContextSource $context |
42 | * @param LinkRenderer $linkRenderer |
43 | * @param string $basePageName |
44 | * @param array $params |
45 | */ |
46 | public function __construct( |
47 | UserNameUtils $userNameUtils, |
48 | LinkBatchFactory $linkBatchFactory, |
49 | AbuseFilterPermissionManager $afPermManager, |
50 | FilterLookup $filterLookup, |
51 | SpecsFormatter $specsFormatter, |
52 | IContextSource $context, |
53 | LinkRenderer $linkRenderer, |
54 | string $basePageName, |
55 | array $params |
56 | ) { |
57 | parent::__construct( $afPermManager, $context, $linkRenderer, $basePageName, $params ); |
58 | $this->userNameUtils = $userNameUtils; |
59 | $this->linkBatchFactory = $linkBatchFactory; |
60 | $this->filterLookup = $filterLookup; |
61 | $this->specsFormatter = $specsFormatter; |
62 | $this->specsFormatter->setMessageLocalizer( $context ); |
63 | $this->filter = $this->mParams['filter'] ?? null; |
64 | } |
65 | |
66 | /** |
67 | * Shows the page |
68 | */ |
69 | public function show() { |
70 | $out = $this->getOutput(); |
71 | $out->enableOOUI(); |
72 | $filter = $this->getRequest()->getIntOrNull( 'filter' ) ?: $this->filter; |
73 | $canViewPrivate = $this->afPermManager->canViewPrivateFilters( $this->getAuthority() ); |
74 | $canViewProtectedVars = $this->afPermManager->canViewProtectedVariables( $this->getAuthority() ); |
75 | |
76 | if ( $filter ) { |
77 | $filterObj = null; |
78 | try { |
79 | $filterObj = $this->filterLookup->getFilter( $filter, false ); |
80 | } catch ( FilterNotFoundException $_ ) { |
81 | $filter = null; |
82 | } |
83 | if ( $filterObj && $filterObj->isHidden() && !$canViewPrivate ) { |
84 | $out->addWikiMsg( 'abusefilter-history-error-hidden' ); |
85 | return; |
86 | } |
87 | if ( $filterObj && $filterObj->isProtected() && !$canViewProtectedVars ) { |
88 | $out->addWikiMsg( 'abusefilter-history-error-protected' ); |
89 | return; |
90 | } |
91 | } |
92 | |
93 | if ( $filter ) { |
94 | // Parse wikitext in this message to allow formatting of numero signs (T343994#9209383) |
95 | $out->setPageTitle( $this->msg( 'abusefilter-history' )->numParams( $filter )->parse() ); |
96 | } else { |
97 | $out->setPageTitleMsg( $this->msg( 'abusefilter-filter-log' ) ); |
98 | } |
99 | |
100 | // Useful links |
101 | $links = []; |
102 | if ( $filter ) { |
103 | $links['abusefilter-history-backedit'] = $this->getTitle( $filter )->getFullURL(); |
104 | } |
105 | |
106 | foreach ( $links as $msg => $title ) { |
107 | $links[$msg] = |
108 | new OOUI\ButtonWidget( [ |
109 | 'label' => $this->msg( $msg )->text(), |
110 | 'href' => $title |
111 | ] ); |
112 | } |
113 | |
114 | $backlinks = |
115 | new OOUI\HorizontalLayout( [ |
116 | 'items' => array_values( $links ) |
117 | ] ); |
118 | $out->addHTML( $backlinks ); |
119 | |
120 | // For user |
121 | $user = $this->userNameUtils->getCanonical( |
122 | $this->getRequest()->getText( 'user' ), |
123 | UserNameUtils::RIGOR_VALID |
124 | ); |
125 | if ( $user !== false ) { |
126 | $out->addSubtitle( |
127 | $this->msg( 'abusefilter-history-foruser' ) |
128 | // We don't really need to pass the real user ID |
129 | ->rawParams( Linker::userLink( 1, $user ) ) |
130 | // For GENDER |
131 | ->params( $user ) |
132 | ->parse() |
133 | ); |
134 | } else { |
135 | $user = null; |
136 | } |
137 | |
138 | $formDescriptor = [ |
139 | 'user' => [ |
140 | 'type' => 'user', |
141 | 'name' => 'user', |
142 | 'default' => $user, |
143 | 'size' => '45', |
144 | 'label-message' => 'abusefilter-history-select-user' |
145 | ], |
146 | 'filter' => [ |
147 | 'type' => 'int', |
148 | 'name' => 'filter', |
149 | 'default' => $filter ?: '', |
150 | 'size' => '45', |
151 | 'label-message' => 'abusefilter-history-select-filter' |
152 | ], |
153 | ]; |
154 | |
155 | $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ); |
156 | $htmlForm->setSubmitTextMsg( 'abusefilter-history-select-submit' ) |
157 | ->setWrapperLegendMsg( 'abusefilter-history-select-legend' ) |
158 | ->setTitle( $this->getTitle( 'history' ) ) |
159 | ->setMethod( 'get' ) |
160 | ->prepareForm() |
161 | ->displayForm( false ); |
162 | |
163 | $pager = new AbuseFilterHistoryPager( |
164 | $this->getContext(), |
165 | $this->linkRenderer, |
166 | $this->linkBatchFactory, |
167 | $this->filterLookup, |
168 | $this->specsFormatter, |
169 | $filter, |
170 | $user, |
171 | $canViewPrivate, |
172 | $canViewProtectedVars |
173 | ); |
174 | |
175 | $out->addParserOutputContent( $pager->getFullOutput() ); |
176 | } |
177 | } |