-
Notifications
You must be signed in to change notification settings - Fork 12
/
SpecialView.php
executable file
·140 lines (111 loc) · 3.6 KB
/
SpecialView.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
<?php
namespace Avatar;
use MediaWiki\MediaWikiServices;
class SpecialView extends \SpecialPage {
public function __construct() {
parent::__construct('ViewAvatar');
}
public function execute($par) {
// Shortcut by using $par
if ($par) {
$this->getOutput()->redirect($this->getPageTitle()->getLinkURL(array(
'user' => $par,
)));
return;
}
$this->setHeaders();
$this->outputHeader();
// Parse options
$opt = new \FormOptions;
$opt->add('user', '');
$opt->add('delete', '');
$opt->add('reason', '');
$opt->fetchValuesFromRequest($this->getRequest());
// Parse user
$user = $opt->getValue('user');
$userObj = \User::newFromName($user);
$userExists = $userObj && $userObj->getId() !== 0;
// If current task is delete and user is not allowed
$canDoAdmin = MediaWikiServices::getInstance()->getPermissionManager()->userHasRight($this->getUser(), 'avataradmin');
if ($opt->getValue('delete')) {
if (!$canDoAdmin) {
throw new \PermissionsError('avataradmin');
}
// Delete avatar if the user exists
if ($userExists) {
if (Avatars::deleteAvatar($userObj)) {
global $wgAvatarLogInRC;
$logEntry = new \ManualLogEntry('avatar', 'delete');
$logEntry->setPerformer($this->getUser());
$logEntry->setTarget($userObj->getUserPage());
$logEntry->setComment($opt->getValue('reason'));
$logId = $logEntry->insert();
$logEntry->publish($logId, $wgAvatarLogInRC ? 'rcandudp' : 'udp');
}
}
}
$this->getOutput()->addModules(array('mediawiki.userSuggest'));
$this->showForm($user);
if ($userExists) {
$haveAvatar = Avatars::hasAvatar($userObj);
if ($haveAvatar) {
$html = \Xml::tags('img', array(
'src' => Avatars::getLinkFor($user, 'original') . '&nocache&ver=' . dechex(time()),
'height' => 400,
), '');
$html = \Xml::tags('p', array(), $html);
$this->getOutput()->addHTML($html);
// Add a delete button
if ($canDoAdmin) {
$this->showDeleteForm($user);
}
} else {
$this->getOutput()->addWikiMsg('viewavatar-noavatar');
}
} else if ($user) {
$this->getOutput()->addWikiMsg('viewavatar-nouser');
}
}
private function showForm($user) {
global $wgScript;
// This is essential as we need to submit the form to this page
$html = \Html::hidden('title', $this->getPageTitle());
$html .= \Xml::inputLabel(
$this->msg('viewavatar-username')->text(),
'user',
'',
45,
$user,
array('class' => 'mw-autocomplete-user') # This together with mediawiki.userSuggest will give us an auto completion
);
$html .= ' ';
// Submit button
$html .= \Xml::submitButton($this->msg('viewavatar-submit')->text());
// Fieldset
$html = \Xml::fieldset($this->msg('viewavatar-legend')->text(), $html);
// Wrap with a form
$html = \Xml::tags('form', array('action' => $wgScript, 'method' => 'get'), $html);
$this->getOutput()->addHTML($html);
}
private function showDeleteForm($user) {
global $wgScript;
// This is essential as we need to submit the form to this page
$html = \Html::hidden('title', $this->getPageTitle());
$html .= \Html::hidden('delete', 'true');
$html .= \Html::hidden('user', $user);
$html .= \Xml::inputLabel(
$this->msg('viewavatar-delete-reason')->text(),
'reason',
'',
45
);
$html .= ' ';
// Submit button
$html .= \Xml::submitButton($this->msg('viewavatar-delete-submit')->text());
// Fieldset
$html = \Xml::fieldset($this->msg('viewavatar-delete-legend')->text(), $html);
// Wrap with a form
$html = \Xml::tags('form', array('action' => $wgScript, 'method' => 'get'), $html);
$this->getOutput()->addHTML($html);
}
}