MediaWiki:Common.js — различия между версиями

Материал из ЭНЭ
Перейти к: навигация, поиск
м
 
(не показано 12 промежуточных версии 3 участников)
Строка 1: Строка 1:
 +
/* */
 +
//<source lang="javascript">
 
/* <pre> */
 
/* <pre> */
// tooltips and access keys
 
ta = new Object();
 
ta['pt-userpage'] = new Array('.','Моя страница пользователя');
 
ta['pt-anonuserpage'] = new Array('.','Страница пользователя для моего IP');
 
ta['pt-mytalk'] = new Array('n','Моя страница обсуждений');
 
ta['pt-anontalk'] = new Array('n','Страница обсуждений для моего IP');
 
ta['pt-preferences'] = new Array('','Мои настройки');
 
ta['pt-watchlist'] = new Array('l','Список страниц моего наблюдения');
 
ta['pt-mycontris'] = new Array('y','Список страниц, которые я редактировал');
 
ta['pt-login'] = new Array('o','Здесь можно зарегистрироваться в системе, но это необязательно');
 
ta['pt-anonlogin'] = new Array('o','Здесь можно зарегистрироваться в системе, но это необязательно');
 
ta['pt-logout'] = new Array('o','Отказаться от регистрации');
 
ta['ca-talk'] = new Array('t','Обсуждение статьи');
 
ta['ca-edit'] = new Array('e','Эту статью можно изменять. Перед сохранением изменений, пожалуйста, нажмите кнопку предварительного просмотра для визуальной проверки результата');
 
ta['ca-addsection'] = new Array('+','Добавить комментарий к обсуждению');
 
ta['ca-viewsource'] = new Array('e','Эта страница защищена от изменений, но вы можете посмотреть и скопировать её исходный текст');
 
ta['ca-history'] = new Array('h','Журнал изменений страницы');
 
ta['ca-protect'] = new Array('=','Защитить страницу от изменений');
 
ta['ca-delete'] = new Array('d','Удалить эту страницу');
 
ta['ca-undelete'] = new Array('d','Восстановить исправления страницы, сделанные до того, как она была удалена');
 
ta['ca-move'] = new Array('m','Переименовать страницу');
 
ta['ca-watch'] = new Array('w','Добавить эту страницу в ваш список наблюдения');
 
ta['ca-unwatch'] = new Array('w','Удалить эту страницу из вашего списка наблюдения');
 
ta['search'] = new Array('f','Искать это слово');
 
ta['p-logo'] = new Array('','Заглавная страница');
 
ta['n-mainpage'] = new Array('z','Перейти на заглавную страницу');
 
ta['n-portal'] = new Array('','О проекте, о том, что вы можете сделать, где что находится');
 
ta['n-currentevents'] = new Array('','Список текущих событий');
 
ta['n-recentchanges'] = new Array('r','Список последних изменений');
 
ta['n-randompage'] = new Array('x','Посмотреть случайную страницу');
 
ta['n-help'] = new Array('','Справочник по проекту «{{SITENAME}}»');
 
ta['n-sitesupport'] = new Array('','Поддержите проект');
 
ta['t-whatlinkshere'] = new Array('j','Список всех страниц, которые ссылаются на эту страницу');
 
ta['t-recentchangeslinked'] = new Array('k','Последние изменения в страницах, которые ссылаются на эту страницу');
 
ta['feed-rss'] = new Array('','Трансляция в формате RSS для этой страницы');
 
ta['feed-atom'] = new Array('','Трансляция в формате Atom для этой страницы');
 
ta['t-contributions'] = new Array('','Список страниц, которые изменял этот участник');
 
ta['t-emailuser'] = new Array('','Отправить письмо этому участнику');
 
ta['t-upload'] = new Array('u','Загрузить изображения или мультимедиа-файлы');
 
ta['t-specialpages'] = new Array('q','Список служебных страниц');
 
ta['t-print']=new Array('', 'Версия без кнопок, пригодная для распечатки');
 
ta['t-permalink'] = new Array('', 'Ссылка на текущую версию этой статьи');
 
ta['ca-nstab-main'] = new Array('c','Содержание статьи');
 
ta['ca-nstab-user'] = new Array('c','Персональная страница участника');
 
ta['ca-nstab-media'] = new Array('c','Мультимедиа-файл');
 
ta['ca-nstab-special'] = new Array('','Это служебная страница, она недоступна для редактирования');
 
ta['ca-nstab-wp'] = new Array('a','Страница проекта');
 
ta['ca-nstab-image'] = new Array('c','Страница изображения');
 
