User:BZPN/MassRollback2.js: Difference between revisions
From Test Wiki
Content deleted Content added
No edit summary |
No edit summary |
||
| Line 15: | Line 15: | ||
createUI: function() { |
createUI: function() { |
||
const $container = $(` |
const $container = $(` |
||
<div id="mass-rollback-container" |
<div id="mass-rollback-container" class="mw-portlet" style="display:none;"> |
||
<h3 style="margin-top: |
<h3 class="mw-headline" style="margin-top:0;">Mass rollback tool</h3> |
||
| ⚫ | |||
<div id="stats-section" style="margin-bottom: |
<div id="stats-section" class="mw-message-box mw-message-box-notice" style="margin-bottom:1em;"> |
||
<h4>User statistics</h4> |
<h4 class="oo-ui-labelElement-label" style="margin:0 0 .5em 0;">User statistics</h4> |
||
<p> |
<p>Edits: <strong id="total-edits">-</strong></p> |
||
<p>First edit: <span id="first-edit">-</span></p> |
<p>First edit: <span id="first-edit">-</span></p> |
||
<p> |
<p>Recent edit: <span id="last-edit">-</span> <button id="refresh-stats" class="oo-ui-buttonElement-button oo-ui-buttonElement-framed oo-ui-flaggedElement-progressive">Refresh</button></p> |
||
</div> |
</div> |
||
| ⚫ | |||
< |
<div id="filters-section" class="mw-portlet-body" style="margin-bottom:1em;"> |
||
<h4 class="oo-ui-labelElement-label">Filter edits</h4> |
|||
<div |
<div class="mw-input" style="margin-bottom:.5em;"> |
||
< |
<label class="mw-label" style="margin-right:.5em;">Date from:</label> |
||
< |
<input type="date" id="start-date" class="oo-ui-inputWidget-input"> |
||
<label style="margin |
<label class="mw-label" style="margin:0 .5em;">to:</label> |
||
<input type="date" id=" |
<input type="date" id="end-date" class="oo-ui-inputWidget-input"> |
||
<label style="margin: 0 5px;">To:</label> |
|||
<input type="date" id="end-date" style="padding: 4px;"> |
|||
</div> |
</div> |
||
<div style="margin-bottom: |
<div class="mw-input" style="margin-bottom:.5em;"> |
||
<label style="margin-right: |
<label class="mw-label" style="margin-right:.5em;">Namespace:</label> |
||
<select id="namespace-filter" multiple |
<select id="namespace-filter" multiple class="oo-ui-inputWidget-input" style="min-width:150px;"> |
||
<option value="all">All</option> |
<option value="all">All</option> |
||
<option value="0">Main</option> |
<option value="0">Main</option> |
||
| Line 59: | Line 57: | ||
</select> |
</select> |
||
</div> |
</div> |
||
<div style="margin-bottom: |
<div class="mw-input" style="margin-bottom:.5em;"> |
||
<label style="margin-right: |
<label class="mw-label" style="margin-right:.5em;">Edit size:</label> |
||
<select id="size-filter" |
<select id="size-filter" class="oo-ui-inputWidget-input"> |
||
<option value="">Any</option> |
<option value="">Any</option> |
||
<option value="small">Small (< 50 bytes)</option> |
<option value="small">Small (< 50 bytes)</option> |
||
| Line 68: | Line 66: | ||
</select> |
</select> |
||
</div> |
</div> |
||
<div style="margin-bottom: |
<div class="mw-input" style="margin-bottom:.5em;"> |
||
<label style="margin-right: |
<label class="mw-label" style="margin-right:.5em;">Sort order:</label> |
||
<select id="sort-order" |
<select id="sort-order" class="oo-ui-inputWidget-input"> |
||
<option value="desc">Latest first</option> |
<option value="desc">Latest first</option> |
||
<option value="asc">Oldest first</option> |
<option value="asc">Oldest first</option> |
||
</select> |
</select> |
||
</div> |
</div> |
||
<div style="margin-bottom: |
<div class="mw-input" style="margin-bottom:.5em;"> |
||
<button id="clear-filters" |
<button id="clear-filters" class="oo-ui-buttonElement-button oo-ui-buttonElement-framed">Clear filters</button> |
||
<button id="show-filtered" |
<button id="show-filtered" class="oo-ui-buttonElement-button oo-ui-buttonElement-framed oo-ui-flaggedElement-progressive" style="margin-left:.5em;">Show filtered edits</button> |
||
</div> |
</div> |
||
</div> |
</div> |
||
| ⚫ | |||
< |
<div id="reason-section" class="mw-portlet-body" style="margin-bottom:1em;"> |
||
<h4 class="oo-ui-labelElement-label">Rollback reason</h4> |
|||
< |
<select id="rollback-reason" class="oo-ui-inputWidget-input"> |
||
| ⚫ | |||
<select id="rollback-reason" style="padding: 4px;"> |
|||
<option value=""></option> |
<option value=""></option> |
||
<option value="vandalism">Vandalism</option> |
<option value="vandalism">Vandalism</option> |
||
| Line 94: | Line 90: | ||
<option value="other">Other</option> |
<option value="other">Other</option> |
||
</select> |
</select> |
||
<input type="text" id="custom-reason" placeholder="Enter custom reason" style="display:none |
<input type="text" id="custom-reason" placeholder="Enter custom reason" class="oo-ui-inputWidget-input" style="display:none; margin-top:.5em; width:100%;"> |
||
</div> |
</div> |
||
| ⚫ | |||
<div id="actions-section" style="text-align: |
<div id="actions-section" class="mw-portlet-body" style="text-align:center;"> |
||
<button id="rollback-selected" |
<button id="rollback-selected" class="oo-ui-buttonElement-button oo-ui-buttonElement-framed oo-ui-flaggedElement-progressive" style="margin-right:.5em;">Rollback selected</button> |
||
<button id="rollback-all" |
<button id="rollback-all" class="oo-ui-buttonElement-button oo-ui-buttonElement-framed oo-ui-flaggedElement-destructive">Rollback all</button> |
||
</div> |
</div> |
||
</div> |
</div> |
||
| ⚫ | |||
<div id="filtered-edits-container" style="display:none |
<div id="filtered-edits-container" class="mw-portlet" style="display:none;"> |
||
<h4>Filtered edits</h4> |
<h4 class="oo-ui-labelElement-label">Filtered edits</h4> |
||
<div style="margin-bottom: |
<div class="mw-input" style="margin-bottom:.5em;"> |
||
<input type="checkbox" id="select-all"> <label for="select-all">Select |
<input type="checkbox" id="select-all"> <label for="select-all">Select all</label> |
||
</div> |
</div> |
||
<table id="filtered-edits-table" style="width: |
<table id="filtered-edits-table" class="wikitable" style="width:100%;"> |
||
<thead> |
<thead> |
||
<tr |
<tr> |
||
<th |
<th>Revid</th> |
||
<th |
<th>Title</th> |
||
<th |
<th>Timestamp</th> |
||
<th |
<th>Namespace</th> |
||
<th |
<th>Size</th> |
||
<th |
<th>Select</th> |
||
</tr> |
</tr> |
||
</thead> |
</thead> |
||
| Line 123: | Line 119: | ||
</tbody> |
</tbody> |
||
</table> |
</table> |
||
<div style="text-align: |
<div style="text-align:center; margin-top:.5em;"> |
||
<button id="rollback-selected-filtered" |
<button id="rollback-selected-filtered" class="oo-ui-buttonElement-button oo-ui-buttonElement-framed oo-ui-flaggedElement-progressive">Rollback selected filtered edits</button> |
||
</div> |
</div> |
||
</div> |
</div> |
||
`); |
`); |
||
| ⚫ | |||
const $toggleButton = $(` |
const $toggleButton = $(` |
||
<button id="mass-rollback-toggle" |
<button id="mass-rollback-toggle" class="oo-ui-buttonElement-button oo-ui-buttonElement-framed oo-ui-flaggedElement-progressive" style="margin-bottom:.75em;"> |
||
Show/ |
Show/hide MassRollback |
||
</button> |
</button> |
||
`); |
`); |
||
| Line 187: | Line 183: | ||
const userName = mw.config.get('wgRelevantUserName'); |
const userName = mw.config.get('wgRelevantUserName'); |
||
const api = new mw.Api(); |
const api = new mw.Api(); |
||
| ⚫ | |||
// Poprawne pobieranie liczby edycji i pierwszej/ostatniej edycji |
|||
const editCountReq = api.get({ |
|||
action: 'query', |
|||
list: 'users', |
|||
ususers: userName, |
|||
usprop: 'editcount' |
|||
| ⚫ | |||
const firstEditReq = api.get({ |
|||
action: 'query', |
action: 'query', |
||
list: 'usercontribs', |
list: 'usercontribs', |
||
ucuser: userName, |
ucuser: userName, |
||
uclimit: |
uclimit: 1, |
||
ucdir: 'newer', |
|||
ucprop: 'timestamp' |
ucprop: 'timestamp' |
||
}) |
}); |
||
const lastEditReq = api.get({ |
|||
action: 'query', |
|||
list: 'usercontribs', |
|||
ucuser: userName, |
|||
const timestamps = contributions.map(c => new Date(c.timestamp)).sort((a, b) => a - b); |
|||
uclimit: 1, |
|||
| ⚫ | |||
ucdir: 'older', |
|||
| ⚫ | |||
ucprop: 'timestamp' |
|||
| ⚫ | |||
$.when(editCountReq, firstEditReq, lastEditReq).done(function(editCountData, firstData, lastData) { |
|||
| ⚫ | |||
const editcount = editCountData[0].query.users[0].editcount; |
|||
$('#total-edits').text(editcount != null ? editcount : '-'); |
|||
} catch (e) { |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
const firstList = firstData[0].query.usercontribs || []; |
|||
$('#first-edit').text(firstList.length ? new Date(firstList[0].timestamp).toLocaleDateString() : '-'); |
|||
} catch (e) { |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
const lastList = lastData[0].query.usercontribs || []; |
|||
| ⚫ | |||
} catch (e) { |
|||
$('#last-edit').text('-'); |
|||
} |
} |
||
| ⚫ | |||
$('#total-edits').text('-'); |
|||
$('#first-edit').text('-'); |
|||
$('#last-edit').text('-'); |
|||
}); |
}); |
||
}, |
}, |
||
| Line 462: | Line 492: | ||
}; |
}; |
||
mw.loader.using([ |
|||
| ⚫ | |||
'oojs-ui-core', |
|||
'oojs-ui-widgets', |
|||
'oojs-ui-core.styles', |
|||
'oojs-ui.styles.icons-interactions', |
|||
'mediawiki.api', |
|||
'mediawiki.util', |
|||
'mediawiki.notify' |
|||
]).then(function () { |
|||
$(function () { |
|||
MassRollback.init(); |
|||
}); |
|||
}); |
}); |
||
})(jQuery, mediaWiki); |
})(jQuery, mediaWiki); |
||