MediaWiki:Common.js: Versiyalar orasidagi farq
Qiyofa
Programmer (munozara | hissa) kTahrir izohi yoʻq |
Programmer (munozara | hissa) kTahrir izohi yoʻq |
||
| Qator 398: | Qator 398: | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
/* 1. Tasodifiy | /* | ||
* Matnni solishtirish uchun normalizatsiya | |||
*/ | |||
function normalizeText(text) { | |||
return $.trim(text || '') | |||
.replace(/\u00a0/g, ' ') | |||
.replace(/\s+/g, ' ') | |||
.toLowerCase(); | |||
} | |||
/* | |||
* Regex maxsus belgilarini himoyalash | |||
*/ | |||
function escapeRegex(value) { | |||
return String(value).replace( | |||
/[.*+?^${}()|[\]\\]/g, | |||
'\\$&' | |||
); | |||
} | |||
/* | |||
* Paragraf boshidagi takroriy maqola nomini | |||
* olib tashlash. | |||
*/ | |||
function removeRepeatedTitle($paragraph, title) { | |||
var fullTitle = $.trim(title); | |||
/* | |||
* Masalan: | |||
* | |||
* 1090 (son) -> 1090 | |||
* Mount Pleasant (Texas) -> Mount Pleasant | |||
*/ | |||
var baseTitle = $.trim( | |||
fullTitle.replace( | |||
/\s*\([^()]+\)\s*$/, | |||
'' | |||
) | |||
); | |||
var normalizedFullTitle = | |||
normalizeText(fullTitle); | |||
var normalizedBaseTitle = | |||
normalizeText(baseTitle); | |||
function matchesTitle(text) { | |||
var value = normalizeText(text); | |||
return ( | |||
value === normalizedFullTitle || | |||
value === normalizedBaseTitle | |||
); | |||
} | |||
/* | |||
* Avvalo paragraf boshidagi b/strong/a | |||
* elementlarni tekshiramiz. | |||
*/ | |||
var removed = false; | |||
$paragraph | |||
.find('b, strong, a') | |||
.each(function () { | |||
if (removed) { | |||
return false; | |||
} | |||
var $el = $(this); | |||
if (!matchesTitle($el.text())) { | |||
return; | |||
} | |||
/* | |||
* Elementdan oldin haqiqiy matn | |||
* mavjud yoki yo‘qligini tekshirish. | |||
*/ | |||
var beforeText = ''; | |||
try { | |||
var range = | |||
document.createRange(); | |||
range.setStart( | |||
$paragraph[0], | |||
0 | |||
); | |||
range.setEndBefore(this); | |||
beforeText = | |||
normalizeText( | |||
range | |||
.cloneContents() | |||
.textContent || '' | |||
); | |||
} catch (e) { | |||
beforeText = ''; | |||
} | |||
/* | |||
* Oldida matn bo‘lmasa, | |||
* bu paragraf boshidagi maqola nomi. | |||
*/ | |||
if (!beforeText) { | |||
var $removeElement = $el; | |||
/* | |||
* Agar: | |||
* | |||
* <b><a>Annopol</a></b> | |||
* | |||
* bo‘lsa, tashqi <b>ni olib tashlaymiz. | |||
*/ | |||
if ( | |||
$el.parent().is('b, strong') && | |||
matchesTitle( | |||
$el.parent().text() | |||
) | |||
) { | |||
$removeElement = | |||
$el.parent(); | |||
} | |||
/* | |||
* Agar: | |||
* | |||
* <a><b>Annopol</b></a> | |||
* | |||
* bo‘lsa, tashqi <a>ni olib tashlaymiz. | |||
*/ | |||
if ( | |||
$removeElement | |||
.parent() | |||
.is('a') && | |||
matchesTitle( | |||
$removeElement | |||
.parent() | |||
.text() | |||
) | |||
) { | |||
$removeElement = | |||
$removeElement.parent(); | |||
} | |||
var removeNode = | |||
$removeElement[0]; | |||
var nextNode = | |||
removeNode.nextSibling; | |||
$removeElement.remove(); | |||
/* | |||
* Nomdan keyingi: | |||
* | |||
* " — " | |||
* | |||
* ni olib tashlaymiz. | |||
* | |||
* Lekin "(" ni tegmaymiz. | |||
* | |||
* Masalan: | |||
* | |||
* 1090 (bir ming to‘qson) | |||
* | |||
* bunda "(" saqlanadi. | |||
*/ | |||
if ( | |||
nextNode && | |||
nextNode.nodeType === 3 | |||
) { | |||
nextNode.nodeValue = | |||
nextNode.nodeValue.replace( | |||
/^[\s\u00a0]*[—–-][\s\u00a0]*/, | |||
'' | |||
); | |||
} | |||
removed = true; | |||
return false; | |||
} | |||
}); | |||
/* | |||
* Agar b/strong/a orqali topilmasa, | |||
* oddiy matn boshini tekshiramiz. | |||
*/ | |||
if (!removed) { | |||
/* | |||
* Paragrafning HTMLini vaqtincha | |||
* string sifatida ham tekshiramiz. | |||
* | |||
* Bu ayrim murakkab MediaWiki | |||
* HTML strukturalarida kerak bo‘ladi. | |||
*/ | |||
var paragraphText = | |||
normalizeText( | |||
$paragraph.text() | |||
); | |||
var possibleTitles = [ | |||
normalizedFullTitle, | |||
normalizedBaseTitle | |||
]; | |||
var startsWithTitle = false; | |||
$.each( | |||
possibleTitles, | |||
function (index, value) { | |||
if ( | |||
value && | |||
paragraphText.indexOf(value) === 0 | |||
) { | |||
startsWithTitle = true; | |||
return false; | |||
} | |||
} | |||
); | |||
if (startsWithTitle) { | |||
/* | |||
* Birinchi haqiqiy text node'ni topamiz. | |||
*/ | |||
var firstTextNode = null; | |||
(function findFirstTextNode(node) { | |||
if (firstTextNode) { | |||
return; | |||
} | |||
for ( | |||
var i = 0; | |||
i < node.childNodes.length; | |||
i++ | |||
) { | |||
var child = | |||
node.childNodes[i]; | |||
if ( | |||
child.nodeType === 3 && | |||
$.trim( | |||
child.nodeValue | |||
) | |||
) { | |||
firstTextNode = child; | |||
return; | |||
} | |||
if ( | |||
child.nodeType === 1 | |||
) { | |||
findFirstTextNode( | |||
child | |||
); | |||
if (firstTextNode) { | |||
return; | |||
} | |||
} | |||
} | |||
})($paragraph[0]); | |||
if (firstTextNode) { | |||
var titleRegex = | |||
new RegExp( | |||
'^[\\s\\u00a0]*(?:' + | |||
escapeRegex( | |||
fullTitle | |||
) + | |||
'|' + | |||
escapeRegex( | |||
baseTitle | |||
) + | |||
')' + | |||
'[\\s\\u00a0]*' + | |||
'(?:[—–-][\\s\\u00a0]*)?', | |||
'i' | |||
); | |||
firstTextNode.nodeValue = | |||
firstTextNode | |||
.nodeValue | |||
.replace( | |||
titleRegex, | |||
'' | |||
); | |||
} | |||
} | |||
} | |||
/* | |||
* Yana bir fallback: | |||
* | |||
* birinchi elementning matni maqola nomi | |||
* bilan boshlansa. | |||
*/ | |||
var $firstVisible = | |||
$paragraph | |||
.children() | |||
.filter(function () { | |||
var text = | |||
normalizeText( | |||
$(this).text() | |||
); | |||
return text.length > 0; | |||
}) | |||
.first(); | |||
if ($firstVisible.length) { | |||
var firstVisibleText = | |||
normalizeText( | |||
$firstVisible.text() | |||
); | |||
if ( | |||
firstVisibleText === normalizedFullTitle || | |||
firstVisibleText === normalizedBaseTitle | |||
) { | |||
var next = | |||
$firstVisible[0] | |||
.nextSibling; | |||
$firstVisible.remove(); | |||
if ( | |||
next && | |||
next.nodeType === 3 | |||
) { | |||
next.nodeValue = | |||
next.nodeValue.replace( | |||
/^[\s\u00a0]*[—–-][\s\u00a0]*/, | |||
'' | |||
); | |||
} | |||
} | |||
} | |||
} | |||
/* | |||
* 1. Tasodifiy maqola nomini olish | |||
*/ | |||
api.get({ | api.get({ | ||
action: 'query', | action: 'query', | ||
| Qator 419: | Qator 781: | ||
} | } | ||
var title = data.query.random[0].title; | var title = | ||
data.query.random[0].title; | |||
/* 2. | |||
/* | |||
* 2. Maqolaning HTML matnini olish | |||
*/ | |||
api.get({ | api.get({ | ||
action: 'parse', | action: 'parse', | ||
| Qator 441: | Qator 807: | ||
} | } | ||
/* Keraksiz elementlarni olib tashlash */ | /* | ||
* HTMLni vaqtinchalik konteynerga | |||
* joylaymiz. | |||
*/ | |||
var $content = | |||
$('<div>').html( | |||
parseData.parse.text | |||
); | |||
/* | |||
* Keraksiz elementlarni olib tashlash | |||
*/ | |||
$content.find( | $content.find( | ||
'table.infobox,' + | 'table.infobox,' + | ||
| Qator 458: | Qator 833: | ||
'.references,' + | '.references,' + | ||
'.thumb,' + | '.thumb,' + | ||
'.gallery,' + | |||
'.mw-empty-elt,' + | '.mw-empty-elt,' + | ||
'style,' + | 'style,' + | ||
'script' | 'script' | ||
).remove(); | ).remove(); | ||
/* | /* | ||
* | * 3. Birinchi mazmunli paragrafni topish | ||
*/ | */ | ||
var $paragraph = | |||
$content | |||
.find('p') | |||
.filter(function () { | |||
return $.trim( | |||
$(this).text() | |||
).length > 20; | |||
}) | |||
. | .first(); | ||
if (!$paragraph.length) { | |||
$box.html( | |||
'<p>Maqola matni topilmadi.</p>' | |||
); | ); | ||
return; | |||
} | } | ||
/* | /* | ||
* | * 4. Takroriy maqola nomini olib tashlash | ||
*/ | */ | ||
removeRepeatedTitle( | |||
$paragraph, | |||
title | |||
); | |||
/* | /* | ||
* | * 5. Ichki havolalarni ZiyoSfera | ||
* | * manziliga moslash. | ||
*/ | */ | ||
$paragraph | $paragraph | ||
| Qator 725: | Qator 889: | ||
} | } | ||
/* | |||
* ./Maqola_nomi | |||
*/ | |||
if ( | if ( | ||
href.indexOf('./') === 0 | href.indexOf('./') === 0 | ||
| Qator 738: | Qator 905: | ||
); | ); | ||
} catch (e) { | } catch (e) { | ||
/* o‘z holicha */ | /* o‘z holicha qoldiriladi */ | ||
} | } | ||
| Qator 752: | Qator 919: | ||
/* | /* | ||
* | * 6. Asosiy maqola havolasi | ||
*/ | */ | ||
var articleUrl = | var articleUrl = | ||
mw.util.getUrl(title); | mw.util.getUrl(title); | ||
var safeTitle = $('<div>') | |||
/* | |||
* Sarlavhani xavfsiz HTML qilish | |||
*/ | |||
var safeTitle = | |||
$('<div>') | |||
.text(title) | |||
.html(); | |||
/* | /* | ||
* | * 7. Yakuniy natija | ||
*/ | */ | ||
var output = | var output = | ||
| Qator 780: | Qator 948: | ||
'">' + | '">' + | ||
safeTitle + | |||
'</a>' + | '</a>' + | ||
| Qator 793: | Qator 961: | ||
'<div ' + | '<div ' + | ||
'class="ziyo-random-more" ' + | |||
'style="' + | |||
'text-align:right;' + | |||
'margin-top:8px;' + | |||
'">' + | |||
'<a href="' + | '<a href="' + | ||
| Qator 811: | Qator 979: | ||
'</div>'; | '</div>'; | ||
/* | |||
* 8. Bosh sahifaga chiqarish | |||
*/ | |||
$box.html(output); | $box.html(output); | ||
}).fail(function ( | }).fail(function ( | ||
| Qator 825: | Qator 998: | ||
$box.html( | $box.html( | ||
'<p>Maqola matnini ' + | '<p>' + | ||
' | 'Maqola matnini yuklashda ' + | ||
'xatolik yuz berdi.' + | |||
'</p>' | |||
); | ); | ||
}); | }); | ||
}).fail(function ( | }).fail(function ( | ||
| Qator 842: | Qator 1 018: | ||
$box.html( | $box.html( | ||
'<p>Tasodifiy maqolani ' + | '<p>' + | ||
' | 'Tasodifiy maqolani yuklashda ' + | ||
'xatolik yuz berdi.' + | |||
'</p>' | |||
); | ); | ||
}); | }); | ||
2026-yil 13-avgust, 22:49 dagi koʻrinishi
/*global mw */
/*jshint strict: false, browser: true, jquery: true */
/**
* MediaWiki:Common.js sahifasidagi kod imkon qadar kam bo‘lishi kerak,
* chunki u Ziyosferadagi barcha sahifalarda barcha foydalanuvchilar uchun yuklanadi.
* Imkon bo‘lsa, katta funksiyalarni alohida gadget sifatida yaratish tavsiya etiladi.
*
* Common.js gadget emasligi sababli, unga bog‘liqliklarni alohida e’lon qilib bo‘lmaydi.
* Shuning uchun kerakli modullar mw.loader.using orqali talab qilinganda yuklanadi.
*/
importMW = function (name) { importScript('MediaWiki:' + name + '.js'); };
mw.loader.using(['mediawiki.util', 'jquery.client'], function () {
/* Begin of mw.loader.using callback */
importMW('Sidebar-related');
/** Bosh sahifa tartibi uchun tuzatishlar
*
* Tavsif: mavjud tillar to‘liq ro‘yxatiga qo‘shimcha havola qo‘shadi.
*/
if ($.inArray(mw.config.get('wgPageName'), ['Bosh_Sahifa', 'Munozara:Bosh_Sahifa']) !== -1) {
$(function () {
mw.util.addPortletLink(
'p-lang',
'https://ziyosfera.uz/ziyo/Ziyosfera:Ensiklopediyalar_roʻyxati',
'Toʻliq roʻyxat',
'interwiki-completelist',
'Ensiklopediyalar va tillar bo‘yicha toʻliq roʻyxat'
);
});
}
// Ziyosfera maxsus sahifalari va ayrim istisno maqolalardan tashqari
if ($.inArray(mw.config.get('wgArticleId'), [639373, 932117, 1297302, 25133866]) === -1)
importMW('Wikibugs');
/**
* User:Name/skin.js va skin.css sahifalarini joriy skin sahifalariga yo‘naltirish
* agar alohida skin sahifasi mavjud bo‘lmasa.
*
* Dependencies: mediawiki.util
*
* @source https://www.mediawiki.org/wiki/Snippets/Redirect_skin.js
* @revision 2016-04-13
*/
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) {
var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
// Slashdan oldin va keyin qism borligini tekshiradi
// Ikkinchi qism skin.js yoki skin.css bo‘lishi kerak
if ( titleParts.length == 2 ) {
var userSkinPage = titleParts[0] + '/' + mw.config.get( 'skin' );
if ( titleParts[1] === 'skin.js' ) {
location.href = mw.util.getUrl( userSkinPage + '.js' );
} else if ( titleParts[1] === 'skin.css' ) {
location.href = mw.util.getUrl( userSkinPage + '.css' );
}
}
}
/**
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @revision 2016-03-26
*/
mw.loader.using( ['mediawiki.util'], function () {
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );
if ( extraCSS ) {
if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
mw.loader.load( '/ziyo/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
} else {
mw.notify( 'Faqat MediaWiki nomfazodagi sahifalarga ruxsat berilgan.', { title: 'Noto‘g‘ri withCSS qiymati' } );
}
}
if ( extraJS ) {
if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
mw.loader.load( '/ziyo/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
} else {
mw.notify( 'Faqat MediaWiki nomfazodagi sahifalarga ruxsat berilgan.', { title: 'Noto‘g‘ri withJS qiymati' } );
}
}
} );
/**
* Windows XP Unicode shrift ko‘rinishini tuzatish
*/
if ( navigator.appVersion.search(/windows nt 5/i) != -1 ) {
mw.util.addCSS( '.IPA { font-family: "Lucida Sans Unicode", "Arial Unicode MS"; } ' +
'.Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; } ' );
}
/**
* WikiMiniAtlas
*
* Tavsif: WikiMiniAtlas — koordinata havolalari uchun kichik xarita oynasi.
* Ushbu skript koordinata havolalari yonida xarita tugmasini ko‘rsatadi.
* Skript meta.wikimedia.org sahifasida joylashgan, chunki u ko‘plab loyihalarda ishlatiladi.
* Batafsil: [[Meta:WikiMiniAtlas]]
* Mas’ullar: [[User:Dschwen]]
*/
( function ( $, mw ) {
var require_wikiminiatlas = false;
var coord_filter = /geohack/;
$( document ).ready( function() {
$( 'a.external.text' ).each( function( key, link ) {
if ( link.href && coord_filter.exec( link.href ) ) {
require_wikiminiatlas = true;
// sikldan chiqish
return false;
}
} );
if ( $( 'div.kmldata' ).length ) {
require_wikiminiatlas = true;
}
if ( require_wikiminiatlas ) {
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
}
} );
} )( jQuery, mediaWiki );
/**
* Interwiki havolalarda tanlangan maqolalarni belgilash **********************
*
* Tavsif: boshqa tillardagi tanlangan yoki yaxshi maqolalarga havolalarni
* yulduzcha yoki maxsus belgi orqali ajratib ko‘rsatadi.
* Mas’ullar: [[User:R. Koot]]
*/
function LinkFA() {
if ( document.getElementById( 'p-lang' ) ) {
var InterwikiLinks = document.getElementById( 'p-lang' ).getElementsByTagName( 'li' );
for ( var i = 0; i < InterwikiLinks.length; i++ ) {
var className = InterwikiLinks[i].className.match(/interwiki-[-\w]+/);
if ( document.getElementById( className + '-fa' ) && InterwikiLinks[i].className.indexOf( 'badge-featuredarticle' ) === -1 ) {
InterwikiLinks[i].className += ' FA';
InterwikiLinks[i].title = 'Bu boshqa tilda tanlangan maqoladir.';
} else if ( document.getElementById( className + '-ga' ) && InterwikiLinks[i].className.indexOf( 'badge-goodarticle' ) === -1 ) {
InterwikiLinks[i].className += ' GA';
InterwikiLinks[i].title = 'Bu boshqa tilda yaxshi maqoladir.';
}
}
}
}
mw.hook( 'wikipage.content' ).add( LinkFA );
/**
* Yig‘iladigan jadvallar ******************************************************
*
* Tavsif: jadvallarni faqat sarlavha qatori ko‘rinadigan qilib yig‘ish imkonini beradi.
* Qarang: [[Ziyosfera:NavFrame]]
* Mas’ullar: [[User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = 'yashir';
var expandCaption = 'koʻrsat';
window.collapseTable = function ( tableIndex ) {
var Button = document.getElementById( 'collapseButton' + tableIndex );
var Table = document.getElementById( 'collapsibleTable' + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
var i;
if ( Button.firstChild.data === collapseCaption ) {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = 'none';
}
Button.firstChild.data = expandCaption;
} else {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
};
function createCollapseButtons() {
var tableIndex = 0;
var NavigationBoxes = {};
var Tables = document.getElementsByTagName( 'table' );
var i;
function handleButtonLink( index, e ) {
window.collapseTable( index );
e.preventDefault();
}
for ( i = 0; i < Tables.length; i++ ) {
if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
/* tugma faqat sarlavha qatori mavjud bo‘lsa qo‘shiladi */
var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
if ( !HeaderRow ) continue;
var Header = HeaderRow.getElementsByTagName( 'th' )[0];
if ( !Header ) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
var Button = document.createElement( 'span' );
var ButtonLink = document.createElement( 'a' );
var ButtonText = document.createTextNode( collapseCaption );
Button.className = 'collapseButton'; /* Uslublar Common.css ichida e’lon qilinadi */
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
ButtonLink.setAttribute( 'href', '#' );
$( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( '[' ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( ']' ) );
Header.insertBefore( Button, Header.firstChild );
tableIndex++;
}
}
for ( i = 0; i < tableIndex; i++ ) {
if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
window.collapseTable( i );
}
else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
var element = NavigationBoxes[i];
while ((element = element.parentNode)) {
if ( $( element ).hasClass( 'outercollapse' ) ) {
window.collapseTable ( i );
break;
}
}
}
}
}
mw.hook( 'wikipage.content' ).add( createCollapseButtons );
/**
* Dinamik navigatsiya panellari
*
* Tavsif: Qarang: [[Ziyosfera:NavFrame]]
* Mas’ullar: faol kuzatilmaydi
*/
/* kerakli so‘zlar */
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
/**
* Navigatsiya bloklaridagi tarkib va rasmni ko‘rsatish/yashirish
* Parametr:
* indexNavigationBar: almashtiriladigan navigatsiya blokining tartib raqami
**/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var NavChild;
if ( !NavFrame || !NavToggle ) {
return false;
}
/* hozir ko‘rsatilgan bo‘lsa */
if ( NavToggle.firstChild.data === NavigationBarHide ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
/* hozir yashirilgan bo‘lsa */
} else if ( NavToggle.firstChild.data === NavigationBarShow ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
event.preventDefault();
};
/* navigatsiya bloklariga ko‘rsatish/yashirish tugmasini qo‘shadi */
function createNavigationBarToggleButton() {
var indexNavigationBar = 0;
var NavFrame;
var NavChild;
/* barcha <div> elementlar bo‘ylab yuradi */
var divs = document.getElementsByTagName( 'div' );
for ( var i = 0; (NavFrame = divs[i]); i++ ) {
/* navigatsiya bloki topilsa */
if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
indexNavigationBar++;
var NavToggle = document.createElement( 'a' );
NavToggle.className = 'NavToggle';
NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
NavToggle.setAttribute( 'href', '#' );
$( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
/**
* Ba’zi eski andozalarda NavFrame tarkibi style="display:none" orqali yashirilgan bo‘lishi mumkin.
* Ushbu tekshiruv eski holatlar bilan moslikni saqlash uchun qoldirilgan.
* Yangi tavsiya: NavFrame elementining o‘ziga "collapsed" klassini berish.
*/
for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
if ( NavChild.style.display === 'none' ) {
isCollapsed = true;
}
}
}
if ( isCollapsed ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
NavChild.style.display = 'none';
}
}
}
var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
NavToggle.appendChild( NavToggleText );
/* NavHead topiladi va toggle havola unga biriktiriladi */
for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
NavToggle.style.color = NavFrame.childNodes[j].style.color;
NavFrame.childNodes[j].appendChild( NavToggle );
}
}
NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
}
}
}
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
if ( document.editform ){
mw.loader.load('/ziyo/index.php?title=MediaWiki:Sayqallash.js&action=raw&ctype=text/javascript');
}
/* </pre> */
mw.loader.load('/ziyo/index.php?title=MediaWiki:CyrillicTitle.js&action=raw&ctype=text/javascript');
/* End of mw.loader.using callback */
} );
/* Edittools panelini Qisqa tavsifdan yuqoriga chiqarish */
jQuery(function ($) {
'use strict';
function moveEdittools() {
var $edittools = $('#editpage-specialchars');
var $editOptions = $('.editOptions');
if ($edittools.length && $editOptions.length) {
$edittools.insertBefore($editOptions);
}
}
moveEdittools();
setTimeout(moveEdittools, 500);
setTimeout(moveEdittools, 1500);
});
/* ZiyoSfera — Bosh sahifada tasodifiy maqola */
mw.loader.using(
['mediawiki.api', 'mediawiki.util'],
function () {
'use strict';
jQuery(function ($) {
var $box = $('#z-rand .ziyo-box-body');
if (!$box.length) {
return;
}
$box.html('<p>Tasodifiy maqola yuklanmoqda...</p>');
var api = new mw.Api();
/*
* Matnni solishtirish uchun normalizatsiya
*/
function normalizeText(text) {
return $.trim(text || '')
.replace(/\u00a0/g, ' ')
.replace(/\s+/g, ' ')
.toLowerCase();
}
/*
* Regex maxsus belgilarini himoyalash
*/
function escapeRegex(value) {
return String(value).replace(
/[.*+?^${}()|[\]\\]/g,
'\\$&'
);
}
/*
* Paragraf boshidagi takroriy maqola nomini
* olib tashlash.
*/
function removeRepeatedTitle($paragraph, title) {
var fullTitle = $.trim(title);
/*
* Masalan:
*
* 1090 (son) -> 1090
* Mount Pleasant (Texas) -> Mount Pleasant
*/
var baseTitle = $.trim(
fullTitle.replace(
/\s*\([^()]+\)\s*$/,
''
)
);
var normalizedFullTitle =
normalizeText(fullTitle);
var normalizedBaseTitle =
normalizeText(baseTitle);
function matchesTitle(text) {
var value = normalizeText(text);
return (
value === normalizedFullTitle ||
value === normalizedBaseTitle
);
}
/*
* Avvalo paragraf boshidagi b/strong/a
* elementlarni tekshiramiz.
*/
var removed = false;
$paragraph
.find('b, strong, a')
.each(function () {
if (removed) {
return false;
}
var $el = $(this);
if (!matchesTitle($el.text())) {
return;
}
/*
* Elementdan oldin haqiqiy matn
* mavjud yoki yo‘qligini tekshirish.
*/
var beforeText = '';
try {
var range =
document.createRange();
range.setStart(
$paragraph[0],
0
);
range.setEndBefore(this);
beforeText =
normalizeText(
range
.cloneContents()
.textContent || ''
);
} catch (e) {
beforeText = '';
}
/*
* Oldida matn bo‘lmasa,
* bu paragraf boshidagi maqola nomi.
*/
if (!beforeText) {
var $removeElement = $el;
/*
* Agar:
*
* <b><a>Annopol</a></b>
*
* bo‘lsa, tashqi <b>ni olib tashlaymiz.
*/
if (
$el.parent().is('b, strong') &&
matchesTitle(
$el.parent().text()
)
) {
$removeElement =
$el.parent();
}
/*
* Agar:
*
* <a><b>Annopol</b></a>
*
* bo‘lsa, tashqi <a>ni olib tashlaymiz.
*/
if (
$removeElement
.parent()
.is('a') &&
matchesTitle(
$removeElement
.parent()
.text()
)
) {
$removeElement =
$removeElement.parent();
}
var removeNode =
$removeElement[0];
var nextNode =
removeNode.nextSibling;
$removeElement.remove();
/*
* Nomdan keyingi:
*
* " — "
*
* ni olib tashlaymiz.
*
* Lekin "(" ni tegmaymiz.
*
* Masalan:
*
* 1090 (bir ming to‘qson)
*
* bunda "(" saqlanadi.
*/
if (
nextNode &&
nextNode.nodeType === 3
) {
nextNode.nodeValue =
nextNode.nodeValue.replace(
/^[\s\u00a0]*[—–-][\s\u00a0]*/,
''
);
}
removed = true;
return false;
}
});
/*
* Agar b/strong/a orqali topilmasa,
* oddiy matn boshini tekshiramiz.
*/
if (!removed) {
/*
* Paragrafning HTMLini vaqtincha
* string sifatida ham tekshiramiz.
*
* Bu ayrim murakkab MediaWiki
* HTML strukturalarida kerak bo‘ladi.
*/
var paragraphText =
normalizeText(
$paragraph.text()
);
var possibleTitles = [
normalizedFullTitle,
normalizedBaseTitle
];
var startsWithTitle = false;
$.each(
possibleTitles,
function (index, value) {
if (
value &&
paragraphText.indexOf(value) === 0
) {
startsWithTitle = true;
return false;
}
}
);
if (startsWithTitle) {
/*
* Birinchi haqiqiy text node'ni topamiz.
*/
var firstTextNode = null;
(function findFirstTextNode(node) {
if (firstTextNode) {
return;
}
for (
var i = 0;
i < node.childNodes.length;
i++
) {
var child =
node.childNodes[i];
if (
child.nodeType === 3 &&
$.trim(
child.nodeValue
)
) {
firstTextNode = child;
return;
}
if (
child.nodeType === 1
) {
findFirstTextNode(
child
);
if (firstTextNode) {
return;
}
}
}
})($paragraph[0]);
if (firstTextNode) {
var titleRegex =
new RegExp(
'^[\\s\\u00a0]*(?:' +
escapeRegex(
fullTitle
) +
'|' +
escapeRegex(
baseTitle
) +
')' +
'[\\s\\u00a0]*' +
'(?:[—–-][\\s\\u00a0]*)?',
'i'
);
firstTextNode.nodeValue =
firstTextNode
.nodeValue
.replace(
titleRegex,
''
);
}
}
}
/*
* Yana bir fallback:
*
* birinchi elementning matni maqola nomi
* bilan boshlansa.
*/
var $firstVisible =
$paragraph
.children()
.filter(function () {
var text =
normalizeText(
$(this).text()
);
return text.length > 0;
})
.first();
if ($firstVisible.length) {
var firstVisibleText =
normalizeText(
$firstVisible.text()
);
if (
firstVisibleText === normalizedFullTitle ||
firstVisibleText === normalizedBaseTitle
) {
var next =
$firstVisible[0]
.nextSibling;
$firstVisible.remove();
if (
next &&
next.nodeType === 3
) {
next.nodeValue =
next.nodeValue.replace(
/^[\s\u00a0]*[—–-][\s\u00a0]*/,
''
);
}
}
}
}
/*
* 1. Tasodifiy maqola nomini olish
*/
api.get({
action: 'query',
list: 'random',
rnnamespace: 0,
rnlimit: 1,
formatversion: 2
}).done(function (data) {
if (
!data ||
!data.query ||
!data.query.random ||
!data.query.random.length
) {
$box.html(
'<p>Tasodifiy maqolani topib bo‘lmadi.</p>'
);
return;
}
var title =
data.query.random[0].title;
/*
* 2. Maqolaning HTML matnini olish
*/
api.get({
action: 'parse',
page: title,
prop: 'text',
redirects: true,
formatversion: 2
}).done(function (parseData) {
if (
!parseData ||
!parseData.parse ||
!parseData.parse.text
) {
$box.html(
'<p>Maqola matnini olib bo‘lmadi.</p>'
);
return;
}
/*
* HTMLni vaqtinchalik konteynerga
* joylaymiz.
*/
var $content =
$('<div>').html(
parseData.parse.text
);
/*
* Keraksiz elementlarni olib tashlash
*/
$content.find(
'table.infobox,' +
'table.navbox,' +
'.navbox,' +
'.vertical-navbox,' +
'.metadata,' +
'.ambox,' +
'.hatnote,' +
'.mw-editsection,' +
'.reflist,' +
'.references,' +
'.thumb,' +
'.gallery,' +
'.mw-empty-elt,' +
'style,' +
'script'
).remove();
/*
* 3. Birinchi mazmunli paragrafni topish
*/
var $paragraph =
$content
.find('p')
.filter(function () {
return $.trim(
$(this).text()
).length > 20;
})
.first();
if (!$paragraph.length) {
$box.html(
'<p>Maqola matni topilmadi.</p>'
);
return;
}
/*
* 4. Takroriy maqola nomini olib tashlash
*/
removeRepeatedTitle(
$paragraph,
title
);
/*
* 5. Ichki havolalarni ZiyoSfera
* manziliga moslash.
*/
$paragraph
.find('a[href]')
.each(function () {
var href =
$(this).attr('href');
if (!href) {
return;
}
/*
* ./Maqola_nomi
*/
if (
href.indexOf('./') === 0
) {
var target =
href.substring(2);
try {
target =
decodeURIComponent(
target
);
} catch (e) {
/* o‘z holicha qoldiriladi */
}
$(this).attr(
'href',
mw.util.getUrl(
target
)
);
}
});
/*
* 6. Asosiy maqola havolasi
*/
var articleUrl =
mw.util.getUrl(title);
/*
* Sarlavhani xavfsiz HTML qilish
*/
var safeTitle =
$('<div>')
.text(title)
.html();
/*
* 7. Yakuniy natija
*/
var output =
'<div class="ziyo-random-article">' +
'<p>' +
'<strong>' +
'<a href="' +
articleUrl +
'">' +
safeTitle +
'</a>' +
'</strong>' +
' — ' +
$paragraph.html() +
'</p>' +
'<div ' +
'class="ziyo-random-more" ' +
'style="' +
'text-align:right;' +
'margin-top:8px;' +
'">' +
'<a href="' +
articleUrl +
'">' +
'Maqolani o‘qish →' +
'</a>' +
'</div>' +
'</div>';
/*
* 8. Bosh sahifaga chiqarish
*/
$box.html(output);
}).fail(function (
code,
details
) {
console.error(
'ZiyoSfera parse API xatosi:',
code,
details
);
$box.html(
'<p>' +
'Maqola matnini yuklashda ' +
'xatolik yuz berdi.' +
'</p>'
);
});
}).fail(function (
code,
details
) {
console.error(
'ZiyoSfera random API xatosi:',
code,
details
);
$box.html(
'<p>' +
'Tasodifiy maqolani yuklashda ' +
'xatolik yuz berdi.' +
'</p>'
);
});
});
}
);