ta['ca-nstab-mediawiki'] = new Array('c','Страница сообщения MediaWiki');
 
ta['ca-nstab-template'] = new Array('c','Страница шаблона');
 
ta['ca-nstab-help'] = new Array('c','Страница справки');
 
ta['ca-nstab-category'] = new Array('c','Страница категории');
 
 
 
var mpTitle = "Заглавная страница";
 
var mpTitle = "Заглавная страница";
 
var isMainPage = (document.title.substr(0, document.title.lastIndexOf(" — ")) == mpTitle);
 
var isMainPage = (document.title.substr(0, document.title.lastIndexOf(" — ")) == mpTitle);
 
var isDiff = (document.location.search && (document.location.search.indexOf("diff=") != -1 || document.location.search.indexOf("oldid=") != -1));
 
var isDiff = (document.location.search && (document.location.search.indexOf("diff=") != -1 || document.location.search.indexOf("oldid=") != -1));
 +
 +
/** JSconfig (old version, to be replaced soon) ************
 +
* Global configuration options to enable and disable specific
 +
* script features from [[MediaWiki:Common.js]]
 +
* Override these default settings in your [[Special:Mypage/monobook.js]]
 +
* for Example: JSconfig.loadAutoInformationTemplate = false;
 +
*
 +
*  Maintainer: [[User:Dschwen]]
 +
*/
 +
 +
var JSconfig_old =
 +
{
 +
loadAutoInformationTemplate : true,
 +
specialSearchEnhanced : true,
 +
subPagesLink : true,
 +
attributeSelf : true,
 +
userUploadsLink : true
 +
}
 +
 +
 +
/** JSconfig ************
 +
* Global configuration options to enable/disable and configure
 +
* specific script features from [[MediaWiki:Common.js]] and
 +
* [[MediaWiki:Monobook.js]]
 +
* This framework adds config options (saved as cookies) to [[Special:Preferences]]
 +
* For a more permanent change you can override the default settings in your
 +
* [[Special:Mypage/monobook.js]]
 +
* for Example: JSconfig.keys[loadAutoInformationTemplate] = false;
 +
*
 +
*  Maintainer: [[User:Dschwen]]
 +
*/
 +
 +
