forked from librewiki/liberty-skin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibertyHooks.php
161 lines (147 loc) · 5.26 KB
/
LibertyHooks.php
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php //phpcs:ignore
class LibertyHooks extends Hooks {
/**
* @since 1.17.0
* @param OutputPage $out
* @param Skin $sk
* @param array &$bodyAttrs
*/
public static function onOutputPageBodyAttributes( OutputPage $out, Skin $sk, &$bodyAttrs ) {
if ( $sk->getSkinName() === 'liberty' ) {
$bodyAttrs['class'] .= ' Liberty width-size';
}
}
/**
* Set up user preferences specific to the Liberty skin.
*
* @param User $user user
* @param Preferences &$preferences preferences
*/
public static function onGetPreferences( $user, &$preferences ) {
global $wgLibertyAdSetting, $wgLibertyAdGroup;
$service = MediaWiki\MediaWikiServices::getInstance();
$userGroupManager = $service->getUserGroupManager();
$userGroups = $userGroupManager->getUserGroups( $user );
$permissionManager = $service->getPermissionManager();
$preferences['liberty-layout-width'] = [
'type' => 'select',
'label-message' => 'liberty-pref-layout-width',
'section' => 'liberty/layout',
'options' => [
wfMessage( 'liberty-layout-select-1000' )->text() => '1000px',
wfMessage( 'liberty-layout-select-1100' )->text() => '1100px',
wfMessage( 'liberty-layout-select-1200' )->text() => null,
wfMessage( 'liberty-layout-select-1300' )->text() => '1300px',
wfMessage( 'liberty-layout-select-1400' )->text() => '1400px',
wfMessage( 'liberty-layout-select-1500' )->text() => '1500px',
wfMessage( 'liberty-layout-select-1600' )->text() => '1600px',
],
'help-message' => 'liberty-pref-layout-width-help',
'default' => null
];
$preferences['liberty-layout-navfix'] = [
'type' => 'toggle',
'label-message' => 'liberty-pref-layout-navfix',
'section' => 'liberty/layout',
];
$preferences['liberty-layout-sidebar'] = [
'type' => 'toggle',
'label-message' => 'liberty-pref-layout-sidebar',
'section' => 'liberty/layout',
];
$preferences['liberty-layout-controlbar'] = [
'type' => 'toggle',
'label-message' => 'liberty-pref-layout-controlbar',
'section' => 'liberty/layout',
];
if (
isset( $wgLibertyAdSetting['client'] ) && $wgLibertyAdSetting['client'] &&
isset( $wgLibertyAdGroup ) && $wgLibertyAdGroup == 'differ'
) {
if (
isset( $wgLibertyAdSetting['belowarticle'] ) && $wgLibertyAdSetting['belowarticle'] &&
$permissionManager->userHasRight( $user, 'blockads-belowarticle' )
) {
$preferences['liberty-ads-morearticle'] = [
'type' => 'toggle',
'label-message' => 'liberty-pref-ads-belowarticle',
'section' => 'liberty/ads',
];
}
if (
isset( $wgLibertyAdSetting['header'] ) && $wgLibertyAdSetting['header'] &&
$permissionManager->userHasRight( $user, 'blockads-header' )
) {
$preferences['liberty-ads-header'] = [
'type' => 'toggle',
'label-message' => 'liberty-pref-ads-header',
'section' => 'liberty/ads',
];
}
if (
isset( $wgLibertyAdSetting['right'] ) && $wgLibertyAdSetting['right'] &&
$permissionManager->userHasRight( $user, 'blockads-right' )
) {
$preferences['liberty-ads-rightads'] = [
'type' => 'toggle',
'label-message' => 'liberty-pref-ads-right',
'section' => 'liberty/ads',
];
}
if (
isset( $wgLibertyAdSetting['bottom'] ) && $wgLibertyAdSetting['bottom'] &&
$permissionManager->userHasRight( $user, 'blockads-bottom' )
) {
$preferences['liberty-ads-bottom'] = [
'type' => 'toggle',
'label-message' => 'liberty-pref-ads-bottom',
'section' => 'liberty/ads',
];
}
}
$preferences['liberty-color-main'] = [
'type' => 'text',
'label-message' => 'liberty-pref-color-main',
'section' => 'liberty/color',
'help-message' => 'liberty-pref-color-main-help'
];
$preferences['liberty-color-second'] = [
'type' => 'text',
'label-message' => 'liberty-pref-color-second',
'section' => 'liberty/color',
'help-message' => 'liberty-pref-color-second-help'
];
$preferences['liberty-font'] = [
'type' => 'selectorother',
'label-message' => 'liberty-pref-fonts',
'section' => 'liberty/font',
'options' => [
wfMessage( 'liberty-font-name-default' )->text() => null,
wfMessage( 'liberty-font-name-noto-sans-kr' )->text() => 'Noto Sans KR',
wfMessage( 'liberty-font-name-noto-serif-kr' )->text() => 'Noto Serif KR',
wfMessage( 'liberty-font-name-spoqa-han-sans' )->text() => 'Spoqa Han Sans',
wfMessage( 'liberty-font-name-nanum-gothic' )->text() => 'Nanum Gothic',
wfMessage( 'liberty-font-name-nanum-myeongjo' )->text() => 'Nanum Myeongjo',
wfMessage( 'liberty-font-name-dokdo' )->text() => 'Dokdo',
wfMessage( 'liberty-font-name-gaegu' )->text() => 'Gaegu',
wfMessage( 'liberty-font-name-hankc' )->text() => 'Hankc',
wfMessage( 'liberty-font-name-youth' )->text() => 'Youth',
wfMessage( 'liberty-font-name-malgun-gothic' )->text() => 'Malgun Gothic'
],
'help-message' => 'liberty-pref-fonts-help',
'default' => null,
];
$preferences['liberty-dark'] = [
'type' => 'select',
'label-message' => 'liberty-pref-dark',
'section' => 'liberty/color',
'options' => [
wfMessage( 'liberty-dark-default' )->text() => null,
wfMessage( 'liberty-dark-dark' )->text() => 'dark',
wfMessage( 'liberty-dark-light' )->text() => 'light'
],
'help-message' => 'liberty-pref-dark-help',
'default' => null
];
}
}