@@ -17,50 +17,69 @@ Many additional bugs fixed.
1717 return ;
1818 }
1919
20- $ . when ( $ . ready , mw . loader . using ( [ 'mediawiki.api' , 'mediawiki.util' ] ) ) . then ( async ( ) => {
21- // add styles
22- mw . util . addCSS (
23- '.unblock-review td { padding: 0 }' +
24- 'td.reason-container { padding-right: 1em; width: 30em }' +
25- '.unblock-review-reason { height: 5em }' ) ;
26-
27- // look for user-block HTML class, which will correspond to {{Unblock}} requests
28- const userBlockBoxes = document . querySelectorAll ( 'div.user-block' ) ;
29- for ( let i = 0 , n = userBlockBoxes . length ; i < n ; i ++ ) {
30- if (
31- userBlockBoxes [ i ] . style [ 'background-color' ] === UNBLOCK_REQ_COLOR_PRE_2025 ||
32- userBlockBoxes [ i ] . style . background === UNBLOCK_REQ_COLOR_POST_2025 ||
33- userBlockBoxes [ i ] . style . background === UNBLOCK_SPAMUN_COLOR
34- ) {
35- // We now have a pending unblock request - add UI
36- const unblockDiv = userBlockBoxes [ i ] ;
37- const [ container , hrEl ] = addTextBoxAndButtons ( unblockDiv ) ;
38- await listenForAcceptAndDecline ( container , hrEl ) ;
39- }
20+ // look for user-block HTML class, which will correspond to {{Unblock}} requests
21+ const userBlockBoxes = document . querySelectorAll ( 'div.user-block' ) ;
22+ for ( let i = 0 , n = userBlockBoxes . length ; i < n ; i ++ ) {
23+ if (
24+ userBlockBoxes [ i ] . style [ 'background-color' ] === UNBLOCK_REQ_COLOR_PRE_2025 ||
25+ userBlockBoxes [ i ] . style . background === UNBLOCK_REQ_COLOR_POST_2025 ||
26+ userBlockBoxes [ i ] . style . background === UNBLOCK_SPAMUN_COLOR
27+ ) {
28+ // We now have a pending unblock request - add UI
29+ const unblockDiv = userBlockBoxes [ i ] ;
30+ const [ container , hrEl ] = addTextBoxAndButtons ( unblockDiv ) ;
31+ await listenForAcceptAndDecline ( container , hrEl ) ;
4032 }
41- } ) ;
33+ }
4234 }
4335
4436 function addTextBoxAndButtons ( unblockDiv ) {
37+ mw . util . addCSS ( `
38+ .unblock-review td { padding: 0 }
39+ td.reason-container { padding-right: 1em; width: 30em }
40+ #unblock-review-autoadd-template { width: 30em; background-color: white; }
41+ .unblock-review-reason { height: 5em }
42+ ` ) ;
43+
4544 const container = document . createElement ( 'table' ) ;
4645 container . className = 'unblock-review' ;
4746 // Note: The innerHtml of the button is sensitive. Is used to figure out which accept/decline wikitext to use. Don't add whitespace to it.
4847 container . innerHTML = `
4948 <tr>
50- <td class=' reason-container' rowspan='2' >
51- <textarea class=' unblock-review-reason mw-ui-input' placeholder=' Reason for accepting/declining here' >${ DEFAULT_DECLINE_REASON } </textarea>
49+ <td class=" reason-container" rowspan="2" >
50+ <textarea class=" unblock-review-reason mw-ui-input" placeholder=" Reason for accepting/declining here" >${ DEFAULT_DECLINE_REASON } </textarea>
5251 </td>
5352 <td>
54- <button class=' unblock-review-accept mw-ui-button mw-ui-progressive' >Accept</button>
53+ <button class=" unblock-review-accept mw-ui-button mw-ui-progressive" >Accept</button>
5554 </td>
5655 </tr>
5756 <tr>
5857 <td>
59- <button class=' unblock-review-decline mw-ui-button mw-ui-destructive' >Decline</button>
58+ <button class=" unblock-review-decline mw-ui-button mw-ui-destructive" >Decline</button>
6059 </td>
61- </tr>` ;
60+ </tr>
61+ <select id="unblock-review-autoadd-template">
62+ <option value="default" selected disabled>Select one of these templates to auto-add it above...</option>
63+ <option>{{subst:2nd chance}}</option>
64+ <option>{{subst:2nd chance autoload}}</option>
65+ <option>{{subst:2nd chance autoload/editintro}}</option>
66+ <option>{{subst:Decline reason here}}</option>
67+ <option>{{subst:Decline spam unblock request}}</option>
68+ <option>{{subst:Decline stale}}</option>
69+ <option>{{subst:Decline-ai}}</option>
70+ <option>{{subst:Declined unblock request for range block text}}</option>
71+ </select>
72+ ` ;
6273 const hrEl = unblockDiv . querySelector ( 'hr' ) ;
6374 unblockDiv . insertBefore ( container , hrEl . previousElementSibling ) ;
75+
76+ // When a template is selected from the dropdown, insert its display text into the reason textarea.
77+ $ ( container ) . find ( '#unblock-review-autoadd-template' ) . on ( 'change' , function ( ) {
78+ // eslint-disable-next-line no-jquery/no-sizzle
79+ const templateText = $ ( this ) . find ( 'option:selected' ) . text ( ) || $ ( this ) . val ( ) || '' ;
80+ $ ( container ) . find ( '.unblock-review-reason' ) . val ( templateText ) ;
81+ } ) ;
82+
6483 return [ container , hrEl ] ;
6584 }
6685
@@ -131,8 +150,10 @@ Many additional bugs fixed.
131150 } ) ;
132151 }
133152
134- mw . loader . using ( 'mediawiki.ui.button' , 'mediawiki.ui.input' ) . then ( async ( ) => {
135- await execute ( ) ;
153+ $ ( async ( ) => {
154+ await mw . loader . using ( [ 'mediawiki.api' , 'mediawiki.util' , 'mediawiki.ui.button' , 'mediawiki.ui.input' ] ) . then ( async ( ) => {
155+ await execute ( ) ;
156+ } ) ;
136157 } ) ;
137158} ( ) ) ;
138159// </nowiki>
0 commit comments