MediaWiki:Gadget-DeOrphaner.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( $( '.loadingAnimation' ).html + ' Article deOrphaning in progress...' ); ( new mw.Api ).get( {     action: 'query',      titles: mw.config.get( 'wgPageName' ),      prop: 'revisions',      rvprop: 'content',      indexpageids: 1,      format: 'json'    } ).done( function( getResponse ) {      var qryResponse = getResponse.query.pages[ getResponse.query.pageids[ 0 ] ];      var deOrphanerContent = qryResponse.revisions[ 0 ][ "*" ];      var oldMIparameter = false;      if ( deOrphanerContent.search( /\| *Orphan *=[\d\w\s\n]*(.*?\}\})/gi ) != -1 ) {        oldMIparameter = true;      }      deOrphanerContent = deOrphanerContent        .replace( /\{\{Orphan(.*?)\}\}[\|\r\n]+/gi, '' )// Parse out  (not) in multiple issues        .replace( /\| *Orphan *=[\d\w\s\n]*(.*?\}\})/gi, '$1' );// Parse out old style multiple issues orphan parameter      ( new mw.Api ).postWithToken( 'edit', { action: 'edit', pageid: mw.config.get( 'wgArticleId' ), text: deOrphanerContent, summary: 'Article deOrphaned!' } ).done( function( editResponse ) { console.log( '%o', editResponse );// Make sure responses are sent to the console until I figure out what errors can occur. var deOrphanedText = $( '.loadingAnimation' ).html + ' Article deOrphaned! ( ';       if ( oldMIparameter ) {         deOrphanedText += 'Load ';        }        else {         deOrphanedText += 'reload | ';        }        deOrphanedText += 'diff ) '; $( '.loadingAnimation' ).html( deOrphanedText ); } );   } );  }  $( '#Mbox-Orphan' ).css( 'display', 'none' ); $( '#Mbox-Orphan' ).prev( 'p' ).css( 'display', 'none' ); $( '#Mbox-Orphan' ).next( 'p' ).css( 'display', 'none' ); $( '#firstHeading' ).append( ' •   • •  ' ); var loadingAnimation = window.setInterval( function { ( $( '.loadingAnimation' ).html == "•   • •  " ? $( '.loadingAnimation' ).html( ' •   • • ' ) : (      $( '.loadingAnimation' ).html == " •   •  • " ?        $( '.loadingAnimation' ).html( '  •   •  •' ) : ( $( '.loadingAnimation' ).html == " •   •  •" ? $( '.loadingAnimation' ).html( ' • •   •  ' ) : $( '.loadingAnimation' ).html( '•   • •  ' ) )   )  ) }, 250);  ( new mw.Api ).get( {    action: 'query',    list: 'backlinks',    format: 'json',    blfilterredir: 'nonredirects',    bllimit: 500,    blnamespace: 0,    bltitle: mw.config.get( 'wgTitle' )  } ).done( 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 a link to this page from an other article. (deOrphan) '; break; case 2: var blStatement = 'There are two 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="http://enwp.org/WP:Orphan" style="font-weight: bold;">orphan</a> as it meets the "Rule of Three" by having three or more links from <a href="https://ddowiki.com/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 ); } ); } // Gadgets