forked from nbdd0121/MW-Avatar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hooks.php
61 lines (47 loc) · 1.61 KB
/
Hooks.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
<?php
namespace Avatar;
class Hooks {
public static function onGetPreferences(\User $user, &$preferences) {
$link = \Linker::link(\SpecialPage::getTitleFor("UploadAvatar"), wfMessage('uploadavatar')->text());
$preferences['editavatar'] = array(
'type' => 'info',
'raw' => true,
'label-message' => 'prefs-editavatar',
'default' => '<img src="' . Avatars::getLinkFor($user->getName()) . '" width="32"></img> ' . $link,
'section' => 'personal/info',
);
return true;
}
public static function onBaseTemplateToolbox(\BaseTemplate &$baseTemplate, array &$toolbox) {
if (isset($baseTemplate->data['nav_urls']['viewavatar'])
&& $baseTemplate->data['nav_urls']['viewavatar']) {
$toolbox['viewavatar'] = $baseTemplate->data['nav_urls']['viewavatar'];
$toolbox['viewavatar']['id'] = 't-viewavatar';
}
}
public static function onSkinTemplateOutputPageBeforeExec(&$skinTemplate, &$tpl) {
$user = $skinTemplate->getRelevantUser();
if ($user) {
$nav_urls = $tpl->get('nav_urls');
$nav_urls['viewavatar'] = [
'text' => wfMessage('sidebar-viewavatar')->text(),
'href' => \SpecialPage::getTitleFor('ViewAvatar')->getLocalURL(array(
'user' => $user->getName(),
)),
];
$tpl->set('nav_urls', $nav_urls);
}
return true;
}
public static function onSetup() {
global $wgAvatarUploadPath, $wgAvatarUploadDirectory;
if ($wgAvatarUploadPath === false) {
global $wgUploadPath;
$wgAvatarUploadPath = $wgUploadPath . '/avatars';
}
if ($wgAvatarUploadDirectory === false) {
global $wgUploadDirectory;
$wgAvatarUploadDirectory = $wgUploadDirectory . '/avatars';
}
}
}