var JSconfig =
 +
{
 +
prefix : 'jsconfig_',
 +
keys : {},
 +
meta : {},
 +
 +
//
 +
// Register a new configuration item
 +
//  * name          : String, internal name
 +
//  * default_value : String or Boolean (type determines configuration widget)
 +
//  * description  : String, text appearing next to the widget in the preferences
 +
//  * prefpage      : Integer (optional), section in the preferences to insert the widget:
 +
//                    0 : User profile
 +
//                    1 : Skin
 +
//                    2 : Math
 +
//                    3 : Files
 +
//                    4 : Date and time
 +
//                    5 : Editing
 +
//                    6 : Recent changes
 +
//                    7 : Watchlist
 +
//                    8 : Search
 +
//                    9 : Misc
 +
//
 +
// Access keys through JSconfig.keys[name]
 +
//
 +
registerKey : function( name, default_value, description, prefpage )
 +
{
 +
  if( typeof(JSconfig.keys[name]) == 'undefined' )
 +
  JSconfig.keys[name] = default_value;
 +
  else {
 +
 +
  // all cookies are read as strings,
 +
  // convert to the type of the default value
 +
  switch( typeof(default_value) )
 +
  {
 +
    case 'boolean' : JSconfig.keys[name] = ( JSconfig.keys[name] == 'true' ); break;
 +
    case 'number'  : JSconfig.keys[name] = JSconfig.keys[name]/1; break;
 +
  }
 +
 +
  }
 +
 +
  JSconfig.meta[name] = { 'description' : description, 'page' : prefpage || 0, 'default_value' : default_value };
 +
},
 +
 +
readCookies : function()
 +
{
 +
  var cookies = document.cookie.split("; ");
 +
  var p =JSconfig.prefix.length;
 +
  var i;
 +
 +
  for( var key in cookies )
 +
  {
 +
  if( cookies[key].substring(0,p) == JSconfig.prefix )
 +
  {
 +
    i = cookies[key].indexOf('=');
 +
    //alert( cookies[key] + ',' + key + ',' + cookies[key].substring(p,i) );
 +
    JSconfig.keys[cookies[key].substring(p,i)] = cookies[key].substring(i+1);
 +
  }
 +
  }
 +
},
 +
 +
writeCookies : function()
 +
{
 +
  for( var key in JSconfig.keys )
 +
  document.cookie = JSconfig.prefix + key + '=' + JSconfig.keys[key] + '; path=/; expires=Thu, 2 Aug 2009 10:10:10 UTC';
 +
},
 +
 +
evaluateForm : function()
 +
{
 +
  var w_ctrl,wt;
 +
  //alert('about to save JSconfig');
 +
  for( var key in JSconfig.meta ) {
 +
  w_ctrl = document.getElementById( JSconfig.prefix + key )
 +
  if( w_ctrl )
 +
  {
 +
    wt = typeof( JSconfig.meta[key].default_value );
 +
    switch( wt ) {
 +
    case 'boolean' : JSconfig.keys[key] = w_ctrl.checked; break;
 +
    case 'string' : JSconfig.keys[key] = w_ctrl.value; break;
 +
    }
 +
  }
 +
  }
 +
 +
  JSconfig.writeCookies();
 +
  return true;
 +
},
 +
 +
setUpForm : function()
 +
{
 +
  var prefChild = document.getElementById('preferences');
 +
  if( !prefChild ) return;
 +
  prefChild = prefChild.childNodes;
 +
 +
  //
 +
  // make a list of all preferences sections
 +
  //
 +
  var tabs = new Array;
 +
  var len = prefChild.length;
 +
  for( var key = 0; key < len; key++ ) {
 +
  if( prefChild[key].tagName &&
 +
      prefChild[key].tagName.toLowerCase() == 'fieldset' )
 +
    tabs.push(prefChild[key]);
 +
  }
 +
 +
  //
 +
  // Create Widgets for all registered config keys
 +
  //
 +
  var w_div, w_label, w_ctrl, wt;
 +
  for( var key in JSconfig.meta ) {
 +
  w_div = document.createElement( 'DIV' );
 +
 +
  w_label = document.createElement( 'LABEL' );
 +
  w_label.appendChild( document.createTextNode( JSconfig.meta[key].description ) )
 +
  w_label.htmlFor = JSconfig.prefix + key;
 +
 +
  wt = typeof( JSconfig.meta[key].default_value );
 +
 +
  w_ctrl = document.createElement( 'INPUT' );
 +
  w_ctrl.id = JSconfig.prefix + key;
 +
 +
  // before insertion into the DOM tree
 +
  switch( wt ) {
 +
    case 'boolean' : w_ctrl.type = 'checkbox'; break;
 +
    case 'string'  : w_ctrl.type = 'text'; break;
 +
  }
 +
 +
  w_div.appendChild( w_label );
 +
  w_div.appendChild( w_ctrl );
 +
  tabs[JSconfig.meta[key].page].appendChild( w_div );
 +
 
 +
  // after insertion into the DOM tree
 +
  switch( wt ) {
 +
    case 'boolean' : w_ctrl.defaultChecked = w_ctrl.checked = JSconfig.keys[key]; break;
 +
    case 'string' : w_ctrl.defaultValue = w_ctrl.value = JSconfig.keys[key]; break;
 +
  }
 +
 +
  }
 +
  addEvent(document.getElementById('preferences').parentNode, 'submit', JSconfig.evaluateForm );
 +
}
 +
}
 +
 +
JSconfig.readCookies();
 +
addOnloadHook(JSconfig.setUpForm);
  
 
if (isMainPage && !isDiff)  
 
if (isMainPage && !isDiff)  
Строка 66: Строка 190:
 
  if (document.URL.indexOf("action=edit") > 0 || document.URL.indexOf("action=submit") > 0)
 
  if (document.URL.indexOf("action=edit") > 0 || document.URL.indexOf("action=submit") > 0)
 
  {
 
  {
        if (wgCanonicalNamespace != "Special")
+
      if (wgCanonicalNamespace != "Special")
        {
+
      {
                document.write('<script type="text/javascript" src="/index.php?title=MediaWiki:Onlyifediting.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
+
          document.write('<script type="text/javascript" src="/index.php?title=MediaWiki:Onlyifediting.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
        }
+
 
 +
/* importScript('MediaWiki:Onlyifediting.js'); */
 +
      }
 
  }
 
  }
 +
  
 
  function addLoadEvent(func)  
 
  function addLoadEvent(func)  
Строка 78: Строка 205:
 
  else if (window.attachEvent)  
 
  else if (window.attachEvent)  
 
   window.attachEvent("onload", func);
 
   window.attachEvent("onload", func);
 +
}
 +
 +
//Execution
 +
if (wgCanonicalNamespace == 'Special'){
 +
  switch (wgCanonicalSpecialPageName){
 +
  case 'Upload': importScript('MediaWiki:Upload.js'); break
 +
  case 'Search': importScript('MediaWiki:Search.js'); break
 +
  }
 
}
 
}
  
