Year of the Dragon: Through April 23rd, claim the adventure pack Slice of Life for free! Speak to Xatheral in the Hall of Heroes.

Game mechanicsNewbie guideIn developmentDDO StoreSocial Media


ChallengesClassesCollectablesCraftingEnhancementsEpic DestiniesFavorFeats

GlossaryItemsMapsMonstersPlacesQuestsRacesReincarnationSkillsSpells


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

MediaWiki:Gadget-SpecialPages.js/WantedFiles.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> - Easier to read [[Special:WantedFiles]]

// Count how many items are on the list to start (to replace the number with a new correct number when done)
var strStartCountString = $( 'ol.special li' ).length.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

/* updateCounters */// Function to update the counters for how many lines/rows are left on the page
function updateCounters() {
  // Count how many items are on the list at the end (to replace the starting number with)
  var strEndCountString = $( 'ol.special li' ).length.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  // Replace the starting number with the new count (should be two of them)
  $( 'strong' ).each( function() {
    $( this ).html( $( this ).html().replace( strStartCountString, strEndCountString ) );
  } );// End replacing the li count
  strStartCountString = strEndCountString;// Update the "start" number.
}

/* hideFalsePositives */// Function to actually remove the false positives like they never happened.
function hideFalsePositives() {
  // Actually remove the false positives
  $( 'del' ).parent( 'li' ).remove();
  updateCounters();
  // Get rid of the extra text and link when done.
  $( 'del' ).parent( 'p' ).html(
    $( 'del' ).parent( 'p' ).html()
    .replace( 'Files from foreign repositories may be listed despite existing.' + 
      ' Any such false positives will be <del>struck out</del>' +
      ' <sup><a href="#" onclick="hideFalsePositives();">hide</a></sup>.' +
      ' Additionally, pages that embed files that do not exist are ',
      'Pages that embed files that do not exist are also '
     )
  );// End replace block text
}// End function

function redirect( titleFrom, titleTo ) {
  /* Code works, but doesn't do the task I want it to... My bad...
  var fileID = titleFrom.replace( /\.[\dA-F]{2}/g, '' );
  var writeRedirect = '#REDIRECT [[' + titleTo + ']] {{Redirected file}}';
  var editSummary = 'Fixing [[Special:WantedFiles]] false positives with [[MediaWiki:Gadget-SpecialPages.js/WantedFiles.js|ReUploader]].';
  ( new mw.Api() ).postWithToken( 'edit', {
    action: 'edit',
    title: titleFrom,
    minor: true,
    recreate: true,
    text: writeRedirect,
    summary: editSummary
  } ).done( function ( fixed ) { 
    if ( fixed.edit.result === 'Success' ) {
      $( '#' + fileID ).remove();
      updateCounters();
    } else {
      if ( $( '#' + fileID ) !== undefined ) {
        $( '#' + fileID ).html( $( '#' + fileID ).html().replace( /\((.*)?\)/, '(- <span class="error">' + uResult.error.info + '</span> -)' ) );
      } else {
        console.error( 'Unable to find #%s', fileID );
      }
      console.warn( 'Possible non-success: %o', uResult );
    }
  } );
  */
  alert( 'Not yet!' );
}

function addImageEntryToDatabase( escapedFilename, extension ) {
  var filename = decodeURI( escapedFilename );
  var fileID = filename.replace( /\.[\dA-F]{2}/g, '' );
  var file = filename + '.' + extension;
  ( new mw.Api() ).postWithToken( 'edit', {
    action: 'upload',
    ignorewarnings: true,
    comment: 'Fixing [[Special:WantedFiles]] false positives with [[MediaWiki:Gadget-SpecialPages.js/WantedFiles.js|ReUploader]].',
    filename: file,
    url: 'https://ddowiki.com/images/' + file
  } ).fail( function( uFailCode, uFail ) {
/* example errors
* error{
*   code: 'filetype-banned',
*   info: 'Filetype not permitted: bmp',
*   filetype: 'bmp',
*   allowed[
*    'png',
*    'jpg',
*    'gif'
*   ]
* }
*
* error{
*   code: 'verification-error',
*   details[
*    'filetype-badmime',
*    'text/html'
*   ],
*   info: 'This file did not pass file verification'
* }
*
* error{
*   code: 'permissiondenied',
*   info: 'Permission denied'
* }
*
* error{
*   0: 'https://ddowiki.com/images/Perigrine.jpg',
*   code: 'http-timed-out',
*   info: 'Error fetching file from remote source'
* }
*
* error{
*   0[ 'backend-fail-alreadyexists', 'mwstore://local-backend/local-public/archive/20160314015536!Divine_Cleansing.jpg' ],
*   code: 'internal-error',
*   info: 'An internal error occurred'
* }
*/
      if ( $( '#' + fileID ) !== undefined ) {
        $( '#' + fileID ).html( $( '#' + fileID ).html().replace( /\((.*)?\)/, '(- <span class="error">' + uFail.error.info + '</span> -)' ) );
      } else {
        console.error( 'Unable to find #%s', fileID );
      }
      console.error( 'Failed: %s (%o)', uFail.error.info, uFail );
  } ).done( function( uResult ) {
    if ( uResult.upload.result === 'Success' ) {
      $( '#' + fileID ).remove();
      updateCounters();
    } else {
      if ( $( '#' + fileID ) !== undefined ) {
        $( '#' + fileID ).html( $( '#' + fileID ).html().replace( /\((.*)?\)/, '(- <span class="error">' + uResult.error.info + '</span> -)' ) );
      } else {
        console.error( 'Unable to find #%s', fileID );
      }
      console.warn( 'Possible non-success: %o', uResult );
    }
  } );
}

