User:Technical 13/Scripts/OrphanStatus.js

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 deOrphaned!', token: mw.user.tokens.get( 'csrfToken' ) };           $.when(                $.post( mw.config.get( 'wgScriptPath' ) + '/api.php', deOrphanerSubmit, function( deOrphanerSesponse ){ } )            ).done( function {                var deOrphanedText = 'Article deOrphaned! ( '; if( oldMIparameter ){ deOrphanedText += 'Load '; } else { deOrphanedText += 'reload | '; }               deOrphanedText += 'diff ) ';                $( '.loadinganimation' ).html( deOrphanedText );            } ); } );   }    $( '.ambox-Orphan' ).css( 'display', 'inherit' );    $( '#firstHeading' ).append( '  •   •  •  ' );    var loadingAnimation = window.setInterval( function { (        $( '.loadinganimation' ).html == "•   •  •  " ?        $( '.loadinganimation' ).html( ' •   •  • ' ) : ( $( '.loadinganimation' ).html == " •   • • " ? $( '.loadinganimation' ).html( ' •   •  •' ) : (                $( '.loadinganimation' ).html == "  •   •  •" ?                $( '.loadinganimation' ).html( ' •  •   •  ') :                $( '.loadinganimation' ).html( '•   •  •  ' )            ) )   ) }, 250);    var requestBacklinks = {        action: 'query',        list: 'backlinks',        format: 'json',        blfilterredir: 'nonredirects',        bllimit: 500,        blnamespace: 0,        bltitle: mw.config.get( 'wgTitle' )    };    $.get( mw.config.get( 'wgScriptPath' ) + '/api.php', requestBacklinks, function( responseBacklinks ) { var backLinks = responseBacklinks.query.backlinks.length; switch ( backLinks ){ case 0: var blStatement = 'This page is an orphan as no other articles link to it.'; break; case 1: var blStatement = 'There is 1 link to this page from an other article. (deOrphan) '; break; case 2: var blStatement = 'There are 2 links to this page from other articles</a>. (<a href="#deOrphan" onClick="deOrphan(' + backLinks + ');" style="font-weight: bold;">deOrphan</a>) '; 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>. (<a href="#deOrphan" onClick="deOrphan(' + backLinks + ');" style="font-weight: bold;">deOrphan</a>) '; //               setTimeout( function { deOrphan( backLinks ); }, 2500 ); break; }       clearInterval( loadingAnimation ); $( '.loadinganimation' ).html( blStatement ); } ); }