MediaWiki:Gadget-SpecialPages.js/WantedFiles.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
//<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: 'http://ddowiki.com/images/' + file
} ).fail( function( uFailCode, uFail ) {
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="http://ddowiki.com/images/' + thisWikiImage + '" title="Direct link to ' + thisImage + '">file</a>';
var uploadLink = '<a href="http://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>'; */// Not yet.
}
line.parent( 'li' ).attr( 'id', title.replace( /\.[\dA-F]{2}/g, '' ) );
line.after( showLinks );
} );
} );
//</nowiki>[[Category:Gadgets]]