MediaWiki:Gadget-RotateLink.js

From wikishia

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.
/**
* Install a rotatelink
* This piece of script is jshint-valid. See [[:commons:MediaWiki:JSValidator.js]].
* Maintainer: [[User:Rillke]]
*/
$( function () {
	'use strict';

	var ext, $fileinfo, i18n,
		title = new mw.Title( mw.config.get( 'wgPageName' ) );

	if (
		!title ||
		// Only logged in users
		mw.user.isAnon() ||
		// Only File pages
		title.getNamespaceId() !== mw.config.get( 'wgNamespaceIds' ).file ||
		// Ignore these extensions
		[ 'ogg', 'oga', 'ogv', 'opus', 'webm', 'mid', 'svg', 'pdf', 'djvu', 'stl' ]
			.indexOf( ext = title.getExtension() && title.getExtension().toLowerCase() ) !== -1 ||
		// User-ignored extensions
		( Array.isArray( title = window.rotateFileTypes ) &&
			title.indexOf( ext ) === -1 ) ||
		// Protected pages
		( ( ext = mw.config.get( 'wgRestrictionEdit' ) ) && ext.length &&
			mw.config.get( 'wgUserGroups' ).indexOf( ext[ 0 ] ) === -1 ) ||
		// Prevent accidental misuse (not on own uploads)
		( mw.config.get( 'wgUserEditCount' ) < 16 &&
			$( '#mw-imagepage-section-filehistory tr:last > td:last' )
				.prev( 'td' ).find( 'a' ).eq( 0 ).text() !== mw.config.get( 'wgUserName' )
		)
	) { return; }

	function loadAndStart( e ) {
		e.preventDefault();
		if ( window.rRot ) {
			$( document ).triggerHandler( 'rotaterequest', [ 'start' ] );
		} else {
			$( document ).on( 'scriptLoaded', function ( evt, d ) {
				if ( d && d === 'rotaterequest' ) {
					$( this ).triggerHandler( d, [ 'start' ] );
				}
			} );
			mw.loader.load( '/w/index.php?title=MediaWiki:RotateRequest.js&action=raw&ctype=text/javascript' );
		}
	}

	if ( ( ext = mw.config.get( 'wgCategories', [] ) ).indexOf( 'Images requiring rotation' ) !== -1 ||
		ext.indexOf( 'Images requiring rotation by bot' ) !== -1 ) {
		$( '#rotateChangeAngle' ).show().on( 'click', 'a', loadAndStart );
		return;
	}

	$fileinfo = $( '#mw-content-text .fileInfo' );
	if ( !$fileinfo.length ) { return; }

	i18n = {
		ar: 'طلب تدوير',
		ca: 'demana girar-la',
		cs: 'vyžádat otočení',
		da: 'Anmod om rotation',
		de: 'Bild drehen',
		el: 'θέλει περιστροφή;',
		en: 'request rotation',
		es: 'solicitar la rotación',
		fa: 'درخواست چرخش',
		fi: 'pyydä kiertoa',
		fr: 'demander la rotation',
		gl: 'solicitar a rotación',
		hr: 'zahtjev za okretanjem slike',
		it: 'richiedi rotazione',
		ja: '画像の回転を依頼',
		mk: 'побарај свртување',
		ml: 'തിരിക്കാൻ നിർദ്ദേശിക്കുക',
		nl: 'Rotatie aanvragen',
		pl: 'Obróć grafikę',
		pt: 'Solicitar rotação',
		ro: 'Cerere de rotaţie',
		ru: 'запросить поворот',
		sl: 'zahteva za zasuk',
		sr: 'захтевање ротације',
		sv: 'Begär rotation',
		uk: 'запит на обертання',
		zh: '请求旋转', // also correct for zh-hans, zh-cn, zh-my, zh-sg
		'zh-hant': '請求旋轉',
		'zh-hk': '請求旋轉',
		'zh-mo': '請求旋轉',
		'zh-tw': '請求旋轉'
	};
	ext = mw.config.get( 'wgUserLanguage' );
	$fileinfo.append(
		'; ',
		$( '<a>' ).attr( {
			href: '#',
			style: 'white-space:nowrap; display:inline-block;',
			title: 'Request a (permanent) correction of the rotation if the thumbnails display in the wrong orientation. Please try to purge the server’s and client’s cache before if this file is an upload before middle of October 2011.'
		} ).on( 'click', loadAndStart ).append(
			'(',
			$( '<img>' ).prop( 'src', '//upload.wikimedia.org/wikipedia/commons/7/70/Silk_arrow_rotate_clockwise.png' ),
			i18n[ ext ] || i18n[ ext.split( '-' )[ 0 ] ] || i18n.en,
			')'
		)
	);
} );