This repository has been archived by the owner on May 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSnapWikiSkin.skin.php
77 lines (67 loc) · 1.87 KB
/
SnapWikiSkin.skin.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
<?php
/**
* SkinTemplate class for SnapWikiSkin
*
* @file
* @ingroup Skins
*/
class HTMLColorField extends HTMLFormField {
public function getInputHTML( $value ) {
$attribs = [
'id' => $this->mID,
'name' => $this->mName,
'value' => $value,
'dir' => $this->mDir,
'pattern' => '#[0-9A-Za-z]{6}',
];
if ( $this->mClass !== '' ) {
$attribs['class'] = $this->mClass;
}
$allowedParams = [
'type',
'pattern',
'title',
'disabled',
'required',
'autofocus',
'readonly',
];
$attribs += $this->getAttributes( $allowedParams );
return Html::input( $this->mName, $value, 'color', $attribs );
}
public function validate( $value, $alldata ) {
if (preg_match('%#[a-zA-Z0-9]{6}%', $value) === 0) {
return $this->msg( 'htmlform-invalid-input' );
}
return parent::validate($value, $alldata);
}
}
class SkinSnapWikiSkin extends SkinTemplate {
var $skinname = 'SnapWikiSkin', $stylename = 'SnapWikiSkin',
$template = 'SnapWikiSkinTemplate', $useHeadElement = true;
/**
* Add CSS via ResourceLoader
*
* @param $out OutputPage
*/
public function setupSkinUserCss( OutputPage $out ) {
parent::setupSkinUserCss( $out );
$out->addModuleStyles( [
'mediawiki.skinning.interface', 'skins.snapwikiskin2'
] );
// make Chrome mobile testing work
$out->addMeta('viewport', 'user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height');
}
static function onGetPreferences( $user, &$preferences ) {
HTMLForm::$typeMappings['color'] = HTMLColorField::class;
$origpref = $user->getOption( 'snapwikiskin-header-color' );
$preferences['snapwikiskin-header-color'] = [
'type' => 'color',
'pattern' => '#[0-9A-Za-z]{6}',
'label-message' => 'snapwikiskin-pref-color',
'section' => 'rendering/skin',
'default' => ($origpref ? $origpref : '#7953c4'),
];
return true;
}
}