User:Inductiveload/basic upload templates.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.
/*
 * Simple script to add some handy links to preload some templates on the
 * Basic upload page's EditTools.
 * There are probably better ways to do this, but if it works....
 */

(function($, mw) {

"use strict";

function load_book_template(is_djvu) {
	
	let type_template = is_djvu ? "DjVu": "PDF";
	let type_cat = (is_djvu ? "DjVu" : "PDF") + " files";
	
    return `== {{int:filedesc}} ==
{{Book
| Author       = {{creator|wikidata=xxx}}
| Editor       = 
| Translator   = 
| Illustrator  = 
| Title        = 
| Subtitle     = 
| Series title = 
| Volume       = 
| Edition      = 
| Publisher    = 
| Printer      = 
| Date         = 
| City         = 
| Language     = {{language|en}}
| Description  = 
| Source       = {{HathiTrust|xxxx|book}}
| Source       = {{IA|}}
| OCLC         =
| Image        = {{PAGENAME}}
| Image page   = 1
| Permission   = 
| Other versions = 
| Wikisource   = s:en:Index:{{PAGENAME}}
| Homecat      = 
| Wikidata     = 
}}
{{${type_template}}}

== {{int:license-header}} ==
{{PD-scan
|PD-old-auto-expired |deathyear=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|PD-US-expired
}}

[[Category:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ${"books"}]]
[[Category:${type_cat} in English]]
`;
}

function add_but(text, cb) {
    let button = $("<button type='button'>").click(function(){
    	$('#wpUploadDescription').val(cb());
    }).append(text);
    $('#specialchars #Standard').append(button);	
}

function but_setup() {
	add_but("{{book}} DjVu", function(){ return load_book_template(true); });
	add_but("{{book}} PDF", function(){ return load_book_template(false); });
}

$(but_setup);

}(jQuery, mediaWiki));