| 1 |
const { defineStore } = require( 'pinia' ); |
| 2 |
const { computed, ref } = require( 'vue' ); |
| 3 |
const api = new mw.Api(); |
| 4 |
|
| 5 |
module.exports = exports = defineStore( 'block', () => { |
| 6 |
const formErrors = ref( mw.config.get( 'blockPreErrors' ) || [] ); |
| 7 |
const targetUser = ref( mw.config.get( 'blockTargetUser' ) || '' ); |
| 8 |
const alreadyBlocked = ref( mw.config.get( 'blockAlreadyBlocked' ) || false ); |
| 9 |
const type = ref( mw.config.get( 'blockTypePreset' ) || 'sitewide' ); |
| 10 |
const expiry = ref( '' ); |
| 11 |
const partialOptions = ref( [ 'ipb-action-create' ] ); |
| 12 |
const pages = ref( |
| 13 |
( mw.config.get( 'blockPageRestrictions' ) || '' ) |
| 14 |
.split( '\n' ) |
| 15 |
.filter( Boolean ) |
| 16 |
); |
| 17 |
const namespaces = ref( |
| 18 |
( mw.config.get( 'blockNamespaceRestrictions' ) || '' ) |
| 19 |
.split( '\n' ) |
| 20 |
.filter( Boolean ) |
| 21 |
.map( Number ) |
| 22 |
); |
| 23 |
const reason = ref( 'other' ); |
| 24 |
const reasonOther = ref( mw.config.get( 'blockReasonOtherPreset' ) || '' ); |
| 25 |
const details = ref( mw.config.get( 'blockDetailsPreset' ) || [] ); |
| 26 |
|
| 27 |
|
| 28 |
const hideNameDisabled = computed( () => { |
| 29 |
return type.value !== 'sitewide' || !mw.util.isInfinity( expiry.value ); |
| 30 |
} ); |
| 31 |
const additionalDetails = ref( mw.config.get( 'blockAdditionalDetailsPreset' ) || [] ); |
| 32 |
|
| 33 |
|
| 34 |
const confirmationRequired = computed( () => { |
| 35 |
return targetUser.value === mw.config.get( 'wgUserName' ) || ( |
| 36 |
type.value === 'sitewide' && |
| 37 |
additionalDetails.value.indexOf( 'wpHideName' ) !== -1 && |
| 38 |
!hideNameDisabled.value |
| 39 |
); |
| 40 |
} ); |
| 41 |
const confirmationChecked = ref( false ); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
function doBlock() { |
| 49 |
const params = { |
| 50 |
action: 'block', |
| 51 |
reblock: alreadyBlocked.value ? 1 : 0, |
| 52 |
format: 'json', |
| 53 |
user: targetUser.value, |
| 54 |
|
| 55 |
expiry: expiry.value.replace( /\.000$/, '' ), |
| 56 |
|
| 57 |
uselang: mw.config.get( 'wgUserLanguage' ), |
| 58 |
errorlang: mw.config.get( 'wgUserLanguage' ), |
| 59 |
errorsuselocal: true |
| 60 |
}; |
| 61 |
|
| 62 |
|
| 63 |
if ( reason.value === 'other' ) { |
| 64 |
params.reason = reasonOther.value; |
| 65 |
} else { |
| 66 |
params.reason = reason.value + ( |
| 67 |
reasonOther.value ? mw.msg( 'colon-separator' ) + reasonOther.value : '' |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
if ( type.value === 'partial' ) { |
| 72 |
const actionRestrictions = []; |
| 73 |
params.partial = 1; |
| 74 |
if ( partialOptions.value.indexOf( 'ipb-action-upload' ) !== -1 ) { |
| 75 |
actionRestrictions.push( 'upload' ); |
| 76 |
} |
| 77 |
if ( partialOptions.value.indexOf( 'ipb-action-move' ) !== -1 ) { |
| 78 |
actionRestrictions.push( 'move' ); |
| 79 |
} |
| 80 |
if ( partialOptions.value.indexOf( 'ipb-action-create' ) !== -1 ) { |
| 81 |
actionRestrictions.push( 'create' ); |
| 82 |
} |
| 83 |
params.actionrestrictions = actionRestrictions.join( '|' ); |
| 84 |
|
| 85 |
if ( pages.value.length ) { |
| 86 |
params.pagerestrictions = pages.value.join( '|' ); |
| 87 |
} |
| 88 |
if ( namespaces.value.length ) { |
| 89 |
params.namespacerestrictions = namespaces.value.join( '|' ); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
if ( details.value.indexOf( 'wpCreateAccount' ) !== -1 ) { |
| 94 |
params.nocreate = 1; |
| 95 |
} |
| 96 |
|
| 97 |
if ( details.value.indexOf( 'wpDisableEmail' ) !== -1 ) { |
| 98 |
params.noemail = 1; |
| 99 |
} |
| 100 |
|
| 101 |
if ( details.value.indexOf( 'wpDisableUTEdit' ) === -1 ) { |
| 102 |
params.allowusertalk = 1; |
| 103 |
} |
| 104 |
|
| 105 |
if ( additionalDetails.value.indexOf( 'wpAutoBlock' ) !== -1 ) { |
| 106 |
params.autoblock = 1; |
| 107 |
} |
| 108 |
|
| 109 |
if ( additionalDetails.value.indexOf( 'wpHideName' ) !== -1 ) { |
| 110 |
params.hidename = 1; |
| 111 |
} |
| 112 |
|
| 113 |
if ( additionalDetails.value.indexOf( 'wpWatch' ) !== -1 ) { |
| 114 |
params.watchuser = 1; |
| 115 |
} |
| 116 |
|
| 117 |
if ( additionalDetails.value.indexOf( 'wpHardBlock' ) !== -1 ) { |
| 118 |
params.nocreate = 1; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
formErrors.value = []; |
| 123 |
|
| 124 |
return api.postWithEditToken( params ); |
| 125 |
} |
| 126 |
|
| 127 |
return { |
| 128 |
formErrors, |
| 129 |
targetUser, |
| 130 |
alreadyBlocked, |
| 131 |
type, |
| 132 |
expiry, |
| 133 |
partialOptions, |
| 134 |
pages, |
| 135 |
namespaces, |
| 136 |
reason, |
| 137 |
reasonOther, |
| 138 |
details, |
| 139 |
hideNameDisabled, |
| 140 |
additionalDetails, |
| 141 |
confirmationRequired, |
| 142 |
confirmationChecked, |
| 143 |
doBlock |
| 144 |
}; |
| 145 |
} ); |