| 1 |
<template> |
| 2 |
<cdx-accordion> |
| 3 |
<template #title> |
| 4 |
{{ $i18n( 'block-user-previous-blocks' ).text() }} |
| 5 |
</template> |
| 6 |
<cdx-table |
| 7 |
class="mw-block-previous-blocks" |
| 8 |
:caption="$i18n( 'block-user-previous-blocks' ).text()" |
| 9 |
:columns="columns" |
| 10 |
:data="data" |
| 11 |
:use-row-headers="true" |
| 12 |
:hide-caption="true" |
| 13 |
> |
| 14 |
<template #empty-state> |
| 15 |
{{ $i18n( 'block-user-no-previous-blocks' ).text() }} |
| 16 |
</template> |
| 17 |
<template #item-timestamp="{ item }"> |
| 18 |
<a |
| 19 |
:href="mw.util.getUrl( 'Special:Log', { logid: item.logid } )" |
| 20 |
> |
| 21 |
{{ util.formatTimestamp( item.timestamp ) }} |
| 22 |
</a> |
| 23 |
</template> |
| 24 |
<template #item-type="{ item }"> |
| 25 |
{{ util.getBlockActionMessage( item ) }} |
| 26 |
</template> |
| 27 |
<template #item-expiry="{ item }"> |
| 28 |
<div v-if="item.type === 'unblock'" class="mw-block-nodata"> |
| 29 |
— |
| 30 |
</div> |
| 31 |
<span v-else> |
| 32 |
{{ util.formatTimestamp( item.expires, item.duration ) }} |
| 33 |
</span> |
| 34 |
</template> |
| 35 |
<template #item-blockedby="{ item }"> |
| 36 |
<!-- eslint-disable-next-line vue/no-v-html --> |
| 37 |
<span v-html="$i18n( 'userlink-with-contribs', item ).parse()"></span> |
| 38 |
</template> |
| 39 |
<template #item-parameters="{ item }"> |
| 40 |
<div v-if="!item" class="mw-block-nodata mw-block-params-hyphen"> |
| 41 |
— |
| 42 |
</div> |
| 43 |
<ul v-else> |
| 44 |
<li v-for="( parameter, index ) in item" :key="index"> |
| 45 |
{{ util.getBlockFlagMessage( parameter ) }} |
| 46 |
</li> |
| 47 |
</ul> |
| 48 |
</template> |
| 49 |
<template #item-reason="{ item }"> |
| 50 |
<div |
| 51 |
v-if="!item" |
| 52 |
class="mw-block-nodata" |
| 53 |
:aria-label="$i18n( 'block-user-no-reason-given-aria-details' ).text()" |
| 54 |
> |
| 55 |
{{ $i18n( 'block-user-no-reason-given' ).text() }} |
| 56 |
</div> |
| 57 |
<span v-else> |
| 58 |
{{ item }} |
| 59 |
</span> |
| 60 |
</template> |
| 61 |
</cdx-table> |
| 62 |
<div v-if="moreblocks" class="mw-block-fulllog"> |
| 63 |
<a |
| 64 |
:href="mw.util.getUrl( 'Special:Log', { page: targetUser, type: 'block' } )" |
| 65 |
> |
| 66 |
{{ $i18n( 'log-fulllog' ).text() }} |
| 67 |
</a> |
| 68 |
</div> |
| 69 |
</cdx-accordion> |
| 70 |
</template> |
| 71 |
|
| 72 |
<script> |
| 73 |
const util = require( '../util.js' ); |
| 74 |
const { defineComponent } = require( 'vue' ); |
| 75 |
const { CdxAccordion, CdxTable } = require( '@wikimedia/codex' ); |
| 76 |
|
| 77 |
// @vue/component |
| 78 |
module.exports = exports = defineComponent( { |
| 79 |
name: 'TargetBlockLog', |
| 80 |
components: { CdxAccordion, CdxTable }, |
| 81 |
props: { |
| 82 |
targetUser: { |
| 83 |
type: [ Number, String, null ], |
| 84 |
required: true |
| 85 |
} |
| 86 |
}, |
| 87 |
setup() { |
| 88 |
const columns = [ |
| 89 |
{ id: 'timestamp', label: mw.message( 'blocklist-timestamp' ).text(), minWidth: '112px' }, |
| 90 |
{ id: 'type', label: mw.message( 'blocklist-type-header' ).text(), minWidth: '112px' }, |
| 91 |
{ id: 'expiry', label: mw.message( 'blocklist-expiry' ).text(), minWidth: '112px' }, |
| 92 |
{ id: 'blockedby', label: mw.message( 'blocklist-by' ).text(), minWidth: '150px' }, |
| 93 |
{ id: 'parameters', label: mw.message( 'blocklist-params' ).text(), minWidth: '160px' }, |
| 94 |
{ id: 'reason', label: mw.message( 'blocklist-reason' ).text(), minWidth: '160px' } |
| 95 |
]; |
| 96 |
|
| 97 |
return { |
| 98 |
columns, |
| 99 |
util, |
| 100 |
mw |
| 101 |
}; |
| 102 |
}, |
| 103 |
data() { |
| 104 |
return { |
| 105 |
data: [], |
| 106 |
moreblocks: false |
| 107 |
}; |
| 108 |
}, |
| 109 |
methods: { |
| 110 |
getUserBlocks( searchTerm ) { |
| 111 |
const api = new mw.Api(); |
| 112 |
|
| 113 |
const params = { |
| 114 |
action: 'query', |
| 115 |
format: 'json', |
| 116 |
formatversion: 2, |
| 117 |
list: 'logevents', |
| 118 |
lelimit: '10', |
| 119 |
letype: 'block', |
| 120 |
leprop: 'ids|title|type|user|timestamp|comment|details', |
| 121 |
letitle: 'User:' + searchTerm |
| 122 |
}; |
| 123 |
|
| 124 |
return api.get( params ) |
| 125 |
.then( ( response ) => response ); |
| 126 |
} |
| 127 |
}, |
| 128 |
watch: { |
| 129 |
targetUser: { |
| 130 |
handler( newValue ) { |
| 131 |
if ( newValue ) { |
| 132 |
this.data = []; |
| 133 |
// Look up the block(s) for the target user in the log |
| 134 |
this.getUserBlocks( newValue ).then( ( data ) => { |
| 135 |
this.moreblocks = !!data.continue; |
| 136 |
data = data.query; |
| 137 |
// The fallback is only necessary for Jest tests. |
| 138 |
data = data || { logevents: [] }; |
| 139 |
for ( let i = 0; i < data.logevents.length; i++ ) { |
| 140 |
this.data.push( { |
| 141 |
timestamp: { |
| 142 |
timestamp: data.logevents[ i ].timestamp, |
| 143 |
logid: data.logevents[ i ].logid |
| 144 |
}, |
| 145 |
type: data.logevents[ i ].action, |
| 146 |
expiry: { |
| 147 |
expires: data.logevents[ i ].params.expiry, |
| 148 |
duration: data.logevents[ i ].params.duration, |
| 149 |
type: data.logevents[ i ].action |
| 150 |
}, |
| 151 |
blockedby: data.logevents[ i ].user, |
| 152 |
parameters: data.logevents[ i ].params.flags, |
| 153 |
reason: data.logevents[ i ].comment |
| 154 |
} ); |
| 155 |
} |
| 156 |
} ); |
| 157 |
} |
| 158 |
}, |
| 159 |
immediate: true |
| 160 |
} |
| 161 |
} |
| 162 |
} ); |
| 163 |
</script> |
| 164 |
|
| 165 |
<style lang="less"> |
| 166 |
@import 'mediawiki.skin.variables.less'; |
| 167 |
|
| 168 |
.mw-block-previous-blocks { |
| 169 |
word-break: auto-phrase; |
| 170 |
} |
| 171 |
|
| 172 |
.mw-block-params-hyphen { |
| 173 |
padding-left: @spacing-75; |
| 174 |
} |
| 175 |
|
| 176 |
.mw-block-fulllog { |
| 177 |
margin-top: @spacing-50; |
| 178 |
} |
| 179 |
|
| 180 |
.mw-block-nodata { |
| 181 |
color: @color-subtle; |
| 182 |
font-style: italic; |
| 183 |
} |
| 184 |
</style> |