/*
2020-11-28:感谢[[User:AnYiLin|AnYiLin]]的[[:Special:PermanentLink/62968156#提议增设一个“复制差异链接”的小工具|复制差异链接]]小工具
*/
$(function () {
const k = mw.config.get(["wgServerName", "wgPageName", "wgRevisionId", "wgCurRevisionId", "wgDiffNewId"]);
const siteInfoPattern = /^([^.]+)\.([^.]+).*$/;
let serverName, projectCode, languageCode, pageName, versionId, diffId;
serverName = k.wgServerName
.replace(/^([^.]+)\.wikimirror/, "$1.wikimedia") // Toaru mirror site
.replace(".wikimirror", "")
.replace(/\.org$/, "");
project = serverName.match(siteInfoPattern)[2];
language = serverName.match(siteInfoPattern)[1];
pageName = k.wgPageName.replace(/_/g, " ");
versionId = mw.util.getParamValue("oldid") || k.wgRevisionId || k.wgCurRevisionId;
diffId = k.wgDiffNewId;
const homewikiProjectCode = window.permanentlinkDefaultProject || "wikipedia";
const homewikiLanguageCode = window.permanentlinkDefaultLanguage || "zh";
let fixCode = function () {
let proj = "",
lang = "";
const projectCodeList = {
wikipedia: "w",
wiktionary: "wikt",
wikinews: "n",
wikibooks: "b",
wikiquote: "q",
wikisource: "s",
wikiversity: "v",
wikivoyage: "voy",
wikidata: "d",
};
const wikimediaProjectList = {
commons: "c",
meta: "m",
mediawiki: "mw",
test: "testwiki",
};
const specialSiteList = {
wikisource: "oldwikisource",
"beta.wikiversity": "betawikiversity",
};
if (typeof specialSiteList[serverName] != "undefined") {
proj = specialSiteList[serverName] === homewikiProjectCode ? ":" : specialSiteList[serverName];
} else if (project === "wikimedia") {
proj = typeof wikimediaProjectList[language] === "undefined" ? language : wikimediaProjectList[language];
proj = language === homewikiProjectCode ? ":" : proj;
} else {
proj = typeof projectCodeList[project] === "undefined" ? project : projectCodeList[project];
proj = project === homewikiProjectCode ? "" : proj;
lang = language === "www" ? "" : language;
lang = lang === homewikiLanguageCode ? "" : lang;
}
return `:${proj}:${lang}`;
};
let prefixCode = "",
pageLink = "",
peramaentLink = "",
innerOutputText = "";
prefixCode = fixCode();
pageLink = `<span style="user-select: all;">[[${prefixCode}:${pageName}]]</span>`;
if (diffId) {
peramaentLink = `[[${prefixCode}:Special:Diff/${versionId}/${diffId}]]`;
} else {
peramaentLink = `[[${prefixCode}:Special:PermanentLink/${versionId}|${versionId}]]`;
}
innerOutputText = pageLink + (versionId ? ` (<span style="user-select: all;">${peramaentLink}</span>)` : "");
innerOutputText = innerOutputText.replace(/:+/g, ":");
$("#contentSub").before(`<div id="citationMarkup" style="font-size: 84%; line-height: 20px;">${innerOutputText}</div>`);
});