Строка 84: Строка 219:
 
addOnloadHook(function(){
 
addOnloadHook(function(){
 
  if (mwEditButtons.length < 3) return;
 
  if (mwEditButtons.length < 3) return;
  mwEditButtons[0].imageFile = 'http://upload.wikimedia.org/wikipedia/ru/9/9a/Button_boldru.png';
+
  mwEditButtons[0].imageFile = 'http://wiki.laser.ru/images/9/9a/Button_boldru.png';
  mwEditButtons[1].imageFile = 'http://upload.wikimedia.org/wikipedia/ru/8/88/Button_italicru.png';
+
  mwEditButtons[1].imageFile = 'http://wiki.laser.ru/images/8/88/Button_italicru.png';
 
  mwEditButtons[2].imageFile = 'http://wiki.laser.ru/images/0/03/Button_internal_link_ukr.png'
 
  mwEditButtons[2].imageFile = 'http://wiki.laser.ru/images/0/03/Button_internal_link_ukr.png'
 
})
 
})
  
 
/* </pre> */
 
/* </pre> */
 +
//</source>

Текущая версия на 12:54, 11 декабря 2013

/* */
//<source lang="javascript">
/* <pre> */
var mpTitle = "Заглавная страница";
var isMainPage = (document.title.substr(0, document.title.lastIndexOf(" — ")) == mpTitle);
var isDiff = (document.location.search && (document.location.search.indexOf("diff=") != -1 || document.location.search.indexOf("oldid=") != -1));
 
/** JSconfig (old version, to be replaced soon) ************
 * Global configuration options to enable and disable specific
 * script features from [[MediaWiki:Common.js]]
 * Override these default settings in your [[Special:Mypage/monobook.js]]
 * for Example: JSconfig.loadAutoInformationTemplate = false;
 *
 *  Maintainer: [[User:Dschwen]]
 */
 
var JSconfig_old =
{
 loadAutoInformationTemplate : true,
 specialSearchEnhanced : true,
 subPagesLink : true,
 attributeSelf : true,
 userUploadsLink : true
}
 
 
/** JSconfig ************
 * Global configuration options to enable/disable and configure
 * specific script features from [[MediaWiki:Common.js]] and
 * [[MediaWiki:Monobook.js]]
 * This framework adds config options (saved as cookies) to [[Special:Preferences]]
 * For a more permanent change you can override the default settings in your 
 * [[Special:Mypage/monobook.js]]
 * for Example: JSconfig.keys[loadAutoInformationTemplate] = false;
 *
 *  Maintainer: [[User:Dschwen]]
 */
 
