MediaWiki:Cosmos.js

// Have categories added to images from upload description if (mw.config.get("wgCanonicalSpecialPageName") === "Upload") { if (!$.getUrlVar("wpForReUpload")) jQuery(function ($) { "use strict"; var $desc = $("#wpUploadDescription"); if ($desc.val) { return; // If not empty then don't do anything (i.e. error message confirm page) } var params = { action: "parse", page: "Template:Default Upload Summary", format: "json", prop: "wikitext", }; var api = new mw.Api; api.get(params).done(function (data) { return $desc.val(data.parse.wikitext["*"]); }); if (window.location.href.indexOf("wpForReUpload") > -1) { return; } else { function verifyLicense { if (!$("#wpLicense").val) { window.alert("Licensing must be complete."); return false; } } $desc.closest("form").submit(verifyLicense); } }); }

$.urlParam = function (name) { var results = new RegExp("[?&]" + name + "=([^&#]*)").exec( window.location.href ); if (results == null) { return null; } return decodeURI(results[1]) || 0; }; $.extend({ _urlVars: null, getUrlVars: function { if ($._urlVars === null) { var i, j, hash, hashes = window.location.search .slice(window.location.search.indexOf("?") + 1) .split("&"); $._urlVars = {}; for (i = 0, j = hashes.length; i < j; i++) { hash = hashes[i].split("="); $._urlVars[hash[0]] = hash[1]; } } return $._urlVars; }, getUrlVar: function (name) { return $.getUrlVars[name]; }, });