Year of the Dragon: Through May 28th, claim free Expansion Pack (excluding Vecna Unleashed) or a Greater Elixir of Discovery! Speak to Xatheral in the Hall of Heroes. edit

Thank you for your patience while we continue to upgrade DDOwiki to the latest MediaWiki LTS version. If you find any errors on the site, please visit the Discord chat server and let us know.

Game mechanicsNewbie guideIn developmentDDO StoreSocial Media


ChallengesClassesCollectablesCraftingEnhancementsEpic DestiniesFavorFeats

GlossaryItemsMapsMonstersPlacesQuestsRacesReincarnationSkillsSpells


Please create an account or log in to remove ads, build a reputation, and unlock more editing privileges and then visit DDO wiki's IRC Chat/Discord if you need any help!

MediaWiki:Gadget-WiP.js

From DDO wiki
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes, you can click here or try one of the methods below..

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl+F5 or Ctrl+r ( Command+r on a Mac)
  • Google Chrome: Press Ctrl+ Shift+R ( Command+ Shift+R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl+F5
  • Konqueror: Click Reload or press F5
  • Opera: Clear the cache in Tools ‣ Preferences
// <nowiki>
if ( $.inArray( 'Works In Progress', mw.config.get( 'wgCategories' ) ) !== -1 && $( '.WorkInProgressDone' ).attr( 'id' ) !== undefined ) {
  var wipArticleId = mw.config.get( 'wgArticleId' );
  /* This it the code to get a list of redirects and create a string element from them delimited by pipes *//*
  var templateWipRedirects = 'Work-in-progress';
  var templateWipId = 42820;// [[Template:Work-in-progress]]
  ( new mw.Api ).get( {
    action: 'query',
    prop: 'redirects',
    titles: 'Template:Work-in-progress'
  } ).done( function( rdResult ) {
    if ( rdResult.query.pages[ templateWipId ].redirects !== undefined ) {
      var redirects = [];
      $.each( rdResult.query.pages[ templateWipId ].redirects, function( index, redirect ) {
        if ( redirect.ns === 10 ) {
          redirects[ index ] = redirect.title.replace( 'Template:', '' );
        }
      } );
      if ( templateWipRedirects.length >= 1 ) {
        templateWipRedirects += '|' + redirects.join( '|' );
      }
    }
  } );
  */
  
  function removeTag( wipIndexNumber ) {
    ( new mw.Api ).get( {
      action: 'query',
      prop: 'revisions',
      rvprop: 'content',
      pageids: wipArticleId
    } ).done( function ( rvResult ) {
      var content = rvResult.query.pages[ wipArticleId ].revisions[ 0 ][ '*' ];
      var matchCountIndex = 0;
      var matchCountStart = 0;
      while ( matchCountIndex !== -1 ) {
        var matchText = content.match( /\{\{(?:WiP|Work-in-progress)(?:\|(?:.*?))?\}\}(?:\n*)?/g );
        if ( matchText[ matchCountIndex ] === undefined ) {
          matchCountIndex = -1;
        } else {
          var preTextStart = content.indexOf( matchText[ matchCountIndex ], matchCountStart );
          var matchTextLength = matchText[ matchCountIndex ].length;
          matchCountStart = preTextStart + matchTextLength;
          if ( matchCountIndex === ( wipIndexNumber - 1 ) ) {
            var preText = content.substr( 0, preTextStart );
            var remText = content.substr( preTextStart, matchCountStart );
            remText = remText.match( /\{\{(WiP|Work-in-progress)(?:\|(.*?))?\}\}\n+/ );
            var postText = content.substr( matchCountStart );
            var newText = preText + postText;
            ( new mw.Api ).postWithToken( 'edit', {
              action: 'edit',
              pageid: wipArticleId,
              minor: true,
              text: newText,
              summary: 'Removing [[T:' + remText[ 1 ] + ']] #' + wipIndexNumber + ' from page.'
            } ).done( function ( editResult ) { 
            if ( editResult.edit.result === 'Success' ) {
                console.log( 'success:\n%o', remText );
                if ( remText[ 2 ] !== undefined ) {
                  /* Better to build an object here with all of the parameters used in the template than to test for specific parameters */
                  //if ( /small=/.test( remText[ 2 ] ) === false ) {
                  /* Notify the user's who's name was in the template that it has been removed from the page on their talk page. */console.log( 'Notify: %s', remText[ 2 ] );
                  //}
                }
                /* if Link replace line with big text that say the template has been successfuly removed from the source then fades away */
                /* if Button replace red color with green, icon with green check, and text to say the template has been successfuly removed from the source then fades away */
              } else {
                /* indicate the edit failed */console.log( 'failed' );
              }
            } );
            matchCountIndex = -2;
          }
          matchCountIndex++;
        }
      }
    } );
  }
  
  $( '.WorkInProgressDone' ).each( function( i ) {
    var wipID = $( this ).attr( 'id' );
    var wipIndexNumber = wipID.replace( 'WiP', '' ).replace( /(Link|Button)/gi, '' );
    var wipLinkOrButton = wipID.replace( 'WiP' + wipIndexNumber, '' );
    if ( wipLinkOrButton === 'Link' ) {
      $( 'div#WiP' + wipIndexNumber + 'Link' ).html( '[&thinsp;<a href="#WiP' + wipIndexNumber + '" title="Mark as done" onclick="removeTag( ' + wipIndexNumber + ' )">Mark as done</a>&thinsp;]' ).toggle();
    } else if ( wipLinkOrButton === 'Button' ) {
      $( 'div#WiP' + wipIndexNumber + 'Button' ).html( '<input type="button" value="Mark as done" onclick="removeTag( ' + wipIndexNumber + ' )" />' ).toggle();
    } else {
      alert( 'Invalid WiP template detected.  Please report this page to an administrator.  Thanks.' );
    }
  } );
}
// </nowiki>