Skip to content

Commit

Permalink
BlockedUserHistory: always show 1000 diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae committed Jul 12, 2024
1 parent 9abdb1e commit bbb4169
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions BlockedUserHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*/

class BlockedUserHistory {
constructor( mw, $ ) {
constructor( mw, $, window ) {
this.mw = mw;
// eslint-disable-next-line no-jquery/variable-pattern
this.$ = $;
this.window = window;
}

async execute() {
Expand All @@ -20,39 +21,60 @@ class BlockedUserHistory {
// TODO: switch to MutationObserver
// check for markblocked HTML classes every second for 20 seconds. when found, execute our user script
let i = 0;
const interval = setInterval( function() {
const markBlockedFinishedLoading = $( 'li[data-mw-revid]' ).has( '.history-user > a.user-blocked-indef, .history-user > a.user-blocked-partial, .history-user > a.user-blocked-temp' );
if ( markBlockedFinishedLoading || i >= 20 ) {
this.doStuff();
const interval = setInterval( () => {
const $markBlockedFinishedLoading = $( 'li[data-mw-revid]' ).has( '.history-user > a.user-blocked-indef, .history-user > a.user-blocked-partial, .history-user > a.user-blocked-temp' );
if ( $markBlockedFinishedLoading || i >= 20 ) {
this.addLinkOrHideBlocked();
clearInterval( interval );
}
i++;
}.bind( this ), 1000);
}, 1000 );
}

doStuff() {
const urlContainsOnlyShowBlocked = this.getUriParameter('onlyShowBlocked') === '1';
addLinkOrHideBlocked() {
const urlContainsOnlyShowBlocked = this.getUriParameter( 'onlyShowBlocked' ) === '1';
if ( urlContainsOnlyShowBlocked ) {
this.hideNotBlocked();
} else {
// Note that the pager links at the bottom of the page will automatically include &onlyShowBlocked=1 once you visit this URL. Good job MediaWiki :)
this.mw.util.addPortletLink( 'p-cactions', window.location.href + '&onlyShowBlocked=1', 'Show only blocked users', 'blocked-user-history' );
// Some people are using a per page default as low as 50. Increase this to 1000 so we can see more blocked revisions on a single page.
const url = this.setUriParameters( this.window.location.href, {
onlyShowBlocked: 1,
limit: 1000
} );
this.mw.util.addPortletLink( 'p-cactions', url, 'Show only blocked users', 'blocked-user-history' );
}
}

/**
* @copyright nickf, CC BY-SA 2.5, https://stackoverflow.com/a/1586333/3480193
*/
getUriParameter( uriParameter ) {
var parts = window.location.search.substr(1).split("&");
var $_GET = {};
for (var i = 0; i < parts.length; i++) {
var temp = parts[i].split("=");
$_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
const parts = this.window.location.search.substr( 1 ).split( '&' );
const $_GET = {};
for ( let i = 0; i < parts.length; i++ ) {
const temp = parts[ i ].split( '=' );
$_GET[ decodeURIComponent( temp[ 0 ] ) ] = decodeURIComponent( temp[ 1 ] );
}
return $_GET[ uriParameter ];
}

/**
* @param {string} url An entire URL, including protocol, domain, anchors, etc. Example: `https://www.test.com/testPage?param1=hello&param2=lol#This_is_my_anchor`
* @param {Object} paramsToChange An associative array, with the key names being the params to change, and the values being the value to change them to. Example: `{ param1: 'newValue', param2: 'anotherNewValue' }`
* @return {string} updatedUrl. Example: `https://www.test.com/testPage?param1=newValue&param2=anotherNewValue#This_is_my_anchor`
*/
setUriParameters( url, paramsToChange ) {
const urlObj = new URL( url );

// Update query parameters based on the paramsToChange object
for ( const key in paramsToChange ) {
urlObj.searchParams.set( key, paramsToChange[ key ] );
}

return urlObj.toString();
}

/**
* @copyright Ponor, CC BY-SA 4.0, https://en.wikipedia.org/w/index.php?title=Wikipedia:User_scripts/Requests&diff=prev&oldid=1231068452
*/
Expand All @@ -73,7 +95,7 @@ class BlockedUserHistory {

$( async () => {
await mw.loader.using( [ 'mediawiki.util' ], async () => {
await ( new BlockedUserHistory( mw, $ ) ).execute();
await ( new BlockedUserHistory( mw, $, window ) ).execute();
} );
} );

Expand Down

0 comments on commit bbb4169

Please sign in to comment.