User:PKM/common.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
//<nowiki>

//catALot///////////////////////////////////////
////////// Cat-a-lot user preferences //////////
window.catALotPrefs = {"disambig_category":"Disambiguation","redir_category":"Category redirects","watchlist":"preferences","minor":true,"editpages":true,"docleanup":true,"subcatcount":50,"uncat":true,"button":true};
////////////////////////////////////catALotEnd//
//</nowiki>

/* 
 * Purpose: Show as much of the data as we can know in as 'raw' a format possible
 * This can help those who are interested in cleaning up metadata to find cases which are currently subpar
 *
 * Licensed: MIT
 *
 * TODO:
 * - Make it collapsible
 * - Add link to place for editors to collaborate on improving
 * - Add checks for duplicate statements
 * - Add checks for complex HTML
 * - Add checks for Geo location/orientation (camera and object)
 * - Add checks for FoP
 * - Add checks for derivates (using category)
 * - Run checks on the database for templates using the classes that we might not know about
 * - Add checks for type and microformats
 * - Add checks for campaigns and or institute donations
 * - Add check for retouched  + user
 * - Add check for FP/QI/VI
 * - Add checks for catalogue numbers/source ids (NASA image id, NARA etc)
 */
( function ( $, mw ) {
	'use strict';
	var $metadataView,
		warnings = [],
		errors = [];
 
	function reportAPIMetadata( data ) {
		$(function() {
			// add to the info to block
			var table = $('<table>');
			table.addClass( 'toccolours' );
 
			function buildRow( header, value ) {
				return $("<tr>")
					.append( $("<th>").html( header ) )
					.append( $("<td>").html( value ) );
			}
 
			for( var page in data.query.pages ) {
				/*jshint -W083 */
				$.each( data.query.pages[page].imageinfo[0].extmetadata, function( k, v ) {
					table.append( buildRow(k, v.value ) );
				} );
				break; // Just one page
			}
 
			table.appendTo( $metadataView.find( '.metadata-api' ) );
		} );
	}
 
	function getAPIMetadata() {
		var api = new mw.Api();
		api.get( {
				action: 'query',
				titles: mw.config.get( 'wgPageName' ),
				prop: 'imageinfo',
				iiprop: 'timestamp|user|url|size|mime|mediatype|extmetadata',
				iiextmetadatalanguage: mw.config.get( 'wgUserLanguage' ),
				iimetadataversion: 'latest',
				iiextmetadatamultilang: '',
				iiextmetadatafilter: [
					'ObjectName',		// title of a book for instance
					'DateTimeOriginal', // date time from desc page
					'ImageDescription', // from desc page
					'Copyrighted',		// from desc page, false if PD
					'License',			// from template
					'LicenseShortName', // from desc page
					'UsageTerms',		// 'long name of terms' from desc page
					'LicenseUrl',		// link to license deed
					'Credit',			// source? from desc page
					'Artist'			// author/copyright holder from desc page
	//			'DateTime',			// datetime from EXIF file data
	//	    	'GPSLatitude',		// let this stuff be for now.
	//	    	'GPSLongitude',
	//	    	'Categories',
	//	    	'Permission'
					].join('|')
		} ).done ( reportAPIMetadata );
	}
 
 
	function collectPageMetadata() {
		var metadata = {},
			temp;
		metadata.html = {};
		metadata.restrictions = {};
 
		// Check for {{Information}}
		if ( $(".commons-file-information-table").length < 1 ) {
			errors.push( "No {{Information}}-template seems to be present");
		}
 
		// From {{Information}}
		metadata.html.description = $( '#fileinfotpl_desc + td' );
		metadata.description = {};
		temp = metadata.html.description.children( '.description [lang]' );
		if( temp.length > 0 ) {
			temp.each( function( i, e ) {
				metadata.description[ $( e ).attr( 'lang' ) ] = $.trim( $( e ).remove( '.language' ).text() );
			} );
		} else {
			metadata.description['*'] = $.trim( metadata.html.description.text() );
		}
 
		metadata.html.author = $( '#fileinfotpl_aut + td' );
		metadata.author = $.trim( metadata.html.author.text() );
 
		metadata.html.source = $( '#fileinfotpl_src + td' );
		metadata.source = $.trim( metadata.html.source.text() );
 
		// From {{Credit line}}, explicit attribution statement, supersedes what we can manufacture ourselves
		metadata.html.attribution = $( '.fileinfotpl_credit + td' );
		metadata.attribution = $.trim( metadata.html.attribution.text() );
 
		// From {{own}}, usually contained in #fileinfotpl_src
		metadata.ownwork = $( '#own-work, .int-own-work' ).length > 0;
 
		// From {{Creator}} which is usually contained in #fileinfotpl_aut
		metadata.html.creator = $( '#creator' );
		metadata.creator = $.trim( $( '#creator' ).text());
 
		// {{Personality rights}}
		metadata.restrictions.personality_rights = $( '#commons-template-personality-rights' ).length > 0;
		metadata.restrictions.trademarked = $( '.restriction-trademarked' ).length > 0;
 
		metadata.licenses = getLicenses();
		return metadata;
	}
 
	function getLicenses() {
		var licenses, $readable;
 
		licenses = [];
		$readable = $('.licensetpl');
 
		$readable.each(function () {
			var cL = {
				link: $(this).find('.licensetpl_link').html(),
				short: $(this).find('.licensetpl_short').html(),
				long: $(this).find('.licensetpl_long').html(),
				attr: $(this).find('.licensetpl_attr').html(),
				aut: $(this).find('.licensetpl_aut').html(),
				link_req: $(this).find('.licensetpl_link_req').html(),
				attr_req: $(this).find('.licensetpl_attr_req').html()
			};
 
			if (cL.short) {
				licenses.push(cL);
			}
		});
		return licenses;
	}
 
	function reportScrapedData( data ) {
		// add to the view	
	}
 
	function initDataCheck() {
		getAPIMetadata();
		$( function() {
			$metadataView = $( '<div>' );
			$metadataView.addClass( 'metadata-content' );
			$metadataView.append( '<h2>Metadata API</h2>' );
			$metadataView.append( '<div class="metadata-api"></div>' );
			$metadataView.append( '<h2><a href="//commons.wikimedia.org/wiki/Commons:Machine-readable_data">Machine-readable metadata</a></h2>' );
			$metadataView.append( '<div class="metadata-scraped">Scraped Metadata</div>' );
			$( '#mw-imagepage-content').before( $metadataView );
 
			reportScrapedData( collectPageMetadata() );
		} );
	}
 
	if ( mw.config.get( 'wgNamespaceNumber') === 6 ) {
		mw.loader.using( 'mediawiki.api', initDataCheck );
	}
} )( jQuery, mediaWiki );