var JSconfig =
{
 prefix : 'jsconfig_',
 keys : {},
 meta : {},
 
 //
 // Register a new configuration item
 //  * name          : String, internal name
 //  * default_value : String or Boolean (type determines configuration widget)
 //  * description   : String, text appearing next to the widget in the preferences
 //  * prefpage      : Integer (optional), section in the preferences to insert the widget:
 //                     0 : User profile
 //                     1 : Skin
 //                     2 : Math
 //                     3 : Files
 //                     4 : Date and time
 //                     5 : Editing
 //                     6 : Recent changes
 //                     7 : Watchlist
 //                     8 : Search
 //                     9 : Misc
 //
 // Access keys through JSconfig.keys[name]
 //
 registerKey : function( name, default_value, description, prefpage )
 {
  if( typeof(JSconfig.keys[name]) == 'undefined' ) 
   JSconfig.keys[name] = default_value;
  else {
 
   // all cookies are read as strings, 
   // convert to the type of the default value
   switch( typeof(default_value) )
   {
    case 'boolean' : JSconfig.keys[name] = ( JSconfig.keys[name] == 'true' ); break;
    case 'number'  : JSconfig.keys[name] = JSconfig.keys[name]/1; break;
   }
 
  }
 
  JSconfig.meta[name] = { 'description' : description, 'page' : prefpage || 0, 'default_value' : default_value };
 },
 
 readCookies : function()
 {
  var cookies = document.cookie.split("; ");
  var p =JSconfig.prefix.length;
  var i;
 
  for( var key in cookies )
  {
   if( cookies[key].substring(0,p) == JSconfig.prefix )
   {
    i = cookies[key].indexOf('=');
    //alert( cookies[key] + ',' + key + ',' + cookies[key].substring(p,i) );
    JSconfig.keys[cookies[key].substring(p,i)] = cookies[key].substring(i+1);
   }
  }
 },
 
 writeCookies : function()
 {
  for( var key in JSconfig.keys )
   document.cookie = JSconfig.prefix + key + '=' + JSconfig.keys[key] + '; path=/; expires=Thu, 2 Aug 2009 10:10:10 UTC';
 },
 
 evaluateForm : function()
 {
  var w_ctrl,wt;
  //alert('about to save JSconfig');
  for( var key in JSconfig.meta ) {
   w_ctrl = document.getElementById( JSconfig.prefix + key )
   if( w_ctrl ) 
   {
    wt = typeof( JSconfig.meta[key].default_value );
    switch( wt ) {
     case 'boolean' : JSconfig.keys[key] = w_ctrl.checked; break;
     case 'string' : JSconfig.keys[key] = w_ctrl.value; break;
    }
   }
  }
 
  JSconfig.writeCookies();
  return true;
 },
 
 setUpForm : function()
 { 
  var prefChild = document.getElementById('preferences');
  if( !prefChild ) return;
  prefChild = prefChild.childNodes;
 
  //
  // make a list of all preferences sections
  //
  var tabs = new Array;
  var len = prefChild.length;
  for( var key = 0; key < len; key++ ) {
   if( prefChild[key].tagName &&
       prefChild[key].tagName.toLowerCase() == 'fieldset' ) 
    tabs.push(prefChild[key]);
  }
 
  //
  // Create Widgets for all registered config keys
  //
  var w_div, w_label, w_ctrl, wt;
  for( var key in JSconfig.meta ) {
   w_div = document.createElement( 'DIV' );
 
   w_label = document.createElement( 'LABEL' );
   w_label.appendChild( document.createTextNode( JSconfig.meta[key].description ) )
   w_label.htmlFor = JSconfig.prefix + key;
 
   wt = typeof( JSconfig.meta[key].default_value );
 
   w_ctrl = document.createElement( 'INPUT' );
   w_ctrl.id = JSconfig.prefix + key;
 
   // before insertion into the DOM tree
   switch( wt ) {
    case 'boolean' : w_ctrl.type = 'checkbox'; break;
    case 'string'  : w_ctrl.type = 'text'; break;
   }
 
   w_div.appendChild( w_label );
   w_div.appendChild( w_ctrl );
   tabs[JSconfig.meta[key].page].appendChild( w_div );
 
   // after insertion into the DOM tree
   switch( wt ) {
    case 'boolean' : w_ctrl.defaultChecked = w_ctrl.checked = JSconfig.keys[key]; break;
    case 'string' : w_ctrl.defaultValue = w_ctrl.value = JSconfig.keys[key]; break;
   }
 
  }
  addEvent(document.getElementById('preferences').parentNode, 'submit', JSconfig.evaluateForm );
 }
}
 
JSconfig.readCookies();
addOnloadHook(JSconfig.setUpForm);
 
if (isMainPage && !isDiff) 
{
document.write('<style type="text/css">/*<![CDATA[*/ #siteSub, #contentSub, h1.firstHeading { display: none !important; } /*]]>*/</style>');
}
 
 /* подгрузка файла со скриптами для редактирования  *****************************************
 */
 if (document.URL.indexOf("action=edit") > 0 || document.URL.indexOf("action=submit") > 0)
 {
       if (wgCanonicalNamespace != "Special")
       {
           document.write('<script type="text/javascript" src="/index.php?title=MediaWiki:Onlyifediting.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
 
/* importScript('MediaWiki:Onlyifediting.js'); */
       }
 }
 
 
 function addLoadEvent(func) 
 {
 if (window.addEventListener) 
   window.addEventListener("load", func, false);
 else if (window.attachEvent) 
   window.attachEvent("onload", func);
}
 
//Execution
if (wgCanonicalNamespace == 'Special'){
  switch (wgCanonicalSpecialPageName){
   case 'Upload': importScript('MediaWiki:Upload.js'); break
   case 'Search': importScript('MediaWiki:Search.js'); break
  }
}
 
// русификация кнопок на панели инструментов
if (wgAction == 'edit' || wgAction == 'submit') 
addOnloadHook(function(){
 if (mwEditButtons.length < 3) return;
 mwEditButtons[0].imageFile = 'http://wiki.laser.ru/images/9/9a/Button_boldru.png';
 mwEditButtons[1].imageFile = 'http://wiki.laser.ru/images/8/88/Button_italicru.png';
 mwEditButtons[2].imageFile = 'http://wiki.laser.ru/images/0/03/Button_internal_link_ukr.png'
})
 
/* </pre> */
//</source>