MediaWiki:Common.js: различия между версиями
Содержимое удалено Содержимое добавлено
обновление данных |
По итогам обсуждения: https://ru.wikinews.org/?diff=618922 |
||
Строка 464: | Строка 464: | ||
if ( mw.config.get( 'wgPageName' ) != 'Заглавная_страница' ) { |
if ( mw.config.get( 'wgPageName' ) != 'Заглавная_страница' ) { |
||
importScript( 'Mediawiki:Comments.js' ); |
importScript( 'Mediawiki:Comments.js' ); |
||
} |
|||
/* Социальные закладки */ |
|||
// написано участником Ry0ukai для Википедии |
|||
// изменено участником Treati |
|||
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) { |
|||
$( document ).ready( function() { |
|||
var content = $( '#bodyContent > p:first' ).text(); |
|||
$( 'head' ) |
|||
.append( |
|||
$( '<meta>' ) |
|||
.attr( { |
|||
property: 'og:description', |
|||
content: content |
|||
} ) |
|||
); |
|||
$( '#p-views ul' ).append( |
|||
$( '<li><div id="p-socb-noim-above" class="vectorMenu" style="height:40px; background-image: none;">' + |
|||
'<span><a href="#" style="display: block; padding: 1.25em 0.5em 0; font-size: 0.8em;" onclick="return false;">Отправить</a></span><div class="menu"><ul style="border: solid 1px silver; border-top: 0px; height:auto; background-image:none;"></ul></div></li>' ) |
|||
) |
|||
.find( '#p-socb-noim-above ul' ) |
|||
.append( |
|||
$( '<li id="t-vkontakte">' ) |
|||
.append( |
|||
$( '<a>' ) |
|||
.attr( 'href', 'http://vkontakte.ru/share.php?url=' + encodeURIComponent( document.URL ) + '&title=' + encodeURIComponent( document.title ) + '&description=' + encodeURIComponent( content ) ) |
|||
.text( 'В Контакте' ) |
|||
), |
|||
$( '<li id="t-facebook">' ) |
|||
.append( |
|||
$( '<a>' ) |
|||
.attr( 'href', 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent( document.URL ) + '&t=' + encodeURIComponent( document.title ) ) |
|||
.text( 'Facebook' ) |
|||
), |
|||
$( '<li id="t-twitter">' ) |
|||
.append( |
|||
$( '<a>' ) |
|||
.attr( 'href', 'http://twitter.com/home/?status=Из%20Викиновостей:%20' + encodeURIComponent( document.URL ) ) |
|||
.text( 'Twitter' ) |
|||
), |
|||
$( '<li id="t-livejournal">' ) |
|||
.append( |
|||
$( '<a>' ) |
|||
.attr( 'href', 'http://www.livejournal.com/update.bml?subject=' + encodeURIComponent( document.title ) + '&event=%3Cdiv+style%3D%22float%3Aleft%3B+border%3A+1px+solid+gray%3B+font-family%3AHelvetica%3B+font-size%3A+10pt%3B+background%3A+%23f7f7f7%3B%22%3E%3Ca+href%3D%22http%3A%2F%2Fru.wikinews.org%22%3E%3Cimg+src%3D%22http%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2F2%2F24%2FWikinews-logo.svg%2F50px-Wikinews-logo.svg.png%22+style%3D%22float%3Aleft%3B+padding%3A+10px%3B%22%3E%3C%2Fa%3E%3Cdiv+style%3D%22float%3Aleft%3B+padding%3A7px%3B+margin-right%3A+11px%3B%22%3E%D0%98%D0%B7+%3Ca+href%3D%22http%3A%2F%2Fru.wikinews.org%22%3E%D0%92%D0%B8%D0%BA%D0%B8%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B5%D0%B9%3C%2Fa%3E%3A%3Cbr+%2F%3E%3Cstrong%3E%3Ca+href%3D%22' + encodeURIComponent( document.URL ) + '%22%3E' + encodeURIComponent( document.title ) + '%3C%2Fa%3E%3C%2Fstrong%3E%3C%2Fdiv%3E%3C%2Fdiv%3E%3Cbr+clear%3D%22both%22+%2F%3E' ) |
|||
.text( 'LiveJournal' ) |
|||
), |
|||
$( '<li id="t-mailru">' ) |
|||
.append( |
|||
$( '<a>' ) |
|||
.attr( 'href', 'http://connect.mail.ru/share?url=' + encodeURIComponent( document.URL ) + '&title=' + encodeURIComponent( document.title ) + '&description=' + encodeURIComponent( content ) ) |
|||
.text( 'Мой мир@Mail.Ru' ) |
|||
) |
|||
); |
|||
$( '#p-socb-noim-above li' ).css( {"display":"block", "height":"auto", "float":"none", "background-image":"none", "background-color":"#FFFFFF"} ); |
|||
$( '#p-socb-noim-above li a' ).css( {"height":"auto", "background-image":"none"} ); |
|||
$( '#p-views' ).css( {"background-repeat":"repeat"} ); |
|||
} ); |
|||
} |
} |
Версия от 10:18, 9 июля 2018
importScript_ = importScript;
importScript = function ( page, proj ) {
if (!proj) {
importScript_(page);
} else {
if ( proj.indexOf( '.' ) === -1 ) {
proj += '.wikinews.org';
}
mw.loader.load( '//' + proj + '/w/index.php?title=' + encodeURIComponent( page.replace( / /g, '_' ) ) + '&action=raw&ctype=text/javascript' );
}
};
importMW = function (name) {
importScript( 'MediaWiki:' + name + '.js' );
};
var auto_comment = 0;
// дополнительные кнопки редактирования, Викификатор
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) {
importScript_( 'MediaWiki:Editpage.js' );
}
// cross-project slidebar from ru.wp
importScript( 'MediaWiki:Sidebar-related.js', 'ru.wikipedia.org' );
// сворачиваемые таблицы и блоки, [[w:ВП:СБ]]
var autoCollapse = 2;
var collapseCaption = 'скрыть';
var expandCaption = 'показать';
var hasClass = ( function (){
var reCache = {};
return function ( element, className ) {
return ( reCache[className] ? reCache[className] : ( reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test( element.className );
};
} )();
function collapsibleTables() {
var Table, HRow, THs, Header, btn, a, tblIdx = 0, colTables = [];
var allTables = document.getElementsByTagName( 'table' );
for ( var i = 0; Table = allTables[i]; i++ ) {
if ( !hasClass( Table, 'collapsible' ) ) {
continue;
}
if ( !( HRow = Table.rows[0] ) ) {
continue;
}
THs = HRow.getElementsByTagName( 'th' );
if ( THs.length == 0 ) {
continue;
}
Header = THs[THs.length-1]; //last TH, not 1st like in en.wp
Table.id = 'collapsibleTable' + tblIdx;
btn = document.createElement( 'span' );
btn.style.styleFloat = btn.style.cssFloat = 'right';
btn.style.fontWeight = 'normal';
a = document.createElement( 'a' );
a.id = 'collapseButton' + tblIdx;
a.href = 'javascript:collapseTable( ' + tblIdx + ' );';
a.appendChild( document.createTextNode( collapseCaption ) );
btn.appendChild( document.createTextNode( '[' ) );
btn.appendChild( a );
btn.appendChild( document.createTextNode( ']' ) );
Header.insertBefore( btn, Header.childNodes[0] );
colTables[tblIdx++] = Table;
}
for ( var i = 0; i < tblIdx; i++ ) {
if ( ( tblIdx > autoCollapse && hasClass( colTables[i], 'autocollapse' ) ) || hasClass( colTables[i], 'collapsed' ) ) {
collapseTable( i );
}
}
}
function collapseTable ( idx ) {
var Table = document.getElementById( 'collapsibleTable' + idx );
var btn = document.getElementById( 'collapseButton' + idx );
if ( !Table || !btn ) {
return false;
}
var Rows = Table.rows;
var isShown = ( btn.firstChild.data == collapseCaption );
btn.firstChild.data = isShown ? expandCaption : collapseCaption;
var disp = isShown ? 'none' : Rows[0].style.display;
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = disp;
}
}
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
var NavigationBarShowDefault = autoCollapse;
function collapsibleDivs(){
var navIdx = 0, colNavs = [], i, NavFrame;
var divs = document.getElementById( 'content' ).getElementsByTagName( 'div' );
for ( i = 0; NavFrame = divs[i]; i++ ) {
if (!hasClass( NavFrame, 'NavFrame' ) ) {
continue;
}
NavFrame.id = 'NavFrame' + navIdx;
var a = document.createElement( 'a' );
a.className = 'NavToggle';
a.id = 'NavToggle' + navIdx;
a.href = 'javascript:collapseDiv( ' + navIdx + ' );';
a.appendChild( document.createTextNode( NavigationBarHide ) );
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for ( var j = 0; j < NavFrame.childNodes.length; j++ ) {
if ( hasClass( NavFrame.childNodes[j], 'NavHead' ) ) {
NavFrame.childNodes[j].appendChild( a );
}
}
colNavs[navIdx++] = NavFrame;
}
for ( i = 0; i < navIdx; i++ ) {
if ( ( navIdx > NavigationBarShowDefault && !hasClass( colNavs[i], 'expanded' ) ) || hasClass( colNavs[i], 'collapsed' ) ) {
collapseDiv( i );
}
}
}
function collapseDiv(idx) {
var div = document.getElementById( 'NavFrame' + idx );
var btn = document.getElementById( 'NavToggle' + idx );
if ( !div || !btn ) {
return false;
}
var isShown = ( btn.firstChild.data == NavigationBarHide );
btn.firstChild.data = isShown ? NavigationBarShow : NavigationBarHide;
var disp = isShown ? 'none' : 'block';
for ( var child = div.firstChild; child != null; child = child.nextSibling ) {
if ( hasClass( child, 'NavPic' ) || hasClass( child, 'NavContent' ) ) {
child.style.display = disp;
}
}
}
$( collapsibleDivs );
$( collapsibleTables );
// for backwards compatibility
var addLoadEvent = function ( func ) {
$( function(){ func(); } );
};
//{Modifynewsectionlink}
function newSectionLink(){
var plus = document.getElementById( 'ca-addsection' );
if ( !plus ) {
return;
}
var custom = document.getElementById( 'add-custom-section' );
if ( !custom ) {
return;
}
plus.firstChild.setAttribute( 'href', custom.getElementsByTagName( 'A' )[0].href );
}
// Choice of multiple search engines
// Autor: Jakob Voss, Guillaume (tret de de:MediaWiki:SpezialSuche.js)
// Version: 0.3.8
// Published as Public Domain
// карта поисковых машин и несколько OpenSearch-based полей
var searchEngines = {
mediawiki: {
ShortName: "внутренний поиск",
Template: "/w/index.php?search={searchTerms}"
},
yandex: {
ShortName: "Яндекс",
Template: "http://yandex.ru/yandsearch?text={searchTerms}&site=ru.wikinews.org"
},
google: {
ShortName: "Google",
Template: "http://www.google.cat/search?as_sitesearch=ru.wikinews.org&hl={language}&q={searchTerms}"
},
wikiwix: {
ShortName: "Wikiwix",
Template: "http://www.wikiwix.com/index.php?lang={language}&action={searchTerms}&disp=news"
},
yahoo: {
ShortName: "Yahoo!",
Template: "http://ru.search.yahoo.com/search?p={searchTerms}&vs=ru.wikinews.org"
},
bing: {
ShortName: "Bing",
Template: "http://www.bing.com/search?q={searchTerms}&q1=site:ru.wikinews.org"
}
};
function externalSearchEngines() {
if ( typeof SpecialSearchEnhanced2Disabled !== 'undefined' ) {
return;
}
var mainNode = document.getElementById( 'powersearch' );
if ( !mainNode ) {
mainNode = document.getElementById( 'search' );
}
if ( !mainNode ) {
return;
}
var beforeNode = document.getElementById( 'mw-search-top-table' );
if ( !beforeNode ) {
return;
}
beforeNode = beforeNode.nextSibling;
if ( !beforeNode ) {
return;
}
var firstEngine = 'mediawiki';
var choices = document.createElement( 'div' );
choices.setAttribute( 'id', 'searchengineChoices' );
choices.style.textAlign = 'center';
var lsearchbox = document.getElementById( 'searchText' );
var initValue = lsearchbox.value;
var space = '';
for (var id in searchEngines) {
var engine = searchEngines[id];
if ( engine.ShortName) {
if ( space ) {
choices.appendChild( space );
}
space = document.createTextNode( ' ' );
var attr = {
type: 'radio',
name: 'searchengineselect',
value: id,
onFocus: 'changeSearchEngine( this.value )',
id: 'searchengineRadio-' + id
};
var html = '<input';
for (var a in attr) {
html += ' ' + a + '="' + attr[a] + '"';
}
html += ' />';
var span = document.createElement( 'span' );
span.innerHTML = html;
choices.appendChild( span );
var label;
if ( engine.Template.indexOf( 'http' ) == 0 ) {
label = document.createElement( 'a' );
label.href = engine.Template.replace( '{searchTerms}', initValue ).replace( '{language}', 'ru' );
} else {
label = document.createElement( 'label' );
}
label.appendChild( document.createTextNode( engine.ShortName ) );
choices.appendChild( label );
}
}
mainNode.insertBefore( choices, beforeNode );
var input = document.createElement( 'input' );
input.id = 'searchengineextraparam';
input.type = 'hidden';
mainNode.insertBefore( input, beforeNode );
changeSearchEngine( firstEngine, initValue );
}
function changeSearchEngine( selectedId, searchTerms ) {
var currentId = document.getElementById( 'searchengineChoices' ).currentChoice;
if ( selectedId == currentId ) {
return;
}
document.getElementById( 'searchengineChoices' ).currentChoice = selectedId;
var radio = document.getElementById( 'searchengineRadio-' + selectedId );
radio.checked = 'checked';
var engine = searchEngines[selectedId];
var p = engine.Template.indexOf( '?' );
var params = engine.Template.substr( p + 1 );
var form;
if ( document.forms['search'] ) {
form = document.forms['search'];
} else {
form = document.getElementById( 'powersearch' );
}
form.setAttribute( 'action', engine.Template.substr( 0, p ) );
var l = ( '' + params ).split( '&' );
for ( var idx = 0; idx < l.length; idx++ ) {
var p = l[idx].split( '=' );
var pValue = p[1];
if ( pValue == '{language}' ) {
} else if ( pValue == '{searchTerms}' ) {
var input;
input = document.getElementById( 'searchText' );
input.name = p[0];
} else {
var input = document.getElementById( 'searchengineextraparam' );
input.name = p[0];
input.value = pValue;
}
}
}
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'Search' ) {
$( externalSearchEngines );
}
// ссылка [править] для нулевой секции
function editZeroSection(){
var body = document.getElementById( 'bodyContent' );
if ( !body || window.disable_zero_section ) {
return;
}
var h2s = body.getElementsByTagName( 'H2' );
var h2 = h2s[0];
if ( !h2 ) {
return;
}
if ( h2.parentNode.id == 'toctitle' ) {
h2 = h2s[1];
}
if ( !h2 ) {
return;
}
var span = h2.firstChild;
if ( !span || span.className != 'editsection' ) {
return;
}
var zero = span.cloneNode( true );
body.insertBefore( zero, body.firstChild );
var a = zero.getElementsByTagName( 'a' )[0];
a.title = a.title.replace( /:.*$/,': 0' );
a.setAttribute( 'href', a.href.replace( /§ion=1/,'§ion=0' ) );
}
var load_extratabs = true;
// добавление RSS-ленты последних статей
$( 'head' ).append( '<link type="application/rss+xml" href="http://feeds.feedburner.com/RuWikinewsLatestNews?format=xml" rel="alternate" title="(подписывайтесь здесь!) Главный новостной RSS-канал русских Викиновостей" \/>' );
/******************
Begin editintro stuff
This makes a custom editintro for people editing old pages, or coming directly from 'pedia
maintainer: User:bawolff
*****************/
function addEditIntro(template) {
//This function assumes that all edit links are in proper order (as in the title arg is first argument), and proper case
//This function appends &editintro=template to any link that edits the CURRENT page.
//template parameter should already be escaped
//var as = document.getElementsByTagName( 'a' );
var bodyContent = document.getElementById( 'bodyContent' );
var list = getElementsByClassName( ( bodyContent ? bodyContent : document ), 'span', 'editsection' );
list[list.length] = document.getElementById( 'ca-edit' );
for ( var i = 0; i < list.length; i++ ) {
var a = list[i].getElementsByTagName( 'a' )[0];
if ( !a ) {
continue; //just in case
}
if ( a.href.indexOf( '&action=edit' ) === -1 ) { //if not an edit link
continue;
}
if ( a.href.indexOf( '?title=' + mw.config.get( 'wgPageName' ) ) === -1 ) { //not a link to this page
continue;
}
if ( a.href.indexOf( '&editintro' ) !== -1 ) { //if it already has an editintro don't add another
continue;
}
a.href = a.href + '&editintro=' + template;
}
}
function doEditIntro() {
//called onload
try {
if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 || mw.config.get( 'wgPageName' ) === 'Заглавная_страница' ) {
return;
}
var notCurrent = doEditIntro.oldNews();
var fromPedia = ( document.referrer.indexOf( 'http://ru.wikipedia.org' ) === 0 );
if ( notCurrent ) {
addEditIntro( 'Template:Editintro_notcurrent' );
} else if ( fromPedia ) {
addEditIntro( 'Template:Editintro_from_wikipedia' );
}
}
catch ( e ) {
//in case of different skin and can't find cat links or something.
}
}
doEditIntro.oldNews = function () {
var cats = document.getElementById( 'catlinks' ).getElementsByTagName( 'a' );
var pubDate, pubCat, archiveCat, tmp, catName;
for ( var i = 0; i < cats.length; i++ ) {
catName = cats[i].title;
tmp = doEditIntro.parseDate( catName );
if ( !isNaN( tmp ) ) {
pubDate = tmp;
}
if ( catName === 'Категория:Опубликовано' ) {
pubCat = true;
}
if ( catName === 'Категория:Архивировано' || catName === 'Категория:Автоматически архивировано' ) {
archiveCat = true;
}
} //end getting cats
if ( !pubDate || !pubCat || archiveCat ) {
//not in a date category, not published, or already archived.
return false;
}
if ( ( ( new Date() ).getTime() - pubDate ) > 24 * 60 * 60 * 1000 ) { //if more than 24h elasped
return true;
}
else {
return false;
}
};
doEditIntro.parseDate = function ( datestring ) {
// + sign converts to number
//Returns NaN in even of parse failure.
var date = datestring.replace( doEditIntro.dateRegex, doEditIntro.dateFunc );
if ( date === datestring ) {
return NaN;
}
return +date;
};
doEditIntro.dateRegex = /^Категория: (\d\d?) (января|февраля|марта|апреля|мая|июня|июля|августа|сентября|октября|ноября|декабря) (20\d\d)$/;
doEditIntro.dateFunc = function ( str, month, day, year ) {
//Since JS month starts at month 0
var months = {'января' : 0, 'февраля': 1, 'марта': 2, 'апреля': 3, 'мая': 4, 'июня': 5, 'июля': 6, 'августа': 7, 'сентября': 8, 'октября': 9, 'ноября': 10, 'декабря': 11};
return Date.UTC( year, months[month], day );
};
$( doEditIntro );
/* Вкладка 'комментарии' */
if ( mw.config.get( 'wgPageName' ) != 'Заглавная_страница' ) {
importScript( 'Mediawiki:Comments.js' );
}