mw.loader.load("//www.wikidata.org/w/index.php?title=User:Yair rand/WikidataInfo.js&action=raw&ctype=text/javascript"); // Backlink: [[d:User:Yair rand/WikidataInfo.js]]

importScript('User:TheDJ/wdcat.js');

/*Magnus's SDC tool*/
importScript('User:Magnus Manske/sdc_tool.js') ;
//<nowiki>

//vFCProfil/////////////////////////////////////
/////// VISUAL FILE CHANGE CONFIGURATION ///////
///// DO NOT MODIFY BY HAND - FINGERS AWAY! ////
////////////////////////////////////////////////
window.vFC_Profiles = {"CreatorːRené":{"editInputs":{"mdDeleteReason":"","mdEditSummary":"fixed creator template ","mdReplacePermission":false,"mdDeleteHeading":"Files found with [[Special:Search/CreatorːRené Tassin]] ","mdTalkNote":"Yours sincerely,","mdRRegEx1":true,"mdRVar1":true,"mdMatchText1":"/CreatorːRené/g","mdReplaceText1":"Creator:René","mdRRegEx2":false,"mdRVar2":true,"mdMatchText2":"","mdReplaceText2":"","selPreserve":"secure","alsoPreserve":""},"action":"c_replace","objectMembers":{"queryParams":{"target":"CreatorːRené Tassin","sroffset":60},"startInput":{"mode":"Search","modeCat":false,"modeUser":false,"modePage":false,"modeSearch":true,"target":"CreatorːRené Tassin","loadThumbs":true,"loadWikitext":true,"startDate":"","startFile":""}},"proceedAt":{"vals":[30,60],"setVals":["sroffset"]},"time":"2019-09-30T04:28:09.015Z"},"creator:Rene":{"editInputs":{"mdDeleteReason":"","mdEditSummary":"Incorrect colon in Creator template","mdReplacePermission":false,"mdDeleteHeading":"Files found with [[Special:Search/CreatorːRené]] ","mdTalkNote":"Yours sincerely,","mdRRegEx1":true,"mdRVar1":true,"mdMatchText1":"/creatorːRené/g","mdReplaceText1":"Creator:René","mdRRegEx2":false,"mdRVar2":true,"mdMatchText2":"","mdReplaceText2":"","selPreserve":"secure","alsoPreserve":""},"action":"c_replace","objectMembers":{"queryParams":{"target":"CreatorːRené","sroffset":90},"startInput":{"mode":"Search","modeCat":false,"modeUser":false,"modePage":false,"modeSearch":true,"target":"CreatorːRené","loadThumbs":true,"loadWikitext":true,"startDate":"","startFile":""}},"proceedAt":{"vals":[60,90],"setVals":["sroffset"]},"time":"2019-09-30T19:20:35.234Z"}};
//////////////////////////////////vFCProfilEnd//
//</nowiki>

importScript('User:Magnus Manske/sdc_tool.js') ;