MediaWiki:Common.js: различия между версиями
начиная с MediaWiki 1.29 функции importScript нет; поэтому написал её через mw.loader.load |
м оформление кода, викификатор для новой панели редактирования, реализация importScriptURI |
||
| Строка 1: | Строка 1: | ||
function importScriptURI(uri) { | |||
mw.loader.load(uri); | |||
} | |||
function importScript(scriptName) { | function importScript(scriptName) { | ||
importScriptURI("/w/index.php?title=" + mw.util.wikiUrlencode(scriptName) + "&action=raw&ctype=text/javascript"); | |||
} | } | ||
| Строка 9: | Строка 13: | ||
importScript("MediaWiki:Gadget-markadmins.js"); | importScript("MediaWiki:Gadget-markadmins.js"); | ||
/* Викификатор для новой панели редактирования. */ | |||
if ($.inArray(mw.config.get("wgAction"), ["edit", "submit"]) !== -1) { | |||
mw.loader.load("//ru.wikipedia.org/w/index.php?title=MediaWiki:Gadget-wikificator.js&action=raw&ctype=text/javascript"); | |||
} | |||
function wikificatorCustomizeToolbar() { | |||
$("#wpTextbox1").wikiEditor("addToToolbar", { | |||
"section": "advanced", | |||
"group": "format", | |||
"tools": { | |||
"wikify": { | |||
label: "Абсурдофикатор — оформитель текста", | |||
type: "button", | |||
icon: "//upload.wikimedia.org/wikipedia/commons/0/06/Wikify-toolbutton.png", | |||
action: { | |||
type: "callback", | |||
execute: function (context) { | |||
Wikify(); | |||
} | |||
} | |||
} | |||
} | |||
}); | |||
} | |||
if ($.inArray(mw.config.get("wgAction"), ["edit", "submit"]) !== -1) { | |||
mw.loader.using("user.options", function () { | |||
if (mw.user.options.get("usebetatoolbar")) { | |||
mw.loader.using("ext.wikiEditor.toolbar", function () { | |||
$(document).ready(wikificatorCustomizeToolbar); | |||
}); | |||
} | |||
}); | |||
} | |||
/* Викификатор для старой панели редактирования. */ | |||
function addWikifButton() { | function addWikifButton() { | ||
var toolbar = (document.getElementById( | var toolbar = (document.getElementById("cke_toolbar_source_1") || document.getElementById("toolbar")); // Monobook+Modern | ||
if (!toolbar) return; | if (!toolbar) return; | ||
var i = document.createElement( | var i = document.createElement("img"); | ||
i.src = | i.src = "//upload.wikimedia.org/wikisource/ru/d/d1/Button-wikifikator.png"; | ||
i.alt = i.title = | i.alt = i.title = "Абсурдофикатор — оформитель текста"; | ||
i.onclick = Wikify; | i.onclick = Wikify; | ||
i.style.cursor = | i.style.cursor = "pointer"; | ||
toolbar.appendChild(i); | toolbar.appendChild(i); | ||
} | } | ||
if (wgAction == | if (wgAction == "edit" || wgAction == "submit") { | ||
mw.loader.load("//ru.wikipedia.org/w/index.php?title=MediaWiki:Wikificator.js&action=raw&ctype=text/javascript"); | |||
$(addWikifButton); | |||
} | } | ||
/* Обеспечиваем фокус с {{sysdep}} — Edward. */ | /* Обеспечиваем фокус с {{sysdep}} — Edward. */ | ||
function sysdep_init() { | function sysdep_init() { | ||
var lo = document.getElementById( | var lo = document.getElementById("linux_only"); | ||
var wo = document.getElementById( | var wo = document.getElementById("winds_only"); | ||
if (navigator.userAgent.match("Linux") || navigator.userAgent.match("X11")) { | if (navigator.userAgent.match("Linux") || navigator.userAgent.match("X11")) { | ||
if (lo) lo.style.display = "block"; | if (lo) lo.style.display = "block"; | ||
| Строка 37: | Строка 78: | ||
} | } | ||
/* Обеспечиваем нигилистические фокусы (см., например, статью [[Google]]) */ | /* Обеспечиваем нигилистические фокусы (см., например, статью [[Google]]). */ | ||
$(function() { | $(function () { | ||
var nhl = $('#nihilism')[0]; | var nhl = $('#nihilism')[0]; | ||
if (nhl && !document.location.href.match("diff")) { | if (nhl && !document.location.href.match("diff")) { | ||
| Строка 44: | Строка 85: | ||
$('body')[0].style.backgroundColor = 'white'; | $('body')[0].style.backgroundColor = 'white'; | ||
$('body').html("<div id='nihilism_message'" + (nhl.style.top == "0px" ? " style='top: 0px; left: 0px;'" : "") + ">" + msg + "</div>"); | $('body').html("<div id='nihilism_message'" + (nhl.style.top == "0px" ? " style='top: 0px; left: 0px;'" : "") + ">" + msg + "</div>"); | ||
$(document).dblclick(function() { | $(document).dblclick(function () { | ||
window.location = 'http://absurdopedia.wiki/w/index.php?title=' + encodeURIComponent(wgPageName) + '&action=edit'; | window.location = 'http://absurdopedia.wiki/w/index.php?title=' + encodeURIComponent(wgPageName) + '&action=edit'; | ||
}); | }); | ||
| Строка 50: | Строка 91: | ||
}); | }); | ||
/* Обеспечиваем стирание памяти для «Людёй в чёрном» */ | /* Обеспечиваем стирание памяти для «Людёй в чёрном». */ | ||
$(function() { | $(function () { | ||
if ($( | if ($("#erase_memory")[0]) | ||
setTimeout(function () { $("#erase_memory").hide(); }, 20000); | |||
}); | }); | ||
/* Заставляем работать шаблон {{title}} (удалить этот код, когда заработает {{DISPLAYTITLE}}) */ | /* Заставляем работать шаблон {{title}} (удалить этот код, когда заработает {{DISPLAYTITLE}}). */ | ||
function rewrite_title() { | function rewrite_title() { | ||
if (wgAction == "view") { | if (wgAction == "view") { | ||
p = document.getElementById( | p = document.getElementById("correctTitle"); | ||
if (p) { | if (p) { | ||
document.getElementById( | document.getElementById("firstHeading").innerHTML = p.innerHTML; | ||
document.getElementById( | document.getElementById("wrongTitle").style.display = "none"; | ||
} | } | ||
} | } | ||
} | } | ||
/* | /* Ссылка «править» для нулевой секции. */ | ||
$(function() { | $(function () { | ||
var zeroSectionTip = | var zeroSectionTip = "Править введение"; | ||
if (!mw.config.get( | if (!mw.config.get("wgArticleId")) { | ||
return; | return; | ||
} | } | ||
var action = mw.config.get( | var action = mw.config.get("wgAction"); | ||
if (action != | if (action != "view" && action != "purge") | ||
return; | return; | ||
mw.util.$content.find( | mw.util.$content.find("h2").children(".mw-editsection:first").clone().prependTo("#bodyContent").css("float", "right").find("a").each(function (index) { | ||
$(this).attr( | $(this).attr("title", zeroSectionTip); | ||
if ($(this).attr( | if ($(this).attr("class") === "mw-editsection-visualeditor") { | ||
$(this).attr( | $(this).attr("href", mw.config.get("wgScript") + "?title=" + mw.util.wikiUrlencode(mw.config.get("wgPageName")) + "&veaction=edit&vesection=0&summary=/*%20Преамбула%20*/%20"); | ||
} else { | } else { | ||
$(this).attr( | $(this).attr("href", mw.config.get("wgScript") + "?title=" + mw.util.wikiUrlencode(mw.config.get("wgPageName")) + "&action=edit§ion=0&summary=/*%20Преамбула%20*/%20"); | ||
} | } | ||
}); | }); | ||
}); | }); | ||
/* Вставка юзернейма с помощью <span class="insertusername"></span> */ | /* Вставка юзернейма с помощью <span class="insertusername"></span>. */ | ||
$(function() { | $(function () { | ||
if ((typeof(disableUsernameReplace) == | if ((typeof (disableUsernameReplace) == "undefined" || !disableUsernameReplace) && wgUserName !== null) | ||
$( | $("span.insertusername").html(wgUserName); | ||
}); | }); | ||
function defaultUploadInfo() { | function defaultUploadInfo() { | ||
var rewrite = document.getElementById( | var rewrite = document.getElementById("wpForReUpload"); | ||
if (!rewrite) return; | if (!rewrite) return; | ||
if (rewrite.value == 1) return; | if (rewrite.value == 1) return; | ||
var d = document.getElementById( | var d = document.getElementById("wpUploadDescription"); | ||
if (d) { | if (d) { | ||
if (!d.value.match(/\[\[(Категория|Category):/)) { | if (!d.value.match(/\[\[(Категория|Category):/)) { | ||
| Строка 108: | Строка 149: | ||
} | } | ||
// | // $(onPageInit); | ||
/* Ссылка на случайную статью */ | /* Ссылка на случайную статью. */ | ||
$(function() { | $(function () { | ||
$( | $(".subnav-2a").each(function () { | ||
if ($(this).attr( | if ($(this).attr("data-canonical") == "random") | ||
$(this).attr( | $(this).attr("href", "/wiki/Служебная:RandomInCategory/Абсурдопедия:Случайные статьи"); | ||
}); | }); | ||
}); | }); | ||