MediaWiki:Gadget-SpecialPages.js/WantedFiles.js

// - 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 struck out ' + ' hide.' + ' 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 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 ReUploader.',    filename: file,    url: 'http://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: 'http://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( /\((.*)?\)/, '(- ' + uFail.error.info + ' -)' ) ); } 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( /\((.*)?\)/, '(- ' + uResult.error.info + ' -)' ) ); } 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( ' hide ' );

// Add direct link to file and reupload link $( 'ol.special' ).find( 'del' ).siblings( 'a' ).each( function ( i ) { var thisImage = $( this ).siblings( 'del' ).text.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 = 'file';  var uploadLink = 'upload'; var showLinks = seperator + downloadLink + seperator + uploadLink; if ( $.inArray( 'sysop', mw.config.get( 'wgUserGroups' ) ) !== -1 ) { if ( $.inArray( thisExtension.toLowerCase, allowedExtensions ) !== -1 ) { showLinks += seperator + 'Fix!'; } else { showLinks += seperator + ' *.' + thisExtension + ' not allowed. ';   }  }  $( this ).parent( 'li' ).attr( 'id', thisID.replace( /\.[\dA-F]{2}/g, '' ) ); $( this ).after( showLinks ); } );

//