User:Microchip08/common.js

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

//</pre><source lang="javascript">

function initTemplates() {
	if ( wgNamespaceNumber == 6 ) {
		mw.util.addPortletLink( 'p-cactions', 'javascript:listTemplates()', 'Add template', 'ca-addTP', 'Add template to image', '', '' );
	}
}
$( initTemplates );
 
function addTemplate( template ) {
    api( wgPageName.replace( "_", " " ) ).setDefaultSummary( 'adding {{[[Template:' + template + '|' + template + ']]}}' ).getPage().lift( function ( pageText ) {
        return pageText + '\n{{' + template + '}}';
    } ).savePage().exec();
    jsMsg( 'Template added' );
}
function listTemplates() {
    var templates = {
        "trans-commons": "Freely licensed image to be moved to Commons",
        "no-commons": "Freely licensed local copy",
        "missing fair use rationale": "Fair use image missing rationale",
        "Image-source": "Image missing source",
        "fu": "Fair use image",
        "fair use orphan": "Orphaned FU image"
    };
 
    var msg = '<ul>';
    for ( var template in templates ) {
        msg += '<li><a href="javascript:addTemplate(\'' + template + '\');">' + templates[template] + '</a></li>\n';
    }
    jsMsg( msg );
}