/
BlockMessageDetails.js
201 lines (192 loc) · 5.91 KB
/
BlockMessageDetails.js
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
'use strict';
const Button = require( '../mobile.startup/Button' ),
View = require( '../mobile.startup/View' ),
Icon = require( '../mobile.startup/Icon' ),
util = require( '../mobile.startup/util' );
/**
* @extends View
*/
class BlockMessageDetails extends View {
/** @inheritdoc */
get isTemplateMode() {
return true;
}
/**
* @inheritdoc
*/
get defaults() {
return {
createDetailsAnchorHref: function () {
return function ( blockId, render ) {
return mw.util.getUrl( 'Special:BlockList', { wpTarget: '#' + render( blockId ) } );
};
},
createDetailsAnchorLabel: function () {
return mw.msg( 'mobile-frontend-editor-blocked-drawer-help' );
},
createTitle: function () {
let msgKey = 'mobile-frontend-editor-blocked-drawer-title';
if ( mw.user.isAnon() ) {
msgKey += '-ip';
}
if ( this.partial ) {
msgKey += '-partial';
}
// The following messages can be passed here:
// * mobile-frontend-editor-blocked-drawer-title
// * mobile-frontend-editor-blocked-drawer-title-partial
// * mobile-frontend-editor-blocked-drawer-title-ip
// * mobile-frontend-editor-blocked-drawer-title-ip-partial
return mw.msg( msgKey );
},
createBody: function () {
let msgKey = '';
if ( mw.user.isAnon() && this.anonOnly ) {
msgKey = 'mobile-frontend-editor-blocked-drawer-body';
if ( this.noCreateAccount ) {
msgKey += '-login';
} else {
msgKey += '-login-createaccount';
}
if ( this.partial ) {
msgKey += '-partial';
}
} else {
if ( this.partial ) {
msgKey = 'mobile-frontend-editor-blocked-drawer-body-partial';
}
}
// The following messages can be passed here:
// * mobile-frontend-editor-blocked-drawer-body-partial
// * mobile-frontend-editor-blocked-drawer-body-login
// * mobile-frontend-editor-blocked-drawer-body-login-partial
// * mobile-frontend-editor-blocked-drawer-body-login-createaccount
// * mobile-frontend-editor-blocked-drawer-body-login-createaccount-partial
return msgKey ? mw.msg( msgKey ) : msgKey;
},
seeMoreLink: mw.msg( 'mobile-frontend-editor-blocked-drawer-body-link' ),
reasonHeader: mw.msg( 'mobile-frontend-editor-blocked-drawer-reason-header' ),
creatorHeader: function () {
// The gender is the subject (the blockee) not the object (the blocker).
return mw.msg( 'mobile-frontend-editor-blocked-drawer-creator-header',
mw.user.options.get( 'gender' ) );
},
expiryHeader: mw.msg( 'mobile-frontend-editor-blocked-drawer-expiry-header' )
};
}
/**
* Configure the call to action depending on the type of block.
*
* @return {Object} Configuration options
*/
getButtonConfig() {
let cta = true;
const config = {
progressive: true
},
wiki = mw.config.get( 'wgDBname' );
if ( mw.user.isAnon() && this.options.anonOnly ) {
// The user can avoid the block by logging in
config.label = mw.msg( 'mobile-frontend-editor-blocked-drawer-action-login' );
config.href = new mw.Title( 'Special:UserLogin' ).getUrl();
} else if ( this.options.partial ) {
// The user can avoid the block by editing a different page
config.label = mw.msg( 'mobile-frontend-editor-blocked-drawer-action-randompage' );
config.href = new mw.Title( 'Special:Random' ).getUrl();
config.quiet = true;
} else {
// The user cannot avoid the block
config.tagName = 'button';
config.label = mw.msg( 'mobile-frontend-editor-blocked-drawer-action-ok' );
config.additionalClassNames = 'cancel';
cta = false;
}
if ( cta && mw.config.get( 'wgMFTrackBlockNotices' ) ) {
mw.track( 'counter.MediaWiki.BlockNotices.' + wiki + '.MobileFrontend.ctaShown', 1 );
config.events = {
click: function () {
mw.track( 'counter.MediaWiki.BlockNotices.' + wiki + '.MobileFrontend.ctaClicked', 1 );
}
};
}
return config;
}
/**
* @inheritdoc
*/
postRender() {
const drawer = this;
this.$el.find( '.block-message-buttons' ).prepend(
new Button( this.getButtonConfig() ).$el
);
this.$el.find( '.block-message-icon' ).prepend(
( new Icon( {
icon: 'block-destructive'
} ) ).$el
);
this.options.parsedReason.then( function ( htmlReason ) {
drawer.$el.find( '.block-message-reason div' ).html( htmlReason );
} );
}
/**
* @inheritdoc
*/
get template() {
return util.template( `
<div class="block-message block-message-container">
<div class="block-message-icon"></div>
<div class="block-message-info">
<div class="block-message-item block-message-title">
<h5>{{ createTitle }}</h5>
</div>
<div class="block-message-data">
<div class="block-message-item">
<p>
{{ createBody }}
<a class ="block-message-see-more" href="#">{{ seeMoreLink }}</a>
</p>
</div>
<div class="block-message-item block-message-creator">
{{#creator.name}}
<p>
{{ creatorHeader }}
<strong>
{{#creator.url}}
<a href="{{ creator.url }}">{{ creator.name }}</a>
{{/creator.url}}
{{^creator.url}}
{{ creator.name }}
{{/creator.url}}
</strong>
</p>
{{/creator.name}}
</div>
{{#duration}}
<div class="block-message-item">
<p>
{{ expiryHeader }}
<strong>{{ duration }}</strong>
</p>
</div>
{{/duration}}
{{#blockId}}
<div class="block-message-item">
<a href="{{#createDetailsAnchorHref}}{{ blockId }}{{/createDetailsAnchorHref}}">
{{ createDetailsAnchorLabel }}
</a>
</div>
{{/blockId}}
</div>
</div>
{{#reason}}
<div class="block-message-item block-message-reason">
<h5>{{ reasonHeader }}</h5>
<div><p>{{{ reason }}}</p></div>
</div>
{{/reason}}
<div class="block-message-buttons">
</div>
</div>` );
}
}
module.exports = BlockMessageDetails;