МедияУики:Common.js
Облик
Забележка: За да се видят промените, необходимо е след публикуване на страницата, кешът на браузъра да бъде изтрит.
- Firefox / Safari: Задържа се клавиш Shift и се щраква върху Презареждане (Reload) или чрез клавишната комбинация Ctrl-F5 or Ctrl-R (⌘-R за Mac);
- Google Chrome: клавишна комбинация Ctrl-Shift-R (⌘-Shift-R за Mac)
- Internet Explorer / Edge: Задържа се клавиш Ctrl и се щраква върху Refresh или чрез клавишната комбинация Ctrl-F5;
- Opera: Press Ctrl-F5.
/** Namespace constants */
mw.ns = mw.ns || {
MEDIA : -2,
SPECIAL : -1,
MAIN : 0,
TALK : 1,
USER : 2,
USER_TALK : 3,
PROJECT : 4,
PROJECT_TALK : 5,
IMAGE : 6,
IMAGE_TALK : 7,
MEDIAWIKI : 8,
MEDIAWIKI_TALK : 9,
TEMPLATE : 10,
TEMPLATE_TALK : 11,
HELP : 12,
HELP_TALK : 13,
CATEGORY : 14,
CATEGORY_TALK : 15
};
mw.ext = mw.ext || {};
/**
* Checks whether the current page action is one of the given ones
* @param string|array actions
* @return boolean
*/
mw.ext.isAction = function(actions) {
if (!$.isArray(actions)) {
actions = [actions];
}
return $.inArray(mw.config.get('wgAction'), actions) !== -1;
};
/**
* Checks whether the current page namespace is one of the given ones
* @param string|array namespaces
* @return boolean
*/
mw.ext.isNs = function(namespaces) {
if (!$.isArray(namespaces)) {
namespaces = [namespaces];
}
return $.inArray(mw.config.get('wgNamespaceNumber'), namespaces) !== -1;
};
// for backwards compatibility
var gLang = { msg: mw.msg, addMessages: function(){} };
mw.messages.set({
// Projects
"wikipedia": "Уикипедия",
"wiktionary": "Уикиречник",
"wikiquote": "Уикицитат",
"wikibooks": "Уикикниги",
"wikisource": "Уикиизточник",
"wikinews": "Уикиновини",
"wikiversity": "Уикиверситет",
"wikispecies": "Уикивидове",
"commons": "Общомедия",
// Featured article marker
"fa-linktitle" : "Тази статия на друг език е избрана.",
// Transclusion tool
"ta-emptyfield" : "Не сте въвели име за подстраницата.",
"ta-summary" : "Автоматично вграждане на [[$1]]",
"ta-bpsummary" : "Нова тема: [[$1]]",
// Toolbox add-ons
"tb-subpages": "Подстраници",
"tb-inother": "В други проекти"
});
/* * * * * * * * * * Toolbox add-ons * * * * * * * * * */
/***** subPagesLink ********
* Adds a link to subpages of current page
* (copied from [[commons:MediaWiki:Common.js]] and slightly modified)
*/
var subPagesLink = {
wo_ns : [mw.ns.MEDIA, mw.ns.SPECIAL, mw.ns.IMAGE, mw.ns.CATEGORY],
install: function() {
if ( document.getElementById("p-tb") && !mw.ext.isNs(subPagesLink.wo_ns) ) {
mw.loader.using(['mediawiki.util']).then(function() {
mw.util.addPortletLink( 'p-tb',
mw.util.getUrl('Special:Prefixindex/' + mw.config.get('wgPageName') +'/'),
mw.msg("tb-subpages"), 't-subpages' );
});
}
}
}
$( function() {
subPagesLink.install();
if ( $.inArray("sysop", mw.config.get('wgUserGroups')) !== -1 && mw.config.get('wgCanonicalNamespace').indexOf("User") === 0 ) {
mw.loader.using(['mediawiki.util']).then(function() {
mw.util.addPortletLink( 'p-tb',
mw.util.getUrl('Специални:Потребителски права/' + mw.config.get('wgTitle')),
"Управление на правата", 't-userrights' );
});
}
});
/**
* ProjectLinks
*
* by [[en:wikt:user:Pathoschild]] (idea from an older, uncredited script)
* generates a sidebar list of links to other projects
*
* (copied from [[en:wikt:MediaWiki:Monobook.js]] and modified)
*/
function Projectlinks() {
var ptb = $("#p-tb");
if ( ! ptb.length ) {
return; // no toolbox, no place to go, asta la vista
}
var wrappers = $('.interProject');
if ( wrappers.length == 0 ) {
return;
}
var projects = {
"wiktionary": mw.msg("wiktionary"),
"wikiquote": mw.msg("wikiquote"),
"wikibooks": mw.msg("wikibooks"),
"wikisource": mw.msg("wikisource"),
"wikinews": mw.msg("wikinews"),
"wikispecies": mw.msg("wikispecies"),
"wikiversity": mw.msg("wikiversity"),
"commons.wiki": mw.msg("commons")
};
function getProjectName(url) {
for ( var code in projects ) {
if ( url.indexOf( code ) != -1 ) {
return projects[code];
}
}
return "";
}
// get projectlinks
var elements = [];
wrappers.each(function() {
var link = $(this).find('a:first').clone();
elements.push(link.text(getProjectName(link[0].href)));
});
// sort alphabetically
elements.sort(function(a, b) {
return (a.text() < b.text()) ? -1 : 1;
});
// create list
var pllist = $('<ul>');
$.each(elements, function(i, element) {
$('<li>', { html: element }).appendTo(pllist);
});
// and navbox
var plheader = $('<h3>', {text: mw.msg("tb-inother")});
var plbox = $('<div>', {'class': 'body', html: pllist}).show();
var portlet = $('<div>', {'class': 'portal', id: 'p-sl'}).append(plheader, plbox);
ptb.after(portlet);
}
mw.hook('wikipage.content').add(Projectlinks);