User:DannyS712 test/draftnocat.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. |
![]() | Documentation for this user script can be added at User:DannyS712 test/draftnocat. |
// 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.
// If forking this script, please note my contributions / give me credit
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 && mw.config.get( 'wgAction' ) === 'view' &&
$.inArray( 'All orphaned articles', mw.config.get( 'wgCategories' ) ) >= 0 ) {
function deOrphan( backLinks ){
$( '.loadinganimation' ).html( 'Article deOrphaning in progress...' );
var deOrphanerRequest = {
action: 'query',
titles: mw.config.get( 'wgPageName' ),
prop: 'revisions',
intoken: 'edit',
rvprop: 'content',
indexpageids: 1,
dataType: 'xml',
format: 'xml'
};
$.get( mw.config.get( 'wgScriptPath' ) + '/api.php', deOrphanerRequest, function( deOrphanerResponse ) {
var deOrphanerContent = $( deOrphanerResponse ).find( 'rev' ).text();
var oldMIparameter = false;
if ( deOrphanerContent.search( /\| *Orphan *=[\d\w\s\n]*(.*?\}\})/gi ) != -1 ) { oldMIparameter = true; }
deOrphanerContent = deOrphanerContent
.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
var deOrphanerSubmit = {
action: 'edit',
pageid: mw.config.get( 'wgArticleId' ),
text: deOrphanerContent,
summary: 'Article [[User:DannyS712/deOrphan|deOrphaned]]!',
token: mw.user.tokens.get( 'editToken' )
};
$.when(
$.post( mw.config.get( 'wgScriptPath' ) + '/api.php', deOrphanerSubmit, function( deOrphanerResponse ){ } )
).done( function() {
var deOrphanedText = 'Article deOrphaned! <small>( ';
if( oldMIparameter ){
deOrphanedText += '<b style="font-variant: small-caps;">Load</b> ';
} else {
deOrphanedText += '<a href="#reLoad" onClick="location.reload();" style="font-weight: bold;">reload</a> | ';
}
deOrphanedText += '<a href="//en.wikipedia.org/w/index.php?title=' + encodeURIComponent( mw.config.get( 'wgTitle' ) ) + '&diff=cur&oldid=prev" style="font-weight: bold;">diff</a> )</small>';
$( '.loadinganimation' ).html( deOrphanedText );
} );
} );
}
$( '.ambox-Orphan' ).css( 'display', 'inherit' );
$( '#firstHeading' ).append( ' <span class="loadinganimation" style="font-size: medium !important; color: #000 !important; font-family: sans-serif !important; float: right;"> </span> ' );
var requestBacklinks = {
action: 'query',
list: 'backlinks',
format: 'json',
blfilterredir: 'nonredirects',
bllimit: 500,
blnamespace: 0,
bltitle: mw.config.get( 'wgTitle' )
};
var orphan_cutoff = (window.user_orphan_cutoff || 1);
$.get( mw.config.get( 'wgScriptPath' ) + '/api.php' , requestBacklinks, function( responseBacklinks ) {
var backLinks = responseBacklinks.query.backlinks.length;
switch ( backLinks ){
case 0:
if (orphan_cutoff <= 0) var blStatement = 'This page is an <a href="//en.wikipedia.org/wiki/Wikipedia:Orphan" style="font-weight: bold;">orphan</a> as no <a href="//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/' + encodeURIComponent( mw.config.get( 'wgTitle' ) ) + '&namespace=0&hideredirs=1&hidetrans=1" style="font-weight: bold;">other articles</a> link to it.';
break;
case 1:
if (orphan_cutoff <= 1) var blStatement = 'There is <b>1 link to this page</b> from an <a href="//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/' + encodeURIComponent( mw.config.get( 'wgTitle' ) ) + '&namespace=0&hideredirs=1&hidetrans=1" style="font-weight: bold;">other article</a>. <small>(<a href="#deOrphan" onClick="deOrphan(' + backLinks + ');" style="font-weight: bold;">deOrphan</a>)</small>';
break;
case 2:
if (orphan_cutoff <= 2) var blStatement = 'There are <b>2 links to this page</b> from <a href="//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/' + encodeURIComponent( mw.config.get( 'wgTitle' ) ) + '&namespace=0&hideredirs=1&hidetrans=1" style="font-weight: bold;">other articles</a>. <small>(<a href="#deOrphan" onClick="deOrphan(' + backLinks + ');" style="font-weight: bold;">deOrphan</a>)</small>';
break;
default:
var blStatement = 'This page is not an <a href="//en.wikipedia.org/wiki/Wikipedia:Orphan" style="font-weight: bold;">orphan</a> as it meets the "Rule of Three" by having three or more links from <a href="//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/' + encodeURIComponent( mw.config.get( 'wgTitle' ) ) + '&namespace=0&hideredirs=1&hidetrans=1" style="font-weight: bold;">other articles</a>. <small>(<a href="#deOrphan" onClick="deOrphan(' + backLinks + ');" style="font-weight: bold;">deOrphan</a>)</small>';
// setTimeout( function() { deOrphan( backLinks ); }, 2500 );
break;
}
$( '.loadinganimation' ).html( blStatement );
} );
}