MediaWiki:Gadget-SpecialPages.js/WantedFiles.js

// - Easier to read Special:WantedFiles

/* hideFalsePositives */// Function to actually remove the false positives like they never happened. function hideFalsePositives { // 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, ","); // Actually remove the false positives $( 'del' ).parent( 'li' ).remove; // 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 // 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 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'      * }      */      console.error( 'Failed: %s (%o)', uFail.error.info, uFail ); $( '#' + fileID ).html( $( '#' + fileID ).html.replace( /\((.*)?\)/, '(- ' + uFail.error.info + ' -)' ) ); } ).done( function( uResult ) { if ( uResult.upload.result === 'Success' ) { $( '#' + fileID ).remove; } else { console.warn( 'Possible non-success: %o', uResult ); $( '#' + fileID ).html( $( '#' + fileID ).html.replace( /\((.*)?\)/, '(- ' + uResult.error.info + ' -)' ) ); } } ); }

// 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 thisEncodedImage = encodeURI( thisImage );  var thisFilename = thisImage.substr( 0, thisImage.indexOf( '.' ) );  var thisWikiFilename = thisFilename.replace( / /g, '_' );  var thisID = mw.util.wikiUrlencode( thisWikiFilename );  var thisExtension = thisImage.substr( thisImage.indexOf( '.' ) + 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 ); $( this ).after( showLinks ); } );

//