MediaWiki talk:Gadget-CropTool.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search


New page parameter + cs[edit]

{{Editprotected}}

CropTool now supports multi-page files (djvu and pdf), so I've added a page parameter. At the same time I also tried to align the code to the coding conventions.

// CropTool code begins, see [[Commons:CropTool]] for details
( function( mw, $ ) {

	if ( mw.config.get( 'wgNamespaceNumber' ) !== 6 ) return;
	if ( mw.config.get( 'wgAction' ) !== 'view' ) return;

	$( function () {

		var currentUri = new mw.Uri(),
			croptoolUri = new mw.Uri( '//tools.wmflabs.org/croptool/' );

		croptoolUri.extend({
			title: mw.config.get( 'wgTitle' ),
			page: currentUri.query.page,
		});

		mw.util.addPortletLink(
			'p-tb',
			croptoolUri.toString(),
			'CropTool',
			't-crop',
			'Crop this image'
		);

	});

})( mediaWiki, jQuery );

Danmichaelo (δ) 21:54, 9 August 2016 (UTC)[reply]

✓ Done Awesome! Thank you! Zhuyifei1999 (talk) 06:03, 10 August 2016 (UTC)[reply]


Add TIFF[edit]

{{Editprotected}}

The tool supports TIFF, so that should be added to the list of supported file formats. – Danmichaelo (δ) 22:45, 17 June 2019 (UTC)[reply]

✓ Done -- User: Perhelion 18:23, 29 July 2019 (UTC)[reply]

Pull request[edit]

{{Editrequest}} I've forked the gadget in my sandbox and cleaned up some code. Please replace the current code with the following code. Masum Reza📞 00:34, 8 October 2019 (UTC)[reply]

// CropTool code begins, see [[Commons:CropTool]] for details
var title = mw.config.get('wgTitle');
if (mw.config.get('wgNamespaceNumber') == 6 && mw.config.get('wgAction') === 'view' && /(PNG|GIF|JPE?G|DJVU|PDF|TIF?F)$/i.test(title)) {
$(function () {
'use strict';
	title = new mw.Uri('//tools.wmflabs.org/croptool/')
		.extend({
			title: title,
			page: new mw.Uri().query.page
		});
	mw.util.addPortletLink(
		'p-tb',
		title.toString(),
		'⌗ CropTool',
		't-crop',
		'Crop this image' );
});
}
Hello Masumrezarock, sure, if you can explain why (regardless of whether the code is better or not). I'm also not sure you know mw:Coding_conventions/JavaScript ("Avoid creating additional global variables", "Use strict equality operators", "Be liberal with comments and don't fear file size because of it. All code is automatically minified by ResourceLoader before being shipped.", "Lines should wrap at no more than 80–100 characters"). Anyway, thanks for suggestions. -- User: Perhelion 09:44, 8 October 2019 (UTC)[reply]
There is no real difference, only it reduces the total size. I didn't know that all codes are minified by the resource loader. Thanks Masum Reza📞 09:50, 8 October 2019 (UTC)[reply]
Ok no hard feelings, you can always get better. But surprise, I will insert your code, because I can say why. It is indeed better to add the "ready" event only if it is needed. The title var is in fact not going global (the RL encapsulate the script already). -- User: Perhelion 10:07, 8 October 2019 (UTC)[reply]
✓ Done Thanks for helping! -- User: Perhelion 10:15, 8 October 2019 (UTC)[reply]

Globalization?[edit]

CropTool does work on multiple wikis. But this gadget was designed to work only on Commons. So if I import this script to another wiki and try to use it, CropTool assumes that the file is on Commons. So if an user wants to use this gadget, they will have to fork it and customize this script to make it work on their wiki. I propose we make the code that will work globally. So that it can work directly on another wiki if we import (using mw.loader.load) it there without any more customization. I am not talking about translation. Masum Reza📞 20:54, 8 October 2019 (UTC)[reply]

@Perhelion: Any thoughts on the matter? Masum Reza📞 20:55, 8 October 2019 (UTC)[reply]
Also this gadget loads on non-existent file pages where it shouldn't. File pages sometimes don't have files (eg. Redirect pages). And every file has a page. So I believe it shouldn't load in non-existent pages (no body can crop a file that doesn't exist anyway). I can work on both of these tasks. Masum Reza📞 21:17, 8 October 2019 (UTC)[reply]
It just needs a mw.config.get('wgArticleId') && mw.config.get('wgArticleId') !== 0 as a if condition. I am adding an edit request template here. Masum Reza📞 01:48, 9 October 2019 (UTC)[reply]

{{Editrequest}}

✓ Done Thank you for the suggestions, it should now work global! -- User: Perhelion 14:02, 9 October 2019 (UTC)[reply]

Bug fix[edit]

{{Editrequest}} This gadget currently doesn't load in non-existent file pages but it does load in file pages that doesn't have files (eg. File redirects). Apparently only files pages that have files have the div tag with file id. So it would be better to replace mw.config.get('wgArticleId') with document.getElementById('file'). I tested it and it seems to be working fine. Sorry for not noticing earlier. Masum Reza📞 05:56, 13 October 2019 (UTC)[reply]

Hey Masumrezarock, I'm not sure this is really needed, because it is absolutely rarely the case and there is no conflict and nevertheless, the link is functional and could be useful. So if we could get a minimal consensus (more than your voice) I would prefer to use wgIsRedirect instead. Regards -- User: Perhelion 07:25, 13 October 2019 (UTC)[reply]
@Perhelion: Do as you wish. Just wanted to make a suggestion. I noticed that this script loaded in a file page with no files. I first noticed it here File:Kharkoo_Lahar_.jpg which is now deleted (the uploader had recreated the file page after it had been deleted by an admin). wgIsRedirect is useful for detecting redirect pages but it doesn't detect if a page in the file namespace does not have a file or not. TinEye and Google images gadget uses the same if condition and that is where I found it. You can try testing it in your userJS. Masum Reza📞 15:29, 13 October 2019 (UTC)[reply]
✓ Done OK it is better, though getElementById is slower. -- User: Perhelion 18:35, 13 October 2019 (UTC)[reply]

URL update[edit]

{{Editrequest}} The tool has been migrated to the new Toolforge domain, so the URL can be updated to https://croptool.toolforge.org/Danmichaelo (δ) 12:49, 4 July 2020 (UTC)[reply]

@Danmichaelo: ✓ Done, thanks! (I accidentally saved without edit summary because I’m used to Alt+Shift+s opening a new dialog for the edit summary, as in the 2017 wikitext editor, instead of saving directly – sorry about that ^^) --Lucas Werkmeister (talk) 09:21, 8 July 2020 (UTC)[reply]