Użytkownik:Polskacafe/rvall.js: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
Polskacafe (dyskusja • edycje) |
Polskacafe (dyskusja • edycje) |
||
Linia 1: | Linia 1: | ||
/** |
|||
* Narzędzie do rewertowania edycji wielu użytkowników |
|||
* Stworzone we wrześniu 2024 |
|||
*/ |
|||
function rvall() { |
function rvall() { |
||
// Ustawiając tą zmienną można ograniczać dostęp do narzędzia. Ofc grupy muszą mieć prawa do rollbacka i patrolu. |
// Ustawiając tą zmienną można ograniczać dostęp do narzędzia. Ofc grupy muszą mieć prawa do rollbacka i patrolu. |
||
Linia 18: | Linia 22: | ||
*/ |
*/ |
||
function makeRevallButton( title, firstRevid, newestRevid ) { |
function makeRevallButton( title, firstRevid, newestRevid ) { |
||
return ' <span class="revall-button mw-rollback-link"><a href="#" class="mw-rollback-link-a" data-title="' + title + |
return ' <span class="revall-button mw-rollback-link"><a href="#" class="mw-rollback-link-a revall-a" data-title="' + title + |
||
'" data-last-revid="' + firstRevid + |
'" data-last-revid="' + firstRevid + |
||
'" data-newest-revid="' + newestRevid + |
'" data-newest-revid="' + newestRevid + |
||
Linia 31: | Linia 35: | ||
*/ |
*/ |
||
function makeRestoreMeButton( title, oneAboveRevid, newestRevid ) { |
function makeRestoreMeButton( title, oneAboveRevid, newestRevid ) { |
||
return ' • <a class="mw-changeslist-restoreme revall-button-restore" href="#" data-title="' + title + |
return ' • <a class="mw-changeslist-restoreme revall-button revall-button-restore revall-a" href="#" data-title="' + title + |
||
'" data-last-revid="' + oneAboveRevid + |
'" data-last-revid="' + oneAboveRevid + |
||
'" data-newest-revid="' + newestRevid + |
'" data-newest-revid="' + newestRevid + |
||
Linia 45: | Linia 49: | ||
$( 'body' ).on( 'DOMNodeInserted', '.mw-rcfilters-ui-changesListWrapperWidget-previousChangesIndicator', function() { |
$( 'body' ).on( 'DOMNodeInserted', '.mw-rcfilters-ui-changesListWrapperWidget-previousChangesIndicator', function() { |
||
$( ".revall-button" ).remove(); |
$( ".revall-button" ).remove(); |
||
$( ".revall-button-restore" ).remove(); |
|||
rcAddLinks(); |
rcAddLinks(); |
||
}); |
}); |
||
Linia 65: | Linia 68: | ||
var firstRevid = $( lastTr ).attr( 'data-mw-revid' ); |
var firstRevid = $( lastTr ).attr( 'data-mw-revid' ); |
||
var newestRevid = $( firstTr ).attr( 'data-mw-revid' ); |
var newestRevid = $( firstTr ).attr( 'data-mw-revid' ); |
||
$( this ).append( makeRevallButton( title, firstRevid, newestRevid )); |
$( this ).append( makeRevallButton( title, firstRevid, newestRevid ) ); |
||
var edits = $( tbody ).children( ".mw-changeslist-edit" ); |
var edits = $( tbody ).children( ".mw-changeslist-edit" ); |
||
edits.each( function( i ) { |
edits.each( function( i ) { |
||
Linia 71: | Linia 74: | ||
var smallRevid = $( edits.get( i-1 )).attr( 'data-mw-revid' ); |
var smallRevid = $( edits.get( i-1 )).attr( 'data-mw-revid' ); |
||
var diffBefore = $( this ).find( "a.mw-changeslist-diff" ); |
var diffBefore = $( this ).find( "a.mw-changeslist-diff" ); |
||
$( diffBefore ).after( makeRestoreMeButton( title, smallRevid, newestRevid )); |
$( diffBefore ).after( makeRestoreMeButton( title, smallRevid, newestRevid ) ); |
||
}); |
}); |
||
$( ".revall-a" ).on( "click", function() { |
|||
$( this ).off( 'click' ); |
$( this ).off( 'click' ); |
||
document.body.style.cursor = "wait"; |
document.body.style.cursor = "wait"; |
||
Linia 80: | Linia 83: | ||
var lastRevid = $( this ).attr( "data-last-revid" ); |
var lastRevid = $( this ).attr( "data-last-revid" ); |
||
var newestRevid = $( this ).attr( "data-newest-revid" ); |
var newestRevid = $( this ).attr( "data-newest-revid" ); |
||
var spinner = $.createSpinner( {size: 'small', type: 'inline'}); |
var spinner = $.createSpinner( {size: 'small', type: 'inline'} ); |
||
$( this ).after( spinner ); |
$( this ).after( spinner ); |
||
$( this ).attr( 'style', 'display: none;' ); |
$( this ).attr( 'style', 'display: none;' ); |
||
rollToVersion( title, lastRevid, newestRevid ); |
rollToVersion( title, lastRevid, newestRevid ); |
||
}; |
}); |
||
$( ".revall-button > .mw-rollback-link-a" ).on( "click", restoreFunc ); |
|||
$( ".revall-button-restore" ).on( "click", restoreFunc ); |
|||
}); |
}); |
||
} |
} |
||
Linia 102: | Linia 102: | ||
'action': 'fmod-patrol', |
'action': 'fmod-patrol', |
||
'maxrevid': revId |
'maxrevid': revId |
||
}).then( function() {window.location.reload();}); |
}).then( function() { window.location.reload(); }); |
||
} |
} |
||
Aktualna wersja na dzień 21:41, 16 wrz 2024
/**
* Narzędzie do rewertowania edycji wielu użytkowników
* Stworzone we wrześniu 2024
*/
function rvall() {
// Ustawiając tą zmienną można ograniczać dostęp do narzędzia. Ofc grupy muszą mieć prawa do rollbacka i patrolu.
const allowedGroups = ["sysop", "content-moderator"];
/**
* Funkcja tworzy "opis" – domyślnie: link – użytkownika, którego zmiana została przywrócona
* @param username Nazwa użytkownika
*/
function makeUserDesc( username ) {
return "[[Specjalna:Wkład/" + username +"|" + username +"]]";
}
/**
* Funkcja zwraca kod przycisku do rewertowania wszystkich edycji zgrupowanych na OZetach
* @param title Nazwa strony
* @param firstRevid pierwszy chronologicznie revid
* @param newestRevid revid najnowszej zmiany
*/
function makeRevallButton( title, firstRevid, newestRevid ) {
return ' <span class="revall-button mw-rollback-link"><a href="#" class="mw-rollback-link-a revall-a" data-title="' + title +
'" data-last-revid="' + firstRevid +
'" data-newest-revid="' + newestRevid +
'">cofnij wszystko</a></span>';
}
/**
* Funkcja zwraca kod przycisku do przywracania konkretnej edycji na OZetach
* @param title Nazwa strony
* @param oneAboveRevid Revid pierwszej edycji wykonanej po edycji przywracanej, czyli ostatniej do zrewertowania
* @param newestRevid Revid najnowszej wersji strony
*/
function makeRestoreMeButton( title, oneAboveRevid, newestRevid ) {
return ' • <a class="mw-changeslist-restoreme revall-button revall-button-restore revall-a" href="#" data-title="' + title +
'" data-last-revid="' + oneAboveRevid +
'" data-newest-revid="' + newestRevid +
'">przywr.</a>';
}
/**
* Automatycznie odświeża przyciski, gdy pojawią się nowe edycje na nowych ( JSowych ) ozetach
*/
function jsRcBind() {
var bodyClass = $( "body" ).attr( "class" );
if ( $( "body" ).attr( "class" ).indexOf( "mw-rcfilters-enabled" ) === -1 ) return;
$( 'body' ).on( 'DOMNodeInserted', '.mw-rcfilters-ui-changesListWrapperWidget-previousChangesIndicator', function() {
$( ".revall-button" ).remove();
rcAddLinks();
});
}
/**
* Dodaje linki do przywracania i wycofywania edycji na OZ
*/
function rcAddLinks() {
$( 'tr.mw-changeslist-last.mw-changeslist-reviewstatus-unpatrolled.mw-changeslist-src-mw-edit > td.mw-changeslist-line-inner' ).each( function() {
var firstSpan = $( this ).children().first();
var href = $( firstSpan ).children().first();
var title = $( href ).attr( 'title' );
var parent = $( this ).parent();
var tbody = $( parent ).parent();
var firstTr = $( tbody ).children( ".mw-changeslist-edit" ).first();
var lastTr = $( tbody ).children().last(); // ostatnie dziekco = pierwsza zmiana chronologicznie
var firstRevid = $( lastTr ).attr( 'data-mw-revid' );
var newestRevid = $( firstTr ).attr( 'data-mw-revid' );
$( this ).append( makeRevallButton( title, firstRevid, newestRevid ) );
var edits = $( tbody ).children( ".mw-changeslist-edit" );
edits.each( function( i ) {
if ( i === 0 ) return;
var smallRevid = $( edits.get( i-1 )).attr( 'data-mw-revid' );
var diffBefore = $( this ).find( "a.mw-changeslist-diff" );
$( diffBefore ).after( makeRestoreMeButton( title, smallRevid, newestRevid ) );
});
$( ".revall-a" ).on( "click", function() {
$( this ).off( 'click' );
document.body.style.cursor = "wait";
var title = $( this ).attr( "data-title" );
var lastRevid = $( this ).attr( "data-last-revid" );
var newestRevid = $( this ).attr( "data-newest-revid" );
var spinner = $.createSpinner( {size: 'small', type: 'inline'} );
$( this ).after( spinner );
$( this ).attr( 'style', 'display: none;' );
rollToVersion( title, lastRevid, newestRevid );
});
});
}
/**
* Patroluje wszystkie wersje danej strony, używając API FancyModeration
* Odświeża stronę po wykonaniu zadania
* @param title Tytuł artykułu
* @param refId Revid ostatniej chronologicznie
*/
function patrolAllChanges( title, revId ) {
var api = new mw.Api();
api.postWithToken( 'patrol', {
'action': 'fmod-patrol',
'maxrevid': revId
}).then( function() { window.location.reload(); });
}
/**
* Przywraca konkretną wersję strony, to jest: wycofuje do ostatniej wersji przed rollBeforeRevID
* @param title Tytuł artykułu
* @param rollBeforeRevID pierwsza chronologicznie "zła" edycja
*/
function rollToVersion( title, rollBeforeRevID, newestRevID ) {
var api = new mw.Api();
api.get( {
'action': 'query',
'formatversion': '2',
'prop': 'revisions',
'titles': title,
'rvprop': 'ids|content|user',
'rvstartid': rollBeforeRevID,
'rvlimit': '2'
}).then( function( result ) {
var revisions = result.query.pages[0].revisions;
if ( !revisions || revisions.length < 2 ) return;
var goodRevision = revisions[1];
api.edit( title, function() {
return {undo: newestRevID,
undoafter: goodRevision.revid,
summary: 'Wycofano edycje wielu użytkowników, przywrócono edycję autorstwa ' + makeUserDesc( goodRevision.user ),
minor: true};
}).then( function() {patrolAllChanges( title, newestRevID );});
});
}
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== "Recentchanges" ) return;
var groups = mw.config.get( "wgUserGroups" );
for ( var i = 0; i < allowedGroups.length; i++ ) {
if ( groups.indexOf( allowedGroups[i] ) !== -1 ) {
rcAddLinks();
jsRcBind();
break;
}
}
}
rvall();