İstifadəçi:Toghrul R/common.js: Redaktələr arasındakı fərq

Silinən məzmun Əlavə edilmiş məzmun
k lokal
Redaktənin izahı yoxdur
Sətir 15:
// Infobox Converter
importScript('İstifadəçi:Toghrul Rahimli/infoboxConverter.js');
 
/////////////////////////////////
//Vikiləşdirici
////////////////////////////////
// <nowiki>
( function () {
 
var wmFullText = 'Vikiləşdirici səhifədəki bütün mətnə tətbiq olunacaq. Davam edilsin?',
wmTalkPage = 'Vikiləşdirici müzakirə səhifələrinə tam tətbiq edilə bilmir.';
window.wfPlugins = window.wfPlugins || [];
window.wfPluginsT = window.wfPluginsT || [];
 
 
// Function takes an input or text as an argument. If it is absent, it uses $( '#wpTextbox1' )
// as an input.
window.Wikify = function ( inputOrText ) {
'use strict';
 
var text, isInput, $input, caretPosition, textScroll,
txt = '',
hidden = [],
winScroll = document.documentElement.scrollTop,
$CodeMirrorVscrollbar = $( '.CodeMirror-vscrollbar' );
 
// Check what's in the first parameter
if ( typeof inputOrText === 'string' ) {
text = inputOrText;
} else {
isInput = ( inputOrText &&
( ( inputOrText.nodeType && inputOrText.value !== undefined ) || // node
( inputOrText.prop && inputOrText.prop( 'nodeType' ) ) // jQuery object
)
);
$input = $( isInput ? inputOrText : '#wpTextbox1' );
}
 
 
// FUNCTIONS
 
function r( r1, r2 ) {
txt = txt.replace( r1, r2 );
}
 
function hide( re ) {
r( re, function ( s ) {
return '\x01' + hidden.push( s ) + '\x02';
} );
}
 
function hideTag ( tag ) {
hide( new RegExp( '<' + tag + '( [^>]+)?>[\\s\\S]+?<\\/' + tag + '>', 'gi' ) );
}
 
function hideTemplates() {
hide( /\{\{([^{]\{?)+?\}\}/g );
var pos = 0,
stack = [],
tpl,
left,
right;
while ( true ) {
left = txt.indexOf( '{{', pos );
right = txt.indexOf( '}}', pos );
if ( left === -1 && right === -1 && !stack.length ) {
break;
}
if ( left !== -1 && ( left < right || right === -1 ) ) {
stack.push( left );
pos = left + 2;
} else {
left = stack.pop();
if ( typeof left === 'undefined' ) {
if ( right === -1 ) {
pos += 2;
continue;
} else {
left = 0;
}
}
if ( right === -1 ) {
right = txt.length;
}
right += 2;
tpl = txt.substring( left, right );
txt = txt.substring( 0, left ) +
'\x01' + hidden.push( tpl ) + '\x02' +
txt.substr( right );
pos = right - tpl.length;
}
}
}
function processLink( link, left, right ) {
left = left.replace( /[ _\u00A0]+/g, ' ' ).trim();
if ( left.match( /^(?:Kateqoriya|Şəkil) ?:/ ) ) {
return '[[' + left + '|' + right + ']]';
}
right = right.replace( / {2,}/g, ' ' ).trim();
var inLink = right.substr( 0, left.length );
var afterLink = right.substr( left.length );
var uniLeft = left.substr( 0, 1 ).toUpperCase() + left.substr( 1 );
var uniRight = ( right.substr( 0, 1 ).toUpperCase() + right.substr( 1 ) ).replace( /[_\u00A0]/g, ' ' );
if ( uniRight.indexOf( uniLeft ) === 0 && afterLink.match( /^[a-zа]*$/ ) ) {
return '[[' + inLink + ']]' + afterLink;
} else {
return '[[' + left + '|' + right + ']]';
}
}
 
function processText() {
var i,
u = '\u00A0'; // non-breaking space
if ( mw.config.get( 'wgNamespaceNumber' ) % 2 || mw.config.get( 'wgNamespaceNumber' ) === 4 ) { // is talk page
var sigs = txt.match( /\d\d:\d\d, \d\d? \S{3,8} 20\d\d \(UTC\)/g );
if ( sigs && sigs.length > 1 ) {
alert( wmTalkPage );
return;
}
}
 
hideTag( 'nowiki' );
hideTag( 'pre' );
hideTag( 'source' );
hideTag( 'syntaxhighlight' );
hideTag( 'templatedata' );
 
hideTag( 'code' );
hideTag( 'kbd' );
hideTag( 'tt' );
 
hideTag( 'graph' );
hideTag( 'hiero' );
hideTag( 'math' );
hideTag( 'timeline' );
hideTag( 'chem' );
hideTag( 'score' );
hideTag( 'categorytree' );
hideTag( 'inputbox' );
hideTag( 'mapframe' );
hideTag( 'maplink' );
 
r( /( |\n|\r)+\{\{(·|•|\*)\}\}/g, '{{$2}}' ); // before {{·/•/*}}, usually in templates
r( /\{\{\s*[Şş]ablon:([\s\S]+?)\}\}/g, '{{$1}}' );
r( /[\u00A0 ]+(\{\{\s*([Rr]ef-[a-z\-]+?|[Ee]n icon|[Cc]hecked|[Vv]|[Yy]oxlanılıb)\}\})/g, '$1' );
r( /<[\/\\]?(hr|br)( [^\/\\>]+?)?? *[\/\\]?>/gi, '<$1$2>' );
r( /<noinclude>\s*(\{\{[dD]ocpage\}\})\s*<\/noinclude>/g, '$1' );
 
r( /(\[\[[^\{\]|\n]+){{!}}([^\{\]|\n]+\]\])/g, '$1|$2' );
 
for ( i in window.wfPluginsT ) {
if ( window.wfPluginsT.hasOwnProperty( i ) ) {
window.wfPluginsT[i]( txt, r );
}
}
 
hideTemplates();
hide( /^[ \t].*/mg );
hide( /(https?|ftp|news|nntp|telnet|irc|gopher):\/\/[^\s\[\]<>"]+ ?/gi );
hide( /^#(redirect|İSTİQAMƏT(LƏNDİRMƏ)?)/i );
hideTag( 'gallery' );
 
 
r( / +(\n|\r)/g, '$1' ); // spaces at EOL
txt = '\n' + txt + '\n';
//BIRTH-DEATH DATES
r( /\{\{[Dd]oğum tarixi\|(\d*)\|\|\}\}/g, '$1' );
r( /\{\{[Dd]oğum tarixi və yaşı\|(\d+)\|(\d*)\|(\d*)\}\}/g, function (s, year, month, day) {
return month ? day + '.' + month + '.' + year : year;
});
r( /\{\{[Vv]əfat tarixi\|(\d*)\|\|\}\}/g, '$1' );
r( /\{\{[Vv]əfat tarixi\|(\d+)\|(\d*)\|(\d*)\}\}/g, function (s, year, month, day) {
return month ? day + '.' + month + '.' + year : year;
});
 
// LINKS
r( /(\[\[:?)(category|kateqoriya):( *)/ig, '$1Kateqoriya:' );
r( /(\[\[:?)(module|module):( *)/ig, '$1Module:' );
r( /(\[\[:?)(template|şablon):( *)/ig, '$1Şablon:' );
r( /(\[\[:?)(image|şəkil|file):( *)/ig, '$1Şəkil:' );
// Linked years, centuries and ranges
r( /(\(|\s)(\[\[[12]?\d{3}\]\])[\u00A0 ]?(-{1,3}|–|—) ?(\[\[[12]?\d{3}\]\])(\W)/g, '$1$2–$4$5' );
r( /(\(|\s)(\[\[[IVX]{1,5}\]\])[\u00A0 ]?(-{1,3}|–|—) ?(\[\[[IVX]{1,5}\]\])(\W)/g, '$1$2–$4$5' );
r( /\[\[(\d+)\]\]/g, '$1');
// Nice links
r( /(\[\[[^|[\]]*)[\u00AD\u200E\u200F]+([^\[\]]*\]\])/g, '$1$2' ); // Soft Hyphen & DirMark
r( /\[\[ *([^|[\]]+?) *\| *('''''|'''|'')([^'|[\]]*)\2 *]]/g, '$2[[$1|$3]]$2' ); // move fomatting out of link text
r( /\[\[ *([^|[\]]+?) *\| *«([^»|[\]]*)» *\]\]/g, '"[[$1|$2]]"' ); // move quotation marks out of link text
r( /\[\[ *([^|[\]]+?) *\| *„([^“|[\]]*)“ *\]\]/g, '"[[$1|$2]]"' );
r( /\[\[ *([^|[\]]+?) *\| *"([^"|[\]]*)" *\]\]/g, '"[[$1|$2]]"' );
r( /\[\[([^|[\]\n]+)\|([^|[\]\n]+)\]\]/g, processLink ); // link shortening
r( /\[\[ *([^|[\]]+)([^|\[\]()]+?) *\| *\1 *\]\]\2/g, '[[$1$2]]' ); // text repetition after link
r( /\[\[ *(?!Şəkil:|Kateqoriya:)([a-zA-Zа\u00A0-\u00FF %!\"$&'()*,\-—.\/0-9:;=?\\@\^_`’~]+) *\| *([^\|\[\]]+) *\]\]([a-zа]+)/g, '[[$1|$2$3]]' ); // "
hide( /\[\[[^\]|]+/g); // only link part
 
 
// TAGS
r( /<<(\S.+\S)>>/g, '"$1"' ); // << >>
r( /(«|»|“|”|„)/g, '"' );
r( /(su[pb]>)-(\d)/g, '$1−$2' ); // ->mənfi
r( /<(b|strong)>(.*?)<\/(b|strong)>/gi, "'''$2'''" );
r( /<(i|em)>(.*?)<\/(i|em)>/gi, "''$2''" );
r( /^<hr ?\/?>/gim, '----' );
r( /[\u00A0 \t]*<ref(?:\s+name="")?(\s|>)/gi, '<ref$1' );
r( /(\n== *[a-z\s\.:]+ *==\n+)<references *\/>/ig, '$1{' + '{İstinad siyahısı}}' );
r( /<references ?\/?>/g, '{{İstinad siyahısı}}' );
hide( /<[a-z][^>]*?>/gi);
 
hide( /^(\{\||\|\-).*/mg); // table/row def
hide( /(^\||^!|!!|\|\|) *[a-z]+=[^|]+\|(?!\|)/mgi); // cell style
hide( /\| +/g); // formatted cell
 
r( /[ \t\u00A0]{2,}/g, ' ' ); // double spaces
// Entities etc. → Unicode chars
if ( mw.config.get( 'wgNamespaceNumber' ) !== 10 ) {
r( /&(#x[0-9a-f]{2,4}|#[0-9]{3,4}|[0-9a-z]{2,8});/gi, function ( s ) {
var t = document.createElement( 'textarea' );
t.innerHTML = s;
var c = t.value;
if ( c.length === 1 && c.charCodeAt( 0 ) > 127 || s === '&#x20;' ) {
return c;
}
return s;
});
}
r( /\(tm\)/gi, '™' );
r( /\.\.\./g, '…' );
r( /(^|[^+])\+-(?!\+|-)/g, '$1±' );
r( /~=/g, '≈' );
r( /\^2(\D)/g, '²$1' );
r( /\^3(\D)/g, '³$1' );
r( /(\s)kv\.\s*(dm|sm|mm|mkm|nm|km|m)(\s)/g, '$1' + u + '$2²$3' );
r( /(\s)kub\.\s*(dm|sm|mm|mkm|nm|km|m)(\s)/g, '$1' + u + '$2³$3' );
r( /((?:^|[\s"])\d+(?:[\.,]\d+)?)\s*[xх]\s*(\d+(?:[\.,]\d+)?)\s*([m]{1,2}(?:[\s"\.,;?!]|$))/g, '$1×$2' + u + '$3' );
r( /\s+×\s+/g, u + '×' + u );
r( /№№/g, '№' );
 
// Headings
r( /^(=+)[ \t\f\v]*(.*?)[ \t\f\v]*=+$/gm, '$1 $2 $1' ); // add spaces inside
r( /([^\r\n])(\r?\n==.+==\r?\n)/g, '$1\n$2' ); // add empty line before
r( /(==.+==)[\r\n]{2,}(?!=)/g, '$1\n' ); // remove empty line after
r( /^== (?:(.+[^.])\.|(.+):) ==$/gm, '== $1$2 ==' );
r( /^== '''(?!.*'''.*''')(.+)''' ==$/gm, '== $1 ==' );
 
// Hyphens and en dashes to pretty dashes
r( /(\s)-{1,3} /g, '$1— ' ); // hyphen -> &mdash;
r( /(\d)--(\d)/g, '$1—$2' ); // -> &mdash;
r( /(\s)-(\d)/g, '$1−$2' ); // hyphen -> minus
 
// Year and century ranges
r( /(\(|\s)([IVX]{1,5})[\u00A0 ]?(-{1,3}|—) ?([IVX]{1,5})(?![\w\-])/g, '$1$2–$4' );
 
// Temperature
r( /([\s\d=≈≠≤≥<>—("'|])([+±−\-]?\d+?(?:[.,]\d+?)?)(([ °\^*]| [°\^*])(C|F))(?=[\s"').,;!?|\x01])/gm, '$1$2' + u + '°$5' ); // '
 
// Dot → comma in numbers
r( /(\s\d+)\.(\d+[\u00A0 ]*[%‰°×])/gi, '$1,$2' );
 
// Plugins
for ( i in window.wfPlugins ) {
if ( window.wfPlugins.hasOwnProperty( i ) ) {
window.wfPlugins[i]( txt, r );
}
}
 
function unhide( s, num ) {
return hidden[ num - 1 ];
}
while ( txt.match( /\x01\d+\x02/ ) ) {
r( /\x01(\d+)\x02/g, unhide );
}
 
txt = txt.substr( 1, txt.length - 2 ); // compensation for "txt = '\n' + txt + '\n';"
}
 
function processAllText() {
txt = $input ? $input.textSelection( 'getContents' ) : text;
processText();
if ( $input ) {
r( /^[\n\r]+/, '' );
// 2017 wikitext editor adds an empty line to the end with every text replacement
// Remove the following block when [[phab:T198010]] is fixed.
if ( window.ve && ve.init && ve.init.target && ve.init.target.active ) {
r( /[\n\r]+$/, '' );
}
$input.textSelection( 'setContents', txt );
if ( caretPosition ) {
$input.textSelection( 'setSelection', {
start: caretPosition[0] > txt.length ? txt.length : caretPosition[0]
} );
}
} else {
text = txt;
}
if ( window.auto_comment &&
window.insertSummary &&
!document.editform.wpSection.value
) {
window.insertSummary( 'vikiləşdirici' );
}
}
 
 
// MAIN CODE
 
if ( $input ) {
$input.focus();
caretPosition = $input.textSelection( 'getCaretPosition', { startAndEnd: true } );
if ( caretPosition ) {
textScroll = ( $CodeMirrorVscrollbar.length ? $CodeMirrorVscrollbar : $input )
.scrollTop();
if ( caretPosition[0] === caretPosition[1] ) {
processAllText();
} else {
txt = $input.textSelection( 'getSelection' );
processText();
// replaceSelection doesn't work with MediaWiki 1.30 in case this gadget is loaded
// from other wiki
$input.textSelection( 'encapsulateSelection', {
replace: true,
peri: txt
} );
// In CodeMirror, the selection isn't preserved, so we do it explicitly
$input.textSelection( 'setSelection', {
start: caretPosition[0],
end: caretPosition[0] + txt.length
} );
}
( $CodeMirrorVscrollbar.length ? $CodeMirrorVscrollbar : $input )
.scrollTop( textScroll );
// If something went wrong
} else if ( confirm( wmFullText ) ) {
processAllText();
}
} else {
processAllText();
return text;
}
 
// scroll back, for 2017 wikitext editor, IE, Opera
document.documentElement.scrollTop = winScroll;
//Qısa məzmun
var summaryValue = $('#wpSummary').val();
if (!/vikiləşdirmə/.test(summaryValue)) {
$('#wpSummary').val(summaryValue + '[[Vikipediya:Qadcetlər/Vikiləşdirici|vikiləşdirmə]]');
}
};
 
 
function registerWikificatorTool() {
registerTool( {
name: 'wikificator',
position: 100,
title: 'Vikiləşdirici',
label: 'Vikiləşdirici — mətnin avtomatik vikiləşdirilməsi',
callback: Wikify,
classic: {
icon: '//upload.wikimedia.org/wikipedia/commons/0/06/Wikify-toolbutton.png',
},
visual: {
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/4/41/Wikificator_VE_icon.svg/20px-Wikificator_VE_icon.svg.png',
modes: [ 'source' ],
addRightAway: true,
},
} );
}
 
if ( mw.config.get( 'wgServerName' ) === 'az.wikipedia.org' ) {
registerWikificatorTool();
} else {
$.when(
mw.loader.using( [ 'mediawiki.util', 'user.options' ] ),
$.getScript( 'https://az.wikipedia.org/w/index.php?title=MediaWiki:Gadget-registerTool.js&action=raw&ctype=text/javascript' )
).done( registerWikificatorTool );
}
 
}() );
// </nowiki>