MediaWiki:Common.js: Versiyalar orasidagi farq
Qiyofa
Programmer (munozara | hissa) kTahrir izohi yoʻq |
Programmer (munozara | hissa) kTahrir izohi yoʻq |
||
| Qator 390: | Qator 390: | ||
var $box = $('#z-rand .ziyo-box-body'); | var $box = $('#z-rand .ziyo-box-body'); | ||
if (!$box.length) { | if (!$box.length) { | ||
return; | return; | ||
| Qator 422: | Qator 421: | ||
var title = data.query.random[0].title; | var title = data.query.random[0].title; | ||
/ | /* 2. Maqola HTML matnini olish */ | ||
api.get({ | api.get({ | ||
action: 'parse', | action: 'parse', | ||
| Qator 444: | Qator 441: | ||
} | } | ||
var $content = $('<div>').html( | var $content = $('<div>').html( | ||
parseData.parse.text | parseData.parse.text | ||
); | ); | ||
/ | /* Keraksiz elementlarni olib tashlash */ | ||
$content.find( | $content.find( | ||
'table.infobox, ' + | 'table.infobox,' + | ||
'table.navbox, ' + | 'table.navbox,' + | ||
'.navbox, ' + | '.navbox,' + | ||
'.vertical-navbox, ' + | '.vertical-navbox,' + | ||
'.metadata, ' + | '.metadata,' + | ||
'.ambox, ' + | '.ambox,' + | ||
'.hatnote, ' + | '.hatnote,' + | ||
'.mw-editsection, ' + | '.mw-editsection,' + | ||
'.reflist, ' + | '.reflist,' + | ||
'.references, ' + | '.references,' + | ||
'.thumb, ' + | '.thumb,' + | ||
'.mw-empty-elt, ' + | '.mw-empty-elt,' + | ||
'style, ' + | 'style,' + | ||
'script' | 'script' | ||
).remove(); | ).remove(); | ||
/ | /* 3. Birinchi mazmunli paragraf */ | ||
var $paragraph = $content | var $paragraph = $content | ||
.find('p') | .find('p') | ||
| Qator 489: | Qator 479: | ||
return; | return; | ||
} | } | ||
/* | /* | ||
* 4. | * 4. PARAGRAF BOSHIDAGI TAKRORIY | ||
* | * MAQOLA NOMINI OLIB TASHLASH | ||
*/ | */ | ||
function normalizeText(text) { | |||
return $.trim(text) | |||
.replace(/\u00a0/g, ' ') | |||
.replace(/\s+/g, ' ') | |||
.toLowerCase(); | |||
} | |||
var normalizedTitle = | |||
normalizeText(title); | |||
/* | /* | ||
* | * Masalan: | ||
* Mount Pleasant (Texas) | * Mount Pleasant (Texas) | ||
* -> | * -> Mount Pleasant | ||
*/ | */ | ||
var baseTitle = $.trim( | var baseTitle = $.trim( | ||
| Qator 519: | Qator 509: | ||
var normalizedBaseTitle = | var normalizedBaseTitle = | ||
baseTitle | normalizeText(baseTitle); | ||
function isTitle(text) { | |||
function | |||
var | var value = | ||
text | normalizeText(text); | ||
return ( | return ( | ||
value === normalizedTitle || | |||
value === normalizedBaseTitle | |||
); | ); | ||
} | } | ||
/* | /* | ||
* | * Paragraf boshida maqola nomini | ||
* saqlayotgan b, strong yoki a | |||
* elementni qidiramiz. | |||
* | |||
* | |||
*/ | */ | ||
var $titleElement = null; | |||
$paragraph | |||
.find('b, strong, a') | |||
.each(function () { | |||
if (!isTitle($(this).text())) { | |||
return; | |||
} | |||
/* | |||
* Shu elementdan oldin haqiqiy | |||
* matn mavjud yoki yo‘qligini | |||
* tekshiramiz. | |||
*/ | |||
var range = | |||
document.createRange(); | |||
range.setStart( | |||
$paragraph[0], | |||
0 | |||
); | |||
range.setEndBefore(this); | |||
var beforeText = | |||
normalizeText( | |||
range | |||
.cloneContents() | |||
.textContent || '' | |||
); | |||
/* | |||
* Undan oldin matn bo‘lmasa, | |||
* demak bu paragraf boshidagi | |||
* maqola nomidir. | |||
*/ | |||
if (!beforeText) { | |||
$titleElement = $(this); | |||
return false; | |||
} | |||
}); | |||
if ( | if ( | ||
$ | $titleElement && | ||
$titleElement.length | |||
) { | ) { | ||
/* | |||
* Agar <a> <b> ichida bo‘lsa | |||
* tashqi <b>ni olib tashlaymiz. | |||
*/ | |||
var $removeElement = | |||
$titleElement; | |||
if ( | |||
$titleElement.parent().is( | |||
'b, strong' | |||
) && | |||
isTitle( | |||
$titleElement | |||
.parent() | |||
.text() | |||
) | |||
) { | |||
$removeElement = | |||
$titleElement.parent(); | |||
} | |||
var removedNode = | |||
$removeElement[0]; | |||
var nextNode = | var nextNode = | ||
removedNode.nextSibling; | |||
$ | $removeElement.remove(); | ||
/* | /* | ||
* | * Keyingi: | ||
* olib | * | ||
* " — " | |||
* | |||
* qismini ham olib tashlash. | |||
*/ | */ | ||
if ( | if ( | ||
| Qator 578: | Qator 619: | ||
nextNode.nodeValue = | nextNode.nodeValue = | ||
nextNode.nodeValue.replace( | nextNode.nodeValue.replace( | ||
/^\s*[—–-]\s*/, | /^[\s\u00a0]*[—–-][\s\u00a0]*/, | ||
'' | '' | ||
); | ); | ||
} | } | ||
} | } | ||
/* | /* | ||
* | * 5. Qo‘shimcha himoya: | ||
* | * | ||
* oddiy text node | * Agar nom oddiy text node | ||
* sifatida kelsa. | |||
*/ | */ | ||
var | var firstTextNode = null; | ||
(function findFirstText(node) { | |||
if (firstTextNode) { | |||
return; | |||
} | |||
for ( | |||
var i = 0; | |||
i < node.childNodes.length; | |||
i++ | |||
) { | |||
var child = | |||
node.childNodes[i]; | |||
if ( | if ( | ||
child.nodeType === 3 && | |||
$.trim( | |||
child.nodeValue | |||
) | ) | ||
) { | ) { | ||
firstTextNode = child; | |||
return; | |||
} | |||
if ( | |||
child.nodeType === 1 | |||
) { | |||
findFirstText(child); | |||
return | if (firstTextNode) { | ||
return; | |||
} | |||
} | } | ||
}); | } | ||
})($paragraph[0]); | |||
if (firstTextNode) { | |||
var text = | |||
firstTextNode.nodeValue; | |||
/* | |||
* Regex uchun maxsus belgilarni | |||
* himoyalash. | |||
*/ | |||
function escapeRegex(value) { | |||
return value.replace( | |||
/[.*+?^${}()|[\]\\]/g, | |||
'\\$&' | |||
); | |||
} | |||
var titleRegex = | |||
new RegExp( | |||
'^[\\s\\u00a0]*(?:' + | |||
escapeRegex(title) + | |||
'|' + | |||
escapeRegex(baseTitle) + | |||
')[\\s\\u00a0]*' + | |||
'[—–-]?' + | |||
'[\\s\\u00a0]*', | |||
'i' | |||
); | |||
firstTextNode.nodeValue = | |||
text.replace( | |||
titleRegex, | |||
'' | |||
); | |||
} | |||
/* | /* | ||
* 6. Ichki havolalarni | * 6. Ichki havolalarni | ||
* | * ZiyoSferaga moslash | ||
*/ | */ | ||
$paragraph | $paragraph | ||
| Qator 647: | Qator 725: | ||
} | } | ||
if ( | if ( | ||
href.indexOf('./') === 0 | href.indexOf('./') === 0 | ||
| Qator 667: | Qator 738: | ||
); | ); | ||
} catch (e) { | } catch (e) { | ||
/* | /* o‘z holicha */ | ||
} | } | ||
| Qator 678: | Qator 749: | ||
} | } | ||
}); | }); | ||
/* | /* | ||
* 7. Asosiy maqola | * 7. Asosiy maqola linki | ||
*/ | */ | ||
var articleUrl = | var articleUrl = | ||
mw.util.getUrl(title); | mw.util.getUrl(title); | ||
var safeTitle = $('<div>') | var safeTitle = $('<div>') | ||
.text(title) | .text(title) | ||
.html(); | .html(); | ||
/* | /* | ||
* 8. | * 8. Natija | ||
* | * | ||
* | * Başkuyu — Turkiyaning ... | ||
* | * | ||
* | * Başkuyu linkli. | ||
*/ | */ | ||
var output = | var output = | ||
| Qator 707: | Qator 775: | ||
'<strong>' + | '<strong>' + | ||
'<a href="' + | '<a href="' + | ||
articleUrl + | |||
'">' + | '">' + | ||
safeTitle + | |||
'</a>' + | '</a>' + | ||
'</strong>' + | '</strong>' + | ||
| Qator 720: | Qator 792: | ||
'</p>' + | '</p>' + | ||
'<div class="ziyo-random-more" ' + | '<div ' + | ||
'class="ziyo-random-more" ' + | |||
'style="' + | |||
'text-align:right;' + | |||
'margin-top:8px;' + | |||
'">' + | |||
'<a href="' + | '<a href="' + | ||
articleUrl + | |||
'">' + | '">' + | ||
'Maqolani o‘qish →' + | 'Maqolani o‘qish →' + | ||
'</a>' + | '</a>' + | ||
| Qator 736: | Qator 811: | ||
'</div>'; | '</div>'; | ||
$box.html(output); | $box.html(output); | ||
| Qator 753: | Qator 825: | ||
$box.html( | $box.html( | ||
'<p> | '<p>Maqola matnini ' + | ||
'yuklashda xatolik yuz berdi.</p>' | |||
'xatolik yuz berdi. | |||
); | ); | ||
}); | }); | ||
| Qator 772: | Qator 842: | ||
$box.html( | $box.html( | ||
'<p> | '<p>Tasodifiy maqolani ' + | ||
'yuklashda xatolik yuz berdi.</p>' | |||
'xatolik yuz berdi. | |||
); | ); | ||
}); | }); | ||
2026-yil 13-avgust, 22:45 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();
/* 1. Tasodifiy maqolani 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. Maqola 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;
}
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,' +
'.mw-empty-elt,' +
'style,' +
'script'
).remove();
/* 3. Birinchi mazmunli paragraf */
var $paragraph = $content
.find('p')
.filter(function () {
return $.trim(
$(this).text()
).length > 30;
})
.first();
if (!$paragraph.length) {
$box.html(
'<p>Maqola matni topilmadi.</p>'
);
return;
}
/*
* 4. PARAGRAF BOSHIDAGI TAKRORIY
* MAQOLA NOMINI OLIB TASHLASH
*/
function normalizeText(text) {
return $.trim(text)
.replace(/\u00a0/g, ' ')
.replace(/\s+/g, ' ')
.toLowerCase();
}
var normalizedTitle =
normalizeText(title);
/*
* Masalan:
* Mount Pleasant (Texas)
* -> Mount Pleasant
*/
var baseTitle = $.trim(
title.replace(
/\s*\([^()]+\)\s*$/,
''
)
);
var normalizedBaseTitle =
normalizeText(baseTitle);
function isTitle(text) {
var value =
normalizeText(text);
return (
value === normalizedTitle ||
value === normalizedBaseTitle
);
}
/*
* Paragraf boshida maqola nomini
* saqlayotgan b, strong yoki a
* elementni qidiramiz.
*/
var $titleElement = null;
$paragraph
.find('b, strong, a')
.each(function () {
if (!isTitle($(this).text())) {
return;
}
/*
* Shu elementdan oldin haqiqiy
* matn mavjud yoki yo‘qligini
* tekshiramiz.
*/
var range =
document.createRange();
range.setStart(
$paragraph[0],
0
);
range.setEndBefore(this);
var beforeText =
normalizeText(
range
.cloneContents()
.textContent || ''
);
/*
* Undan oldin matn bo‘lmasa,
* demak bu paragraf boshidagi
* maqola nomidir.
*/
if (!beforeText) {
$titleElement = $(this);
return false;
}
});
if (
$titleElement &&
$titleElement.length
) {
/*
* Agar <a> <b> ichida bo‘lsa
* tashqi <b>ni olib tashlaymiz.
*/
var $removeElement =
$titleElement;
if (
$titleElement.parent().is(
'b, strong'
) &&
isTitle(
$titleElement
.parent()
.text()
)
) {
$removeElement =
$titleElement.parent();
}
var removedNode =
$removeElement[0];
var nextNode =
removedNode.nextSibling;
$removeElement.remove();
/*
* Keyingi:
*
* " — "
*
* qismini ham olib tashlash.
*/
if (
nextNode &&
nextNode.nodeType === 3
) {
nextNode.nodeValue =
nextNode.nodeValue.replace(
/^[\s\u00a0]*[—–-][\s\u00a0]*/,
''
);
}
}
/*
* 5. Qo‘shimcha himoya:
*
* Agar nom oddiy text node
* sifatida kelsa.
*/
var firstTextNode = null;
(function findFirstText(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
) {
findFirstText(child);
if (firstTextNode) {
return;
}
}
}
})($paragraph[0]);
if (firstTextNode) {
var text =
firstTextNode.nodeValue;
/*
* Regex uchun maxsus belgilarni
* himoyalash.
*/
function escapeRegex(value) {
return value.replace(
/[.*+?^${}()|[\]\\]/g,
'\\$&'
);
}
var titleRegex =
new RegExp(
'^[\\s\\u00a0]*(?:' +
escapeRegex(title) +
'|' +
escapeRegex(baseTitle) +
')[\\s\\u00a0]*' +
'[—–-]?' +
'[\\s\\u00a0]*',
'i'
);
firstTextNode.nodeValue =
text.replace(
titleRegex,
''
);
}
/*
* 6. Ichki havolalarni
* ZiyoSferaga moslash
*/
$paragraph
.find('a[href]')
.each(function () {
var href =
$(this).attr('href');
if (!href) {
return;
}
if (
href.indexOf('./') === 0
) {
var target =
href.substring(2);
try {
target =
decodeURIComponent(
target
);
} catch (e) {
/* o‘z holicha */
}
$(this).attr(
'href',
mw.util.getUrl(
target
)
);
}
});
/*
* 7. Asosiy maqola linki
*/
var articleUrl =
mw.util.getUrl(title);
var safeTitle = $('<div>')
.text(title)
.html();
/*
* 8. Natija
*
* Başkuyu — Turkiyaning ...
*
* Başkuyu linkli.
*/
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>';
$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>'
);
});
});
}
);