-
Notifications
You must be signed in to change notification settings - Fork 0
/
UespPatreonHooks.php
136 lines (108 loc) · 3.64 KB
/
UespPatreonHooks.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
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This is a MediaWiki extension and must be run from within MediaWiki.' );
}
require_once("/home/uesp/secrets/patreon.secrets");
global $wgSharedTables;
$wgSharedTables[] = 'patreon_user';
class UespPatreonHooks {
/**
* UserGetDefaultOptions hook handler
* @param $defaultOptions Array of default preference keys and values
* @return bool
*/
public static function userGetDefaultOptions( &$defaultOptions ) {
$defaultOptions['uesppatreon-shirtsize'] = 'Not Set';
return true;
}
/**
* GetPreferences hook handler.
* @param $user User
* @param $preferences Array: Preference descriptions
* @return bool
*/
public static function getPreferences( $user, &$preferences )
{
$patreonId = SpecialUespPatreon::loadPatreonUserId();
if ($patreonId <= 0) {
$text = wfMessage( "uesppatreon-link" )->parse();
$authorizationUrl = SpecialUespPatreon::getLink("redirect");
}
else {
$text = wfMessage( "uesppatreon-unlink" )->parse();
$authorizationUrl = SpecialUespPatreon::getLink("unlink");
}
$text = str_replace("https://patreon.com", $authorizationUrl, $text);
$text .= wfMessage( "uesppatreon-linkmsg" )->parse();
$preferences['uesppatreon-link'] =
array(
'type' => 'info',
'label' => ' ',
'default' => $text,
'section' => 'uesppatreon/uesppatreon-link',
'raw' => 1,
'rawrow' => 1,
);
$patreonUser = SpecialUespPatreon::loadPatreonUser();
if ($patreonId > 0 && $patreonUser != null)
{
$appCode = SpecialUespPatreon::loadPatreonAppCode();
if ($appCode < 0) $appCode = "NO CODE AVAILABLE (code missing)";
if ($patreonUser['lifetimePledgeCents'] < 0)
{
$appCode = "CODE NOT AVAILABLE</b> (usually available within the hour after subscribing for new patrons)<b>";
}
$text = wfMessage( "uesppatreon-appcodemsg" )->parse();
$text = str_replace("APPCODE", $appCode, $text);
$preferences['uesppatreon-appcode'] =
array(
'type' => 'info',
'label' => ' ',
'default' => $text,
'section' => 'uesppatreon/uesppatreon-appcode',
'raw' => 1,
'rawrow' => 1,
);
}
$text = "Reward options may be selected here in the future.";
/*
$preferences['uesppatreon-options'] =
array(
'type' => 'info',
'label' => ' ',
'default' => $text,
'section' => 'uesppatreon/uesppatreon-options',
'raw' => 1,
'rawrow' => 1,
); */
$preferences['uesppatreon-shirtsize'] =
array(
'type' => 'select',
'label' => 'Select your preferred shirt size:',
'section' => 'uesppatreon/uesppatreon-options',
'options' => [
'Not Set' => 'Not Set',
'Small' => 'Small',
'Medium' => 'Medium',
'Large' => 'Large',
'X-Large' => 'X-Large',
'XX-Large' => 'XX-Large',
'XXX-Large' => 'XXX-Large',
'XXXX-Large' => 'XXXX-Large',
],
'raw' => 1,
'rawrow' => 1,
);
return true;
}
public static function onLoadExtensionSchemaUpdates( $updater ) {
$sql = __DIR__ . '/sql';
$updater->addExtensionUpdate( [ 'addTable', 'patreon_user', "$sql/patreon_user.sql", true ] );
$updater->addExtensionUpdate( [ 'addTable', 'patreon_tierchange', "$sql/patreon_tierchange.sql", true ] );
$updater->addExtensionUpdate( [ 'addTable', 'patreon_info', "$sql/patreon_info.sql", true ] );
$updater->addExtensionUpdate( [ 'addTable', 'patreon_shipment', "$sql/patreon_shipments.sql", true ] );
$updater->addExtensionUpdate( [ 'addTable', 'patreon_reward', "$sql/patreon_reward.sql", true ] );
$updater->addExtensionUpdate( [ 'addTable', 'patreon_tag', "$sql/patreon_tag.sql", true ] );
return true;
}
};