// Make sure that there are always 5,000 results (max results)
if ( mw.util.getParamValue( 'limit' ) === null ) {
  location.href = location.href.replace( location.hash, '' ) + ( location.search ? '&' : '?' ) + 'limit=5000'
}

// Find the -struck out- text and add a remove link after it so false positives are only removed on request.
$( $( 'del' ).get( 0 ) ).after( ' <sup><a href="#" onClick="hideFalsePositives();">hide</a></s>' );

// Add direct link to file and reupload link
$( 'ol.special' ).find( 'del' ).siblings( 'a' ).each( function ( i ) {
  var line = $( this );
  var title = line.siblings( 'del' ).text();
  var thisImage = title.replace( 'File:', '' );
  var thisWikiImage = encodeURI( thisImage.replace( / /g, '_' ) );
  var thisFilename = thisImage.substr( 0, thisImage.lastIndexOf( '.' ) );
  var thisWikiFilename = thisFilename.replace( / /g, '_' );
  var thisID = mw.util.wikiUrlencode( thisWikiFilename ).replace( '%', '.' );
  var thisExtension = thisImage.substr( thisImage.lastIndexOf( '.' ) + 1 );
  var allowedExtensions = [ 'png', 'jpg', 'gif' ];
  var seperator = ' - ';
  var downloadLink = '<a href="https://ddowiki.com/images/' + thisWikiImage + '" title="Direct link to ' + thisImage + '">file</a>';
  var uploadLink = '<a href="https://ddowiki.com/page/Special:Upload?wpIgnoreWarning=1&wpForReUpload=1&wpUploadDescription=' + encodeURI( 'Fixing [[Special:WantedFiles]] false positives with [[MediaWiki:Gadget-SpecialPages.js/WantedFiles.js|ReUploader]].' ) + '&wpDestFile=' + thisWikiImage + '" title="Reupload ' + thisImage + '">upload</a>';
  var showLinks = seperator + downloadLink + seperator + uploadLink;
  ( new mw.Api() ).get( {
    action: 'query',
    redirects: 1,
    titles: title
  } ).done( function( rdResult ) {
    if( rdResult.query.redirects === undefined ) {
      /* reupURL */// Not a redirect, reupload this from the URL
      if ( $.inArray( 'sysop', mw.config.get( 'wgUserGroups' ) ) !== -1 ) {
        if ( $.inArray( thisExtension.toLowerCase(), allowedExtensions ) !== -1 ) {
          showLinks += seperator + '<a href="#' + thisWikiFilename + '.' + thisExtension + '" onclick="addImageEntryToDatabase( \'' + thisID + '\', \'' + thisExtension + '\' );" title="Fix false positive for ' + thisImage + ' by adding an entry for file to the database.">Fix!</a>';
        } else {
          showLinks += seperator + '<span class="error">*.' + thisExtension + ' not allowed.</span>';
        }
      }
    } else {
      /* fixRedirect */// Update all links to redirect to use direct link
      showLinks += seperator + '<a href="#' + thisWikiFilename + '.' + thisExtension + '" onclick="redirect( \'' + rdResult.query.redirects[ 0 ].from + '\', \'' + rdResult.query.redirects[ 0 ].to + '\' );" title="Fix false positive for ' + thisImage + ' by using target of this redirect instead.">Fix!</a>';
    }
    line.parent( 'li' ).attr( 'id', title.replace( /\.[\dA-F]{2}/g, '' ) );
    line.after( showLinks );
  } );
} );

//</nowiki>