Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
97.56% |
40 / 41 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
PreferencesHookHandler | |
97.56% |
40 / 41 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
onGetPreferences | |
97.56% |
40 / 41 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ |
16 | |
17 | namespace ORES\Hooks; |
18 | |
19 | use MediaWiki\Preferences\Hook\GetPreferencesHook; |
20 | use MediaWiki\User\User; |
21 | |
22 | class PreferencesHookHandler implements GetPreferencesHook { |
23 | |
24 | /** |
25 | * GetPreferences hook, adding ORES section, letting people choose a threshold |
26 | * Also let people make hidenondamaging default |
27 | * |
28 | * @param User $user |
29 | * @param array[] &$preferences |
30 | */ |
31 | public function onGetPreferences( $user, &$preferences ) { |
32 | global $wgOresFiltersThresholds; |
33 | |
34 | if ( !Helpers::oresUiEnabled() || !Helpers::isModelEnabled( 'damaging' ) ) { |
35 | return; |
36 | } |
37 | |
38 | $options = []; |
39 | foreach ( Helpers::$damagingPrefMap as $prefName => $level ) { |
40 | // In other places, we look at the keys of getDamagingThresholds() to determine which |
41 | // damaging levels exist, but it can drop levels from its output if the ORES API |
42 | // has issues. We don't want preference definitions to be potentially unstable. |
43 | // So instead, we use $wgOresFiltersThresholds directly so the preference definition |
44 | // only depends on the configuration. |
45 | if ( |
46 | isset( $wgOresFiltersThresholds[ 'damaging' ][ $level ] ) && |
47 | $wgOresFiltersThresholds[ 'damaging' ][ $level ] !== false |
48 | ) { |
49 | $options[ 'ores-damaging-' . $level ] = $prefName; |
50 | } |
51 | } |
52 | |
53 | $preferences['oresDamagingPref'] = [ |
54 | 'type' => 'select', |
55 | 'label-message' => 'ores-pref-damaging', |
56 | 'section' => 'watchlist/ores-wl', |
57 | 'options-messages' => $options, |
58 | 'help-message' => 'ores-help-damaging-pref', |
59 | ]; |
60 | |
61 | $preferences['rcOresDamagingPref'] = [ |
62 | 'type' => 'select', |
63 | 'label-message' => 'ores-pref-damaging', |
64 | 'section' => 'rc/ores-rc', |
65 | 'options-messages' => $options, |
66 | 'help-message' => 'ores-help-damaging-pref', |
67 | ]; |
68 | |
69 | // highlight damaging edits based on configured sensitivity |
70 | $preferences['oresHighlight'] = [ |
71 | 'type' => 'toggle', |
72 | 'section' => 'watchlist/ores-wl', |
73 | 'label-message' => 'ores-pref-highlight', |
74 | ]; |
75 | |
76 | // Control whether the "r" appears on RC |
77 | $preferences['ores-damaging-flag-rc'] = [ |
78 | 'type' => 'toggle', |
79 | 'section' => 'rc/ores-rc', |
80 | 'label-message' => 'ores-pref-damaging-flag', |
81 | ]; |
82 | |
83 | // Make hidenondamaging default |
84 | $preferences['oresWatchlistHideNonDamaging'] = [ |
85 | 'type' => 'toggle', |
86 | 'section' => 'watchlist/ores-wl', |
87 | 'label-message' => 'ores-pref-watchlist-hidenondamaging', |
88 | ]; |
89 | $preferences['oresRCHideNonDamaging'] = [ |
90 | 'type' => 'toggle', |
91 | 'section' => 'rc/ores-rc', |
92 | 'label-message' => 'ores-pref-rc-hidenondamaging', |
93 | ]; |
94 | } |
95 | |
96 | } |