User:DannyS712/deOrphan.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:DannyS712/deOrphan. |
// Install with:
// <code><nowiki> {{subst:Iusc|User:DannyS712/deOrphan.js}} </nowiki></code>
// or with
// <code><nowiki> importScript( 'User:DannyS712/deOrphan.js' ); // Backlink: [[User:DannyS712/deOrphan.js]] </nowiki></code>
//
// Special thanks to User:Technical 13 and his script, [[User:Technical 13/Scripts/OrphanStatus.js]], which I forked
// before later rewriting the script.
// If forking this script, please note my contributions / give me credit
$(function (){
const DeOrphan = {};
DeOrphan.removeTag = function () {
const $progressDisplay = $('.loadinganimation');
$progressDisplay.text( 'Article deOrphaning in progress...' );
new mw.Api().edit(
mw.config.get( 'wgPageName' ),
function ( revision ) {
const newContent = revision.content
.replace( /\{\{Orphan(.*?)\}\}[\|\n]/gi, '' )// Parse out orphan template (not) in multiple issues
.replace( /\| *Orphan *=[\d\w\s\n]*(.*?\}\})/gi, '$1' ); // Parse out old style multiple issues orphan parameter
return {
text: newContent,
summary: 'Article [[User:DannyS712/deOrphan|deOrphaned]]!',
assert: 'user',
minor: true
};
}
).then( function() {
$progressDisplay.empty()
.append(
'Article deOrphaned!',
$( '<small>' ).append(
'(',
$( '<a>' ).text( 'reload' ).on( 'click', () => location.reload() ),
' | ',
$( '<a>' ).text( 'diff' )
.attr( 'href', "//en.wiki.x.io/w/index.php?title=" + encodeURIComponent( mw.config.get( 'wgTitle' ) ) + "&diff=cur&oldid=prev" ),
')'
)
);
} );
};
DeOrphan.render = function () {
mw.util.addCSS(`
.loadinganimation {
font-size: medium !important;
color: #000 !important;
font-family: sans-serif !important;
float: right;
}
.loadinganimation a {
font-weight: bold;
}
`);
$progressDisplay = $( '<span>' ).addClass( 'loadinganimation' );
$( '#firstHeading' ).append( $progressDisplay );
new mw.Api().get( {
action: 'query',
list: 'backlinks',
format: 'json',
blfilterredir: 'nonredirects',
bllimit: 500,
blnamespace: 0,
bltitle: mw.config.get( 'wgTitle' )
} ).done( function ( response ) {
var orphan_cutoff = (window.user_orphan_cutoff || 1);
var backLinks = response.query.backlinks.length;
const $linksHere = $( '<a>' )
.attr( 'href', '//en.wiki.x.io/w/index.php?title=Special:WhatLinksHere/' + encodeURIComponent( mw.config.get( 'wgTitle' ) ) + '&namespace=0&hideredirs=1&hidetrans=1' )
.text( 'other articles' );
const $deOrphan = $( '<small>' ).append(
'(',
$( '<a>' ).text( 'deOrphan' ).on( 'click', () => DeOrphan.removeTag() ),
')'
);
const $orphan = $( '<a>' ).text( 'orphan' ).attr( 'href', '//en.wiki.x.io/wiki/Wikipedia:Orphan' );
switch ( backLinks ){
case 0:
if (orphan_cutoff <= 0) {
$progressDisplay.append(
'This page is an ', $orphan, ' as no ', $linksHere, ' link to it'
);
}
break;
case 1:
if (orphan_cutoff <= 1) {
$progressDisplay.append(
'There is ', $( '<b>' ).text( '1 link to this page' ), ' from an', $linksHere.text( 'other article' ), '. ', $deOrphan
);
}
break;
case 2:
if (orphan_cutoff <= 2) {
$progressDisplay.append(
'There are ', $( '<b>' ).text( '2 links to this page' ), ' from ', $linksHere, '. ', $deOrphan
);
}
break;
default:
$progressDisplay.append(
'This page is not an ', $orphan, ' as it meets the "Rule of Three" by having three or more links from ', $linksHere, '. ', $deOrphan
);
break;
}
} );
};
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 && mw.config.get( 'wgAction' ) === 'view' &&
$.inArray( 'All orphaned articles', mw.config.get( 'wgCategories' ) ) >= 0
) {
$( '.ambox-Orphan' ).css( 'display', 'inherit' );
mw.loader.using(
[ 'mediawiki.util', 'mediawiki.api' ],
DeOrphan.render
);
}
});