۷٬۰۸۸
ویرایش
Nazarzadeh (بحث | مشارکتها) (صفحهای تازه حاوی «// <nowiki> // DO NOT REMOVE THIS LINE EVER /** * Wikipedia specific Persian text style improvement tools * Tests: [[مدیاویکی:Gad...» ایجاد کرد) |
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش |
||
خط ۸: | خط ۸: | ||
var persianWikiTools = (function () { | var persianWikiTools = (function () { | ||
'use strict'; | 'use strict'; | ||
var persianMonths = ["فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"]; | |||
//http://www.entitycode.com/ | |||
var htmlEntityCodes = { | var htmlEntityCodes = { | ||
"¡": "¡", "¢": "¢", "£": "£", "¤": "¤", | "¡": "¡", "¢": "¢", "£": "£", "¤": "¤", | ||
خط ۳۱: | خط ۳۲: | ||
"⌈": "⌈", "…": "…", "•": "•", "`": "`", | "⌈": "⌈", "…": "…", "•": "•", "`": "`", | ||
"±": "±", "´": "´", "·": "·", "½": "½", | "±": "±", "´": "´", "·": "·", "½": "½", | ||
"Ä": "Ä", "Ö": "Ö", | "Ä": "Ä", "Ö": "Ö", "Ü": "Ü", "’": "’", | ||
"‚": "‚", "‚": "‚", "”": "”", "„": "„", | "‚": "‚", "‚": "‚", "”": "”", "„": "„", | ||
"„": "„", | "„": "„", "‡": "‡", "÷": "÷", "≤": "≤", | ||
"≥": "≥", "≤": "≤", "≥": "≥" | "≥": "≥", "≤": "≤", "≥": "≥" | ||
}; // " , & < > | | }; // " , & < > | | ||
خط ۴۰: | خط ۴۱: | ||
arabicTagEnclosed: /\{\{(?:عربی|شروع عربی|آغاز عربی)\}\}([\s\S]*?)\{\{(?:پایان عربی)\}\}/g, | arabicTagEnclosed: /\{\{(?:عربی|شروع عربی|آغاز عربی)\}\}([\s\S]*?)\{\{(?:پایان عربی)\}\}/g, | ||
LtRTagEnclosed: /\{\{(?:چپ چین|چپچین)\}\}([\s\S]*?)\{\{(?:پایان چپچین|پایان چپ چین|پایان)\}\}/g, | LtRTagEnclosed: /\{\{(?:چپ چین|چپچین)\}\}([\s\S]*?)\{\{(?:پایان چپچین|پایان چپ چین|پایان)\}\}/g, | ||
argumentsBlacklist: /(?:accessdate|namespace|legend1start|image|تصویر|doi|style|شابک|عرض|bibcode|isbn|issn|pmid|arxiv|upright|upleft|padding|spacing|border|filename|نام پرونده)\s*\=\s*[^\|\}\]]*/gi, | argumentsBlacklist: /(?:accessdate|namespace|legend1start|image|تصویر|doi|style|شابک|عرض|bibcode|isbn|issn|pmid|arxiv|upright|upleft|padding|spacing|border|filename|نام پرونده|ایستاده)\s*\=\s*[^\|\}\]]*/gi, | ||
color: /#(?:[abcdef0-9]{8}|[abcdef0-9]{6}|[abcdef0-9]{3})/gi, | color: /#(?:[abcdef0-9]{8}|[abcdef0-9]{6}|[abcdef0-9]{3})/gi, | ||
//colorAsParameter: /\=\s*(?:[abcdef0-9]{8}|[abcdef0-9]{6}|[abcdef0-9]{3})(?:[\s\|\}]|$)/gi, | //colorAsParameter: /\=\s*(?:[abcdef0-9]{8}|[abcdef0-9]{6}|[abcdef0-9]{3})(?:[\s\|\}]|$)/gi, | ||
خط ۴۷: | خط ۴۸: | ||
diffLink: /\[\[(?:ویژه|Special):(?:تفاوت|Diff)\/[^\|\]]*/gi, | diffLink: /\[\[(?:ویژه|Special):(?:تفاوت|Diff)\/[^\|\]]*/gi, | ||
englishDate: /\d{1,2},? [a-z]{3,} \d{2,4}/gi, // 3, May 2013 | englishDate: /\d{1,2},? [a-z]{3,} \d{2,4}/gi, // 3, May 2013 | ||
fileNames: /(?:پرونده|File|تصویر|Image)\:.*?(?=\||\]|\n|$)/ | fileNames: /(?:پرونده|File|تصویر|Image)\:.*?(?=\||\]|\n|$)|=.*\.(?:flac|gif|jpeg|jpg|mid|mp3|mpeg|mpg|ogg|pdf|png|svg|wav|webm)$/mgi, // don't capture | after | ||
fileParameter: /\|\s*(image|تصویر)\s*\=\s*.*/g, | fileParameter: /\|\s*(image|تصویر)\s*\=\s*.*/g, | ||
ipSign: /\[\[ویژه:مشارکت\u200cها.*?\]\]/g, | ipSign: /\[\[ویژه:مشارکت\u200cها.*?\]\]/g, | ||
خط ۵۷: | خط ۵۸: | ||
insideQuote: /[^ا]".*?"/g, | insideQuote: /[^ا]".*?"/g, | ||
wikilinkTargets: /\[[^\[|\]]+/g, | wikilinkTargets: /\[[^\[|\]]+/g, | ||
nowikiTag:/<nowiki>.+?<\/nowiki>/g, | nowikiTag: /<nowiki>.+?<\/nowiki>/g, | ||
preTag:/<pre.*?>.*?<\/pre>/g, | preTag: /<pre.*?>.*?<\/pre>/g, | ||
insideHtmlComment: /<\!\-\-[\s\S]*?\-\->/g, | insideHtmlComment: /<\!\-\-[\s\S]*?\-\->/g, | ||
linksOnEnglishContext: /[a-z][\:\,\. ]*\[\[[\da-z\-\, ]*/gi, | linksOnEnglishContext: /[a-z][\:\,\. ]*\[\[[\da-z\-\, ]*/gi, | ||
خط ۶۸: | خط ۶۹: | ||
ref: /(?:<ref[^\/]*?>[\s\S]*?<\/ref>|<ref[^\/]*?\/>)/g, // inside <ref></ref> and <ref/> | ref: /(?:<ref[^\/]*?>[\s\S]*?<\/ref>|<ref[^\/]*?\/>)/g, // inside <ref></ref> and <ref/> | ||
refname: /\<ref name\=.*?\>/g, | refname: /\<ref name\=.*?\>/g, | ||
citation:/\{\{\s*(?:[Cc]it|یادکرد).*?[_\s]*(?:\{\{.*?\}\}|[^\}])*\}\}/g, | citation: /\{\{\s*(?:[Cc]it|یادکرد).*?[_\s]*(?:\{\{.*?\}\}|[^\}])*\}\}/g, | ||
signatures: /\[\[(?:کاربر|User|بحث[ _]کاربر|User[_ ]talk)\:.*?\]\]/gi, | signatures: /\[\[(?:کاربر|User|بحث[ _]کاربر|User[_ ]talk)\:.*?\]\]/gi, | ||
sourceTag: /(<source.*?>[\s\S]*?<\/source>|<syntaxhighlight.*?>[\s\S]*?<\/syntaxhighlight>|<code.*?>[\s\S]*?<\/code>|<timeline.*?>[\s\S]*?<\/timeline>)/g, | sourceTag: /(<source.*?>[\s\S]*?<\/source>|<syntaxhighlight.*?>[\s\S]*?<\/syntaxhighlight>|<code.*?>[\s\S]*?<\/code>|<timeline.*?>[\s\S]*?<\/timeline>)/g, | ||
tagNames: /<\/?[a-zA-Z\d]*/g, | tagNames: /<\/?[a-zA-Z\d]*/g, | ||
graphTemplate: /(?:\<div[^\>]+>)?\{\{[ \_]*(?:الگو|Template)?(?:[Gg]raph\:?[^\|\}]+).*?[_\s\n]*(?:\{\{.*?\}\}|[^\}])*\}\}(?:\<\/div\>)/g, | |||
templateEnglishName: /(الگو|Template):[a-z][a-z\d\-\+_]+/gi, | templateEnglishName: /(الگو|Template):[a-z][a-z\d\-\+_]+/gi, | ||
templateWithEnglishName: /\{\{[ \_]* | templateWithEnglishName: /\{\{[ \_]*(?:الگو|Template)?[\x00-\x7a~]*\|.*?\}\}/gi, | ||
templateParameterName: /\|\s*(?=[a-z_]*\d)[a-z_\d]*\s*\=/gi, | templateParameterName: /\|\s*(?=[a-z_]*\d)[a-z_\d]*\s*\=/gi, | ||
globalExceptionTag: /(<nowiki>.+?<\/nowiki>|<!--[\s]*ابر[\s]*-->.+?<!--[\s]*\/[\s]*ابر[\s]*-->|\{\{استثنای ابرابزار\|[\s\S]*?\}\})/gi, | globalExceptionTag: /(<nowiki>.+?<\/nowiki>|<!--[\s]*ابر[\s]*-->.+?<!--[\s]*\/[\s]*ابر[\s]*-->|\{\{استثنای ابرابزار\|[\s\S]*?\}\})/gi, | ||
خط ۷۹: | خط ۸۱: | ||
boxVar: /([a-zA-Z][۱۲۳۴۵۶۷۸۹۰]+) *\=/g, | boxVar: /([a-zA-Z][۱۲۳۴۵۶۷۸۹۰]+) *\=/g, | ||
url: /\/\/.*?(?=[\s\n\|\}\]<]|$)/gi, // بدون https?: هم ممکن است | url: /\/\/.*?(?=[\s\n\|\}\]<]|$)/gi, // بدون https?: هم ممکن است | ||
urlArchive: /\/\/web\.archive\.org[^\|\}\n\<\>]+/gi, | |||
mediawikiFunctions: /\{\{\#(?:\{\{.*?\}\}|[^\}])*\}\}/gi, | mediawikiFunctions: /\{\{\#(?:\{\{.*?\}\}|[^\}])*\}\}/gi, | ||
articleTitleParts: new RegExp('\\s' + mw.config.get('wgTitle').split(' ').join('\\s|\\s') + '\\s', 'g'), | articleTitleParts: new RegExp('\\s' + mw.config.get('wgTitle').split(' ').join('\\s|\\s') + '\\s', 'g'), | ||
catgories:/\[\[(?:رده|[Cc]ategory)\:[^\]]+\]\]/gi | catgories: /\[\[(?:رده|[Cc]ategory)\:[^\]]+\]\]/gi | ||
}; | }; | ||
function escapeRE( s ) { | function escapeRE(s) { | ||
return s.replace( /([$()*+\-.?[\\\]^{|}])/g, '\\$1' ); | return s.replace(/([$()*+\-.?[\\\]^{|}])/g, '\\$1'); | ||
} | } | ||
خط ۹۱: | خط ۹۴: | ||
return x.from - y.from; | return x.from - y.from; | ||
} | } | ||
function removeCheckDict(text){ | function removeCheckDict(text) { | ||
// رفع مشکل [[Special:Permalink/25174868#متن هایلایتشده]] | // رفع مشکل [[Special:Permalink/25174868#متن هایلایتشده]] | ||
var otext = '' | var otext = '' | ||
while (otext!=text){ | while (otext != text) { | ||
otext = text | otext = text | ||
text=text.replace(/\<span[^>]+CheckDictation\-marked[^>]+\>([^<>]+)\<\/span\>/g, '$1') | text = text.replace(/\<span[^>]+CheckDictation\-marked[^>]+\>([^<>]+)\<\/span\>/g, '$1') | ||
} | } | ||
return text | return text | ||
خط ۱۵۰: | خط ۱۵۳: | ||
text, | text, | ||
persianTools.toStandardPersianCharacters, | persianTools.toStandardPersianCharacters, | ||
[patterns.globalExceptionTag, patterns.otherLanguagesInline, patterns.arabicTagEnclosed, patterns.fileNames, patterns.signatures, patterns.url] | [patterns.globalExceptionTag, patterns.otherLanguagesInline, patterns.arabicTagEnclosed, patterns.fileNames, patterns.signatures, patterns.url, patterns.fileParameter] | ||
); | ); | ||
} | } | ||
خط ۱۶۰: | خط ۱۶۳: | ||
} | } | ||
function autoFormatCleanReferences ( str ) { | function autoFormatCleanReferences(str) { | ||
// تمیزکاری autoFormater.js > cleanReferences | // تمیزکاری autoFormater.js > cleanReferences | ||
str = str.replace( | str = str.replace( | ||
خط ۱۶۶: | خط ۱۶۹: | ||
'<references$1/>' | '<references$1/>' | ||
); | ); | ||
if (mw.config.get('wgNamespaceNumber') === 0){ | if (mw.config.get('wgNamespaceNumber') === 0) { | ||
//ویکیپدیای فارسی منبع برای ارجاع نیست | //ویکیپدیای فارسی منبع برای ارجاع نیست | ||
str = str.replace(/\<ref[^>]*\>\[?(?:https?:)?\/\/fa.(?:m\.)?wikipedia.org\/[^\<\n\}\]\[]+\]?\<\/ref\>/gi, '') | str = str.replace(/\<ref[^>]*\>\[?(?:https?:)?\/\/fa.(?:m\.)?wikipedia.org\/[^\<\n\}\]\[]+\]?\<\/ref\>/gi, '') | ||
}; | }; | ||
str = str.replace( /<\s*references\s*(\s\b[^<\/>]*?)?\s*>/gi, '<references$1>' ); | str = str.replace(/<\s*references\s*(\s\b[^<\/>]*?)?\s*>/gi, '<references$1>'); | ||
str = str.replace( /<\s*\/\s*references\s*>/gi, '<\/references>' ); | str = str.replace(/<\s*\/\s*references\s*>/gi, '<\/references>'); | ||
var re = /(<references[^<\/>]*)>/g, m; | var re = /(<references[^<\/>]*)>/g, m; | ||
while ( m = re.exec( str ) ) { | while (m = re.exec(str)) { | ||
if ( str.indexOf( '<\/references>', m.index ) < 0 ) { | if (str.indexOf('<\/references>', m.index) < 0) { | ||
str = str.slice( 0, m.index ) + m[1] + '/>' + str.slice( m.index + m[0].length ); | str = str.slice(0, m.index) + m[1] + '/>' + str.slice(m.index + m[0].length); | ||
} | } | ||
} | } | ||
str = str.replace( /< *ref\s*(\s\b[^<>]*?)\s*(?:\/+|>\s*<\s*\/+\s*ref) *>/gi, '<ref$1/>' ); | str = str.replace(/< *ref\s*(\s\b[^<>]*?)\s*(?:\/+|>\s*<\s*\/+\s*ref) *>/gi, '<ref$1/>'); | ||
/* remove line breaks with assays only the top of the article */ | /* remove line breaks with assays only the top of the article */ | ||
var i = str.indexOf( '<references' ), | var i = str.indexOf('<references'), | ||
slice; | slice; | ||
if ( i > 0 ) { | if (i > 0) { | ||
slice = str.slice( i ); | slice = str.slice(i); | ||
slice = slice.replace( /< *ref\s*(\s\b[^<\/>]*?)?\s*>[\t ]*/gi, '<ref$1>' ); | slice = slice.replace(/< *ref\s*(\s\b[^<\/>]*?)?\s*>[\t ]*/gi, '<ref$1>'); | ||
slice = slice.replace( /(?:(\n[\t ]*)|[\t ]*)<\s*\/+\s*ref\s*>/gi, '$1<\/ref>' ); | slice = slice.replace(/(?:(\n[\t ]*)|[\t ]*)<\s*\/+\s*ref\s*>/gi, '$1<\/ref>'); | ||
str = str.slice( 0, i ); | str = str.slice(0, i); | ||
} | } | ||
str = str.replace( /< *ref\s*(\s\b[^<\/>]*?)?\s*>\s*/gi, '<ref$1>' ); | str = str.replace(/< *ref\s*(\s\b[^<\/>]*?)?\s*>\s*/gi, '<ref$1>'); | ||
str = str.replace( /\s*<\s*\/+\s*ref\s*>/gi, '<\/ref>' ); | str = str.replace(/\s*<\s*\/+\s*ref\s*>/gi, '<\/ref>'); | ||
if ( slice ) { | if (slice) { | ||
str += slice; | str += slice; | ||
} | } | ||
/* Space between the end of block and remove <ref> or two <ref> */ | /* Space between the end of block and remove <ref> or two <ref> */ | ||
str = str.replace( /([!,.;?]|<ref\b[^<>]*(?:\/|>[^<>]*<\/ref)>) +(?=<ref[ >])/gi, '$1' ); | str = str.replace(/([!,.;?]|<ref\b[^<>]*(?:\/|>[^<>]*<\/ref)>) +(?=<ref[ >])/gi, '$1'); | ||
/* Two identical punctuation before and cut after a <ref> on one */ | /* Two identical punctuation before and cut after a <ref> on one */ | ||
str = str.replace( /([!,.:;?])(<ref\b[^<>]*(?:\/|>[^<>]*<\/ref)>)\1/gi, '$1$2' ); | str = str.replace(/([!,.:;?])(<ref\b[^<>]*(?:\/|>[^<>]*<\/ref)>)\1/gi, '$1$2'); | ||
/* ref inside small */ | /* ref inside small */ | ||
return str.replace( /\<small\> *(\<ref[^\<]+\<\/ref\>)<\/small\>/gi, '$1' ); | return str.replace(/\<small\> *(\<ref[^\<]+\<\/ref\>)<\/small\>/gi, '$1'); | ||
} | } | ||
function autoFormatCleanTags(str) { | function autoFormatCleanTags(str) { | ||
str = str.replace( /(<\/?s)trike\b/gi, '$1' ); | str = str.replace(/(<\/?s)trike\b/gi, '$1'); | ||
str = str.replace( | str = str.replace( | ||
/\<u\>([^\<]+)\<\/u\>/gi, | /\<u\>([^\<]+)\<\/u\>/gi, | ||
خط ۲۳۶: | خط ۲۳۹: | ||
); | ); | ||
/* Remove inline elements with no attributes */ | /* Remove inline elements with no attributes */ | ||
while ( /<(font|span)\s*>\s*(?:<(?!\1)|[^<])*?\s*<\/\1[^<>]*>/i.test( str ) ) { | while (/<(font|span)\s*>\s*(?:<(?!\1)|[^<])*?\s*<\/\1[^<>]*>/i.test(str)) { | ||
str = str.replace( /<(font|span)\s*>[ \n]*((?:<(?!\1)|[^<])*?)[ \n]*<\/\1[^<>]*>/gi, '$2' ); | str = str.replace(/<(font|span)\s*>[ \n]*((?:<(?!\1)|[^<])*?)[ \n]*<\/\1[^<>]*>/gi, '$2'); | ||
} | } | ||
str = str.replace( | str = str.replace( | ||
خط ۲۶۲: | خط ۲۶۵: | ||
/* Verschiedenste Formen von HTML-Zeilenumbrüchen durch einheitliche ersetzen */ | /* Verschiedenste Formen von HTML-Zeilenumbrüchen durch einheitliche ersetzen */ | ||
str = str.replace( /<(?:[\s\/\\]*br\b)+\s*(\s\w[^<>]*?)?[\s.\/\\]*>/gi, '<br$1/>' ); | str = str.replace(/<(?:[\s\/\\]*br\b)+\s*(\s\w[^<>]*?)?[\s.\/\\]*>/gi, '<br$1/>'); | ||
/* Unnötige HTML-Zeilenumbrüche entfernen, wenn sowieso ein Absatz folgt */ | /* Unnötige HTML-Zeilenumbrüche entfernen, wenn sowieso ein Absatz folgt */ | ||
str = str.replace( / *(?:{{سخ}}|<br \/>)(?=[\r\n][\n#*:;\|}\]])/gi, '' ); | str = str.replace(/ *(?:{{سخ}}|<br \/>)(?=[\r\n][\n#*:;\|}\]])/gi, ''); | ||
str = str.replace( | str = str.replace( | ||
/<(ref|small|su[bp])\b\s*(\s\w[^<>]*?)?\s*><small\s*>([^<>]*)<\/small\s*><\/\1\s*>/gi, | /<(ref|small|su[bp])\b\s*(\s\w[^<>]*?)?\s*><small\s*>([^<>]*)<\/small\s*><\/\1\s*>/gi, | ||
خط ۲۸۲: | خط ۲۸۵: | ||
function autoFormatCleanDuplicateLinks(str) { | function autoFormatCleanDuplicateLinks(str) { | ||
/* Exclude files and infoboxes from the start of the article */ | /* Exclude files and infoboxes from the start of the article */ | ||
var m = /^(?:\s*\[\[\w+:(?:\[\[[^\n\]]*\]\]|[^\n\]])*\]\])*(?:\s*\{\{(?:\{\{[^}]*\}\}|[^}])*\}\})+/.exec( str ), | var m = /^(?:\s*\[\[\w+:(?:\[\[[^\n\]]*\]\]|[^\n\]])*\]\])*(?:\s*\{\{(?:\{\{[^}]*\}\}|[^}])*\}\})+/.exec(str), | ||
start = m ? m[0].length : 0, | start = m ? m[0].length : 0, | ||
found = [], | found = [], | ||
خط ۲۸۹: | خط ۲۹۲: | ||
var re = /\[\[ *([۱۲][۱۲۳۴۵۶۷۸۹۰]{3}|[۱۲][۱۲۳۴۵۶۷۸۹۰]{3} \((میلادی|قمری)\)) *\]\]/g; | var re = /\[\[ *([۱۲][۱۲۳۴۵۶۷۸۹۰]{3}|[۱۲][۱۲۳۴۵۶۷۸۹۰]{3} \((میلادی|قمری)\)) *\]\]/g; | ||
/* In each case the first discovery of a year noted entlinken thereafter */ | /* In each case the first discovery of a year noted entlinken thereafter */ | ||
while ( m = re.exec( str ) ) { | while (m = re.exec(str)) { | ||
if ( m.index >= start ) { | if (m.index >= start) { | ||
found[m[1]] ? a.push( m ) : found[m[1]] = true; | found[m[1]] ? a.push(m) : found[m[1]] = true; | ||
} | } | ||
} | } | ||
var r = '', | var r = '', | ||
p = 0; | p = 0; | ||
for ( var i = 0; i < a.length; i++ ) { | for (var i = 0; i < a.length; i++) { | ||
r += str.slice( p, a[i].index ) + a[i][1]; | r += str.slice(p, a[i].index) + a[i][1]; | ||
p = a[i].index + a[i][0].length; | p = a[i].index + a[i][0].length; | ||
} | } | ||
return p ? r + str.slice( p ) : str; | return p ? r + str.slice(p) : str; | ||
} | } | ||
function autoFormatCleanDates(str){ | function autoFormatCleanDates(str) { | ||
var months = ["ژانویه", "فوریه", "مارس", "آوریل", "مه", "ژوئن", "ژوئیه", "اوت", "سپتامبر", "اکتبر", "نوامبر", "دسامبر" | var months = ["ژانویه", "فوریه", "مارس", "آوریل", "مه", "ژوئن", "ژوئیه", "اوت", "سپتامبر", "اکتبر", "نوامبر", "دسامبر", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"].concat(persianMonths); | ||
/* Add missing space between day and month */ | /* Add missing space between day and month */ | ||
str = str.replace( new RegExp( '([\\s!\'(>|„](?:3[01]|[12]\\d|0?[1-9])\\.?)(?=(?:' + | str = str.replace(new RegExp('([\\s!\'(>|„](?:3[01]|[12]\\d|0?[1-9])\\.?)(?=(?:' + | ||
months.join( '|' ) + ')\\b)', 'g' ), '$1 ' ); | months.join('|') + ')\\b)', 'g'), '$1 '); | ||
/* No non-breaking space between month and year */ | /* No non-breaking space between month and year */ | ||
str = str.replace( new RegExp( '(\\b(?:3[01]|[12]\\d|0?[1-9])\\.?(?:[\\s\\xA0]| )+(?:' + | str = str.replace(new RegExp('(\\b(?:3[01]|[12]\\d|0?[1-9])\\.?(?:[\\s\\xA0]| )+(?:' + | ||
months.join( '|' ) + '))(?:\xA0| )(?=[12]\\d{3}\\b)', 'g' ), '$1 ' ); | months.join('|') + '))(?:\xA0| )(?=[12]\\d{3}\\b)', 'g'), '$1 '); | ||
/* Missverständliches deutsches Datumsformat durch Langform ersetzen */ | /* Missverständliches deutsches Datumsformat durch Langform ersetzen */ | ||
var separator= ' '; | var separator = ' '; | ||
str = str.replace( | str = str.replace( | ||
/([\s'(>„])(3[01]|[12]\d|0?[1-9])\. *(1[012]|0?[1-9])\. *(?=[12]\d{3}[!,.:;?]?[\s')<\]“])/g, | /([\s'(>„])(3[01]|[12]\d|0?[1-9])\. *(1[012]|0?[1-9])\. *(?=[12]\d{3}[!,.:;?]?[\s')<\]“])/g, | ||
function( $0, $1, $2, $3 ) { | function ($0, $1, $2, $3) { | ||
return $1 + ( $2 | 0 ) + separator + months[$3 | 0] + ' '; | return $1 + ($2 | 0) + separator + months[$3 | 0] + ' '; | ||
} | } | ||
); | ); | ||
// عدد فارسی | // عدد فارسی | ||
str = str.replace( new RegExp( '([\\s!\'(>|„](?:۳[۰۱]|[۱۲][۱۲۳۴۵۶۷۸۹]|۰?[۱۲۳۴۵۶۷۸۹])\\.?)(?=(?:' + | str = str.replace(new RegExp('([\\s!\'(>|„](?:۳[۰۱]|[۱۲][۱۲۳۴۵۶۷۸۹]|۰?[۱۲۳۴۵۶۷۸۹])\\.?)(?=(?:' + | ||
months.join( '|' ) + ')[\\s\')<\\]»}|])', 'g' ), '$1 ' ); | months.join('|') + ')[\\s\')<\\]»}|])', 'g'), '$1 '); | ||
/* No non-breaking space between month and year */ | /* No non-breaking space between month and year */ | ||
str = str.replace( new RegExp( '([\\s\'(>«](?:۳[۰۱]|[۱۲][۱۲۳۴۵۶۷۸۹]|۰?[۱۲۳۴۵۶۷۸۹])\\.?(?:[\\s\\xA0]| )+(?:' + | str = str.replace(new RegExp('([\\s\'(>«](?:۳[۰۱]|[۱۲][۱۲۳۴۵۶۷۸۹]|۰?[۱۲۳۴۵۶۷۸۹])\\.?(?:[\\s\\xA0]| )+(?:' + | ||
months.join( '|' ) + '))(?:\xA0| )(?=[۱۲][۱۲۳۴۵۶۷۸۹]{3}[\\s\')<\\]»}|])', 'g' ), '$1 ' ); | months.join('|') + '))(?:\xA0| )(?=[۱۲][۱۲۳۴۵۶۷۸۹]{3}[\\s\')<\\]»}|])', 'g'), '$1 '); | ||
/* Missverständliches deutsches Datumsformat durch Langform ersetzen */ | /* Missverständliches deutsches Datumsformat durch Langform ersetzen */ | ||
var separator= ' '; | var separator = ' '; | ||
str = str.replace( | str = str.replace( | ||
/([\s'(>«])(۳[۰۱]|[۱۲][۱۲۳۴۵۶۷۸۹]|۰?[۱۲۳۴۵۶۷۸۹])\. *(۱[۰۱۲]|۰?[۱۲۳۴۵۶۷۸۹])\. *(?=[۱۲][۱۲۳۴۵۶۷۸۹]{3}[!,.:;?]?[\s')<\]»}|])/g, | /([\s'(>«])(۳[۰۱]|[۱۲][۱۲۳۴۵۶۷۸۹]|۰?[۱۲۳۴۵۶۷۸۹])\. *(۱[۰۱۲]|۰?[۱۲۳۴۵۶۷۸۹])\. *(?=[۱۲][۱۲۳۴۵۶۷۸۹]{3}[!,.:;?]?[\s')<\]»}|])/g, | ||
function( $0, $1, $2, $3 ) { | function ($0, $1, $2, $3) { | ||
return $1 + ( $2 | 0 ) + separator + months[$3 | 0] + ' '; | return $1 + ($2 | 0) + separator + months[$3 | 0] + ' '; | ||
} | } | ||
); | ); | ||
return str | return str | ||
} | |||
function quotationReplace(line) { | |||
[ | |||
['“', '”'], ['”', '“'], ['‘', '’'], ['’', '‘'], ['‚', '’'], ['„', '”'], ['\\<\\<', '\\>\\>'], ['\\(\\(', '\\)\\)'] | |||
].forEach(function(qs) { | |||
line = line.replace(new RegExp( | |||
'(^|[' + persianTools.persianCharacters + '\\:>،»؛\\s\\n\\}\\]\\.]+)' | |||
+ qs[0] + '((?:\\[\\[|).*?[' + persianTools.persianCharacters + '\\n]+?(?:\\]\\]|\\.|\\<|\\:|\\{|\\[|…|))' + qs[1] | |||
+ '([' + persianTools.persianCharacters + '،«؛\\s\\n\\.\\[\\{]|$)', 'g' | |||
), '$1«$2»$3'); | |||
}); | |||
return line; | |||
} | } | ||
خط ۳۵۲: | خط ۳۶۷: | ||
); | ); | ||
// if some of quote marks are remained from conversion, something might wrong, revert | // if some of quote marks are remained from conversion, something might wrong, revert | ||
var testline=line.replace(/(?:<ref[^\/]*?>[\s\S]*?<\/ref>|<ref[^\/]*?\/>)/g,'') | var testline = line.replace(/(?:<ref[^\/]*?>[\s\S]*?<\/ref>|<ref[^\/]*?\/>)/g, '') | ||
if (testline.match(/"/g)) { | if (testline.match(/"/g)) { | ||
خط ۳۵۹: | خط ۳۷۴: | ||
} | } | ||
// رفع مشکل استفاده از ـً به جای گیومه لاتین در متن فارسی | // رفع مشکل استفاده از ـً به جای گیومه لاتین در متن فارسی | ||
line=line.replace(new RegExp('ا\\"([ ]*[' +persianTools.persianCharacters + '])', 'g'), 'اً$1') | line = line.replace(new RegExp('ا\\"([ ]*[' + persianTools.persianCharacters + '])', 'g'), 'اً$1') | ||
line=line.replace(new RegExp('ا\\”([ ]*[' +persianTools.persianCharacters + '])', 'g'), 'اً$1') | line = line.replace(new RegExp('ا\\”([ ]*[' + persianTools.persianCharacters + '])', 'g'), 'اً$1') | ||
line = quotationReplace(line); | |||
line = | |||
result.push(line); | result.push(line); | ||
} | } | ||
خط ۴۰۹: | خط ۳۸۵: | ||
* @param {string} text محتوا | * @param {string} text محتوا | ||
*/ | */ | ||
function addColumnToRefTemplate(text) { | |||
var refTemplate = /\{\{پانویس([^\}\{]+)?\}\}/i.exec(text), needChange = false; | |||
if (refTemplate) { | if (refTemplate) { | ||
if ((text.match(/<ref/gi) || []).length >= 6) { | if ((text.match(/<ref/gi) || []).length >= 6) { | ||
خط ۴۲۷: | خط ۴۰۳: | ||
} | } | ||
} | } | ||
}else{ | } else { | ||
if ((mw.config.get('wgNamespaceNumber') === 0 && mw.config.get("wgEditMessage")==='editing')||mw.config.get('wgPageName') ==="ویکیپدیا:ویکیپروژه_ابزارها/آزمایش_واحد") { | if ((mw.config.get('wgNamespaceNumber') === 0 && mw.config.get("wgEditMessage") === 'editing') || mw.config.get('wgPageName') === "ویکیپدیا:ویکیپروژه_ابزارها/آزمایش_واحد") { | ||
if ((text.match(/<ref/gi) || []).length > 0 && | if ((text.match(/<ref/gi) || []).length > 0 && /\{\{پانویس([^\}\{]+)?\}\}/i.exec(text) != null) { | ||
var text2 = text.replace ('== منابع ==','== منابع ==\n{{پانویس}}') | var text2 = text.replace('== منابع ==', '== منابع ==\n{{پانویس}}') | ||
if (text2==text){ | if (text2 == text) { | ||
text2 = text.replace ('== پانویس ==','== پانویس ==\n{{پانویس}}') | text2 = text.replace('== پانویس ==', '== پانویس ==\n{{پانویس}}') | ||
} | } | ||
if (text2==text){ | if (text2 == text) { | ||
text2 = text.replace ('[[رده:','== منابع ==\n{{پانویس}}\n\n[[رده:') | text2 = text.replace('[[رده:', '== منابع ==\n{{پانویس}}\n\n[[رده:') | ||
} | } | ||
if (text2==text){ | if (text2 == text) { | ||
text2 = text + '\n== منابع ==\n{{پانویس}}' | text2 = text + '\n== منابع ==\n{{پانویس}}' | ||
} | } | ||
text=text2 | text = text2 | ||
} | } | ||
} | } | ||
} | } | ||
return text; | return text; | ||
} | } | ||
/** | /** | ||
* اصلاح پیوندها | * اصلاح پیوندها | ||
خط ۴۵۷: | خط ۴۳۴: | ||
// حذف پیوند سال و روز ماه | // حذف پیوند سال و روز ماه | ||
text = text.replace(/\[{2}([۰-۹]+|[۰-۹]+ [\)\(\u0621-\u0655\u067E\u0686\u0698\u06AF\u06A9\u0643\u06AA\uFED9\uFEDA\u06CC\uFEF1\uFEF2]+)(?:\|([^\]\|\[]+))?\]{2}/g, function (match, p1, p2) { | text = text.replace(/\[{2}([۰-۹]+|[۰-۹]+ [\)\(\u0621-\u0655\u067E\u0686\u0698\u06AF\u06A9\u0643\u06AA\uFED9\uFEDA\u06CC\uFEF1\uFEF2]+)(?:\|([^\]\|\[]+))?\]{2}/g, function (match, p1, p2) { | ||
// اگر فقط سال پیوند شدهباشد یا به شکل [[سال|همان سال]] باشد فقط سال را میگرداند. | |||
var calendar_type = / \((میلادی|قمری|خورشیدی|شمسی|پیش از میلاد|قبل از میلاد)\)/g; | |||
if (p1 !== p2 && p1.replace(calendar_type, '') === p2) { | |||
return p2; | |||
}//[[Special:Permalink/19908981#حذف پیوند تاریخها]] | |||
if (p2 === undefined || p1 === p2) { | |||
// اگر پیوند به روز و ماه بود، برای جلوگیری از اشتباه و تداخل، بررسی میشوند که حتما یکی از ماهها داخل رشته باشد. | |||
if (p1.indexOf(" ") > -1) { | |||
var | |||
months = [ | |||
"محرم", "صفر", "ربیعالاول", "ربیعالثانی", "جمادیالاول", "جمادیالثانی", "رجب", "شعبان", "رمضان", "شوال", "ذیقعده", "ذیحجه" | |||
].concat(persianMonths), | |||
i; | |||
for (i = months.length - 1; i >= 0; i--) { | |||
if (p1.indexOf(months[i]) > -1) { | |||
return p1.replace(calendar_type, ''); | |||
} | |||
} | } | ||
return "[[" + p1 + "]]"; | |||
} | } | ||
return | return p1; | ||
} | } | ||
// اگر متن جایگزین پیوند مخالف پیوند سال بود، متن جایگزین را برمیگرداند. | |||
return p2; | |||
}); | |||
return text; | |||
} | } | ||
function wikiPunctuation(text) { | function wikiPunctuation(text) { | ||
text = autoFormatCleanReferences (text) | text = autoFormatCleanReferences(text) | ||
text = autoFormatCleanTags(text) | text = autoFormatCleanTags(text) | ||
text = autoFormatCleanDuplicateLinks(text) | text = autoFormatCleanDuplicateLinks(text) | ||
خط ۴۹۶: | خط ۴۷۴: | ||
[patterns.ref] | [patterns.ref] | ||
); | ); | ||
if (mw.config.get('wgNamespaceNumber') === 0){ | if (mw.config.get('wgNamespaceNumber') === 0) { | ||
var old_text=text.replace(/\=\=/g, '') | var old_text = text.replace(/\=\=/g, '') | ||
if (old_text==text){//در صورتی که در مقاله بخشبندی وجود نداشته باشد | if (old_text == text) {//در صورتی که در مقاله بخشبندی وجود نداشته باشد | ||
text=text.replace(/(\n\{\{سخ\}\}|\n\n)(\s|_|)\'\'\'(.*?)\'\'\'(\s|_|)(\{\{سخ\}\}|\n)([\n\#\*])/g, '\n\n== $3 ==\n$6') | text = text.replace(/(\n\{\{سخ\}\}|\n\n)(\s|_|)\'\'\'(.*?)\'\'\'(\s|_|)(\{\{سخ\}\}|\n)([\n\#\*])/g, '\n\n== $3 ==\n$6') | ||
} | } | ||
} | } | ||
خط ۵۲۸: | خط ۵۰۶: | ||
}, | }, | ||
[patterns.globalExceptionTag, patterns.mathTag, patterns.fileNames, patterns.url, patterns.wikilinkTargets, | [patterns.globalExceptionTag, patterns.mathTag, patterns.fileNames, patterns.url, patterns.wikilinkTargets, | ||
patterns.galleryTag, patterns.sourceTag, patterns.translatedUrl, patterns.parenthesesHa] | |||
) | ) | ||
.replace(/\u00A0/g, ' ') // convert implicit nbsp to space, probably is being added by some bug on ContentTranslation | .replace(/\u00A0/g, ' ') // convert implicit nbsp to space, probably is being added by some bug on ContentTranslation | ||
خط ۵۳۴: | خط ۵۱۲: | ||
.replace(new RegExp('([' + persianTools.persianCharacters + '\]])٬', 'g'), '$1،') | .replace(new RegExp('([' + persianTools.persianCharacters + '\]])٬', 'g'), '$1،') | ||
.replace(new RegExp('([' + persianTools.persianCharacters + '])(\]\]|»|)[ ]*[,]', 'g'), '$1$2، ') | .replace(new RegExp('([' + persianTools.persianCharacters + '])(\]\]|»|)[ ]*[,]', 'g'), '$1$2، ') | ||
.replace(/\[\[([^\|\]]+)\|(\'{2,3})\1'{2,3}\]\]/g,'$2[[$1]]$2') // for [[foo|'''foo''']] > '''[[foo]]''' | .replace(/\[\[([^\|\]]+)\|(\'{2,3})\1'{2,3}\]\]/g, '$2[[$1]]$2') // for [[foo|'''foo''']] > '''[[foo]]''' | ||
.replace(new RegExp('\\[\\[(' + escapeRE(mw.config.get('wgPageName')) + ')\\]\\]', 'g'), '$1') // پیوندزدایی از خود صفحه | .replace(new RegExp('\\[\\[(' + escapeRE(mw.config.get('wgPageName')) + ')\\]\\]', 'g'), '$1') // پیوندزدایی از خود صفحه | ||
//برگرفته از https:// | //برگرفته از https://checkwiki.toolforge.org/cgi-bin/checkwikin.cgi?project=fawiki&view=project | ||
.replace(/\[\[([^\|\]]+)\|\1([\u200c ]*(های?))\]\]/g, '[[$1]]$2')//[[Special:Diff/17515365/17865938]] | .replace(/\[\[([^\|\]]+)\|\1([\u200c ]*(های?))\]\]/g, '[[$1]]$2')//[[Special:Diff/17515365/17865938]] | ||
.replace(/([\S]*)[\s\u200c]*-[\s\u200c]*(تاکنون)(?![ ]+)/g, '$1-اکنون')//[[Special:Diff/17515365/17865938]] | .replace(/([\S]*)[\s\u200c]*-[\s\u200c]*(تاکنون)(?![ ]+)/g, '$1-اکنون')//[[Special:Diff/17515365/17865938]] | ||
خط ۵۵۶: | خط ۵۳۴: | ||
// پیوند به بیرونهایی که در میان پیوند نویسهٔ رفتن به خط بعد، وجود داشته باشد | // پیوند به بیرونهایی که در میان پیوند نویسهٔ رفتن به خط بعد، وجود داشته باشد | ||
.replace(/\[(?:https?\:|)\/\/[^\]\[]+\]/g, function (x) { | .replace(/\[(?:https?\:|)\/\/[^\]\[]+\]/g, function (x) { | ||
x = x.replace(/[\n\r]/g,''); | x = x.replace(/[\n\r]/g, ''); | ||
return x | return x | ||
}) | }) | ||
// فاصله اول زیربخش | // فاصله اول زیربخش | ||
.replace(/پیوند\n\=/,'پیوند=')// [[Special:Diff/20238012/20244702]] | .replace(/پیوند\n\=/, 'پیوند=')// [[Special:Diff/20238012/20244702]] | ||
.replace(/^ +(\=+[^\=]+\=+)/mg, '$1') | .replace(/^ +(\=+[^\=]+\=+)/mg, '$1') | ||
.replace(/\[\[\|/g, '[[') | .replace(/\[\[\|/g, '[[') | ||
خط ۵۷۹: | خط ۵۵۷: | ||
// تمیزکاری autoFormatter.js > CleanGalleries | // تمیزکاری autoFormatter.js > CleanGalleries | ||
.replace(/<gallery\b([^<>]*)>([^<>]+)<\/gallery\b[^<>]*>/gi, | .replace(/<gallery\b([^<>]*)>([^<>]+)<\/gallery\b[^<>]*>/gi, | ||
function( $0, $1, $2 ) { | function ($0, $1, $2) { | ||
return '<gallery' + $1 + '>' + $2 | return '<gallery' + $1 + '>' + $2 | ||
.replace( /^(\s*)\[+([^[\]]*)\]\]?\s*$/gm, '$1$2' ) | .replace(/^(\s*)\[+([^[\]]*)\]\]?\s*$/gm, '$1$2') | ||
.replace( /^(\s*)\[+/gm, '$1' ) + '<\/gallery>'; | .replace(/^(\s*)\[+/gm, '$1') + '<\/gallery>'; | ||
} | } | ||
) | ) | ||
// تمیزکاری پروندهها | // تمیزکاری پروندهها | ||
// زمانی که برچسب کوچک در توضیحات تصویر میآید برای دستگاههای با مانیتور کوچک خواندن متن مشکل میشود | // زمانی که برچسب کوچک در توضیحات تصویر میآید برای دستگاههای با مانیتور کوچک خواندن متن مشکل میشود | ||
//https:// | //https://checkwiki.toolforge.org/cgi-bin/checkwiki.cgi?project=fawiki&view=only&id=77 | ||
.replace(/\[\[(پرونده|[Ff]ile)\:((?:\[\[.*?\]\]|[^\]])*)\]\]/g, function ($0, $1, $2) { | .replace(/\[\[(پرونده|[Ff]ile)\:((?:\[\[.*?\]\]|[^\]])*)\]\]/g, function ($0, $1, $2) { | ||
$2 = $2.replace(/\<\/?(big|center|small)>/g,''); | $2 = $2.replace(/\<\/?(big|center|small)>/g, ''); | ||
return '[['+$1+':'+$2+']]' | return '[[' + $1 + ':' + $2 + ']]' | ||
}) | }) | ||
.replace( /\[\[ *تصو[يی]ر\:/gi, '[[پرونده:' ) | .replace(/\[\[ *تصو[يی]ر\:/gi, '[[پرونده:') | ||
// تمیزکاری الگو autoFormater.js > cleanTemplates | // تمیزکاری الگو autoFormater.js > cleanTemplates | ||
.replace( /\{\{\s*:?\s*(?:الگو|Template)\s*:\s*/gi, '{\{' ) | .replace(/\{\{\s*:?\s*(?:الگو|Template)\s*:\s*/gi, '{\{') | ||
// حذف خط زیر از عنوان الگو | // حذف خط زیر از عنوان الگو | ||
.replace(/(?:^|[^{])\{\{[ 0-9a-z\xC0-\u024F-]*_[ \w\xC0-\u024F-]*/gi, | .replace(/(?:^|[^{])\{\{[ 0-9a-z\xC0-\u024F-]*_[ \w\xC0-\u024F-]*/gi, | ||
function( $0 ) { | function ($0) { | ||
return $0.replace( /_+$/, '' ).replace( /[ _]+/g, ' ' ).replace( /\{ +/, '{' ); | return $0.replace(/_+$/, '').replace(/[ _]+/g, ' ').replace(/\{ +/, '{'); | ||
} | } | ||
) | ) | ||
خط ۶۱۱: | خط ۵۸۹: | ||
.replace(/\{\{سخ\}\}\]/g, ']') | .replace(/\{\{سخ\}\}\]/g, ']') | ||
.replace(/\[\{\{سخ\}\}/g, '[') | .replace(/\[\{\{سخ\}\}/g, '[') | ||
.replace(/\n\n(\*|\#)/g,'\n$1') | .replace(/\n\n(\*|\#)/g, '\n$1') | ||
.replace(/\n(\#|\*)( |)\n/g,'\n$1') | .replace(/\n(\#|\*)( |)\n/g, '\n$1') | ||
.replace(/\n(\*|\#)( |)(\={2,})/g,'\n$3') | .replace(/\n(\*|\#)( |)(\={2,})/g, '\n$3') | ||
.replace(/(\n?)\s+?<\/ref>/g, '$1</ref>') | .replace(/(\n?)\s+?<\/ref>/g, '$1</ref>') | ||
.replace(/\{ *\|/g, '{|') | .replace(/\{ *\|/g, '{|') | ||
خط ۶۱۹: | خط ۵۹۷: | ||
.replace(/\{\| *\{\|/g, '{|') | .replace(/\{\| *\{\|/g, '{|') | ||
.replace(/\|\} *\|\}/g, '|}') | .replace(/\|\} *\|\}/g, '|}') | ||
.replace( /^=.* .*=$/gim, function( $0 ) { | .replace(/^=.* .*=$/gim, function ($0) { | ||
return $0.replace(/(?: |\s)+/gi, ' '); | |||
}) | }) | ||
.replace(/([^=])\n+(\=.*?\=\n+)/g, '$1\n\n$2') | .replace(/([^=])\n+(\=.*?\=\n+)/g, '$1\n\n$2') | ||
خط ۶۳۳: | خط ۶۱۱: | ||
.replace(/(\={2,}) *([^\n\r]*?) *(\={2,})/g, '$1 $2 $3') // Format headings level 2 and above | .replace(/(\={2,}) *([^\n\r]*?) *(\={2,})/g, '$1 $2 $3') // Format headings level 2 and above | ||
// زیربخش نیازی به برچسب بزرگ و کوچک ندارد | // زیربخش نیازی به برچسب بزرگ و کوچک ندارد | ||
.replace(/(\=+) \<(?:small|big)\>([^\=\n\r]+)\<\/(?:small|big)\> (\=+)/g, '$1 $2 $3') | .replace(/(\=+) \<(?:small|big)\>([^\=\n\r]+)\<\/(?:small|big)\> (\=+)/g, '$1 $2 $3') | ||
// فاصلههای اضافی را از داخل پیوند به بیرون منتقل کند تا اگر اضافه بودند در کدهای دیگر حذف شوند | // فاصلههای اضافی را از داخل پیوند به بیرون منتقل کند تا اگر اضافه بودند در کدهای دیگر حذف شوند | ||
.replace(/\[\[(\s*)(.*?)(\s*)\]\]/g, '$1[[$2]]$3') | .replace(/\[\[(\s*)(.*?)(\s*)\]\]/g, '$1[[$2]]$3') | ||
خط ۶۴۶: | خط ۶۲۴: | ||
.replace(/([^.])([\.،,:]){2}(((?:<ref[^\/]*?\/>)+)+)/g, '$1$2$3') | .replace(/([^.])([\.،,:]){2}(((?:<ref[^\/]*?\/>)+)+)/g, '$1$2$3') | ||
/* هر رده در یک خط */ | /* هر رده در یک خط */ | ||
.replace( /([^\s>-]) *(\[\[رده:[^\n[\]]*\]\])/gi, '$1\n$2' ) | .replace(/([^\s>-]) *(\[\[رده:[^\n[\]]*\]\])/gi, '$1\n$2') | ||
.replace( /(\[\[رده:[^\n[\]]*\]\]) *(?![\s<-]|$)/gi, '$1\n' ) | .replace(/(\[\[رده:[^\n[\]]*\]\]) *(?![\s<-]|$)/gi, '$1\n') | ||
.replace( /(\[\[رده:[^\n[\]]*\]\]\n) *(?!\[\[رده:|[\s<-]|$)/gi,'$1\n') | .replace(/(\[\[رده:[^\n[\]]*\]\]\n) *(?!\[\[رده:|[\s<-]|$)/gi, '$1\n') | ||
//ترتیبپیشفرض | //ترتیبپیشفرض | ||
.replace(/\{\{(?:DEFAULTSORT|[Dd]efaultsort|ترتیب|ترتیب[ ]پیش[ ]?فرض) *[|:] *(?=.*?}})/g, '{{ترتیبپیشفرض:') | .replace(/\{\{(?:DEFAULTSORT|[Dd]efaultsort|ترتیب|ترتیب[ ]پیش[ ]?فرض) *[|:] *(?=.*?}})/g, '{{ترتیبپیشفرض:') | ||
.replace(/\{\{(ترتیبپیشفرض|DEFAULTSORT)\:[-\w,\s\(\)]+\}\}\n?/g, '') | .replace(/\{\{(ترتیبپیشفرض|DEFAULTSORT)\:[-\w,\s\(\)]+\}\}\n?/g, '') | ||
.replace(/(\{\{(?:ترتیبپیشفرض|DEFAULT\w*SORT\w*):[^\n{}]*\}\})\s*(?=\[\[رده:)/gi,'$1\n') | .replace(/(\{\{(?:ترتیبپیشفرض|DEFAULT\w*SORT\w*):[^\n{}]*\}\})\s*(?=\[\[رده:)/gi, '$1\n') | ||
.replace(/(\{\{ترتیبپیشفرض\:)\s/g, '$1') | .replace(/(\{\{ترتیبپیشفرض\:)\s/g, '$1') | ||
.replace( /(==\n)\n+(?=<references[^\n<>]*\/>\n\n)/gi, '$1' ) | .replace(/(==\n)\n+(?=<references[^\n<>]*\/>\n\n)/gi, '$1') | ||
//نچسبیدن و+فاصله به براکت که محصول اشتباه در تایپ کردن است | //نچسبیدن و+فاصله به براکت که محصول اشتباه در تایپ کردن است | ||
.replace(/\]\]و /g, ']] و ') | .replace(/\]\]و /g, ']] و ') | ||
خط ۶۶۶: | خط ۶۴۴: | ||
//تبدیل بندهای ترتیبی به قالببندی ویکی [[Special:Permalink/19923598#تبدیل بندهای ترتیبی به قالببندی ویکی]] | //تبدیل بندهای ترتیبی به قالببندی ویکی [[Special:Permalink/19923598#تبدیل بندهای ترتیبی به قالببندی ویکی]] | ||
.replace(/(?:(?:^(?:\* ?)?[۱۲۳۴۵۶۷۸۹۰0-9]{1,2} ?[\.\-\)]) ?[^۱۲۳۴۵۶۷۸۹۰0-9\n]+\n+){2,}/gm, function (x) { | .replace(/(?:(?:^(?:\* ?)?[۱۲۳۴۵۶۷۸۹۰0-9]{1,2} ?[\.\-\)]) ?[^۱۲۳۴۵۶۷۸۹۰0-9\n]+\n+){2,}/gm, function (x) { | ||
var x2=x.replace(/((?:\* ?)?[۱۲۳۴۵۶۷۸۹۰0-9]{1,2} ?[\.\-\)]) ?([^۱۲۳۴۵۶۷۸۹۰0-9\n]+)\n+/gm,'# $2\n') | var x2 = x.replace(/((?:\* ?)?[۱۲۳۴۵۶۷۸۹۰0-9]{1,2} ?[\.\-\)]) ?([^۱۲۳۴۵۶۷۸۹۰0-9\n]+)\n+/gm, '# $2\n') | ||
if (x2.replace(/[۱۲۳۴۵۶۷۸۹۰0-9]/g, '')===x2){ | if (x2.replace(/[۱۲۳۴۵۶۷۸۹۰0-9]/g, '') === x2) { | ||
return x2; | return x2; | ||
} | } | ||
خط ۶۷۷: | خط ۶۵۵: | ||
function wikiSubsection(text) { | function wikiSubsection(text) { | ||
return text.replace(/\<(?:\s*)references?(?:\s*\/|\s*\/\s*)\>/g, '{{پانویس}}') | return text.replace(/\<(?:\s*)references?(?:\s*\/|\s*\/\s*)\>/g, '{{پانویس}}') | ||
.replace(/\{\{(?:[Rr]eflist|[Rr]eferences?|پانویس[ ]?ها)(?=\||\})/g, '{{پانویس') | |||
.replace(/\{\{راست(| |)چین\}\}\s*\{\{پانویس(.*?)\}\}\s*\{\{(پایان راست(| |)چین|پایان)\}\}/g, '{{پانویس$2}}') | |||
.replace(/\{\{چپ(| |)چین\}\}\s*\{\{پانویس(.*?)\}\}\s*\{\{(پایان چپ(| |)چین|پایان)\}\}/g, '{{پانویس$2|چپچین=بله}}') | |||
.replace(/\<small\>\s*\{\{پانویس(.*?)\}\}\s*\<\/small\>/g, '{{پانویس$1|اندازه=کوچک}}') | |||
.replace(/(({\{پانویس.*?\}\})(\n|)){1,}/g, '$1') | |||
.replace(/\=\s*لیست\s*\=/g, '= فهرست =') | |||
.replace(/\=\s*(?:[gG]allery|نگارستان|گالری (تصویر|عکس|))\s*\=/g, '= نگارخانه =') | |||
.replace(/\=\s*(?:بیوگرافی|زندگینامه)\s*\=/g, '= زندگینامه =') | |||
.replace(/\=\s*(?:[eE]xternal links|لینک?های بیرونی|پیوندهای خارجی|لینک?های خارجی|پیوندهای بیرونی)\s*\=/g, '= پیوند به بیرون =') | |||
.replace(/\=\s*(?:[nN]otes|[fF]ootnotes?|پاورقی|پاورقیها|پانوشت|پانویسها)\s*\=/g, '= پانویس =') | |||
.replace(/\=\s*(?:[Ss]ee [Aa]lso|همچنین ببینی[مد]|بیشتر ببینی[مد]|همچنین نگاه کنید|بیشتر بدانی[مد]|مراجعات مرتبط|جستار وابسته|مطلب مرتبط|مطالب مرتبط|جستارهای مشابه|جستارهای دیگر)\s*\=/g, '= جستارهای وابسته =') | |||
.replace(/\=\s*(?:منبع|منبع[ ]?ها|رفرنس|رفرنس[ ]?ها|ارجاع[ ]?ها|ارجاع|مرجع[ ]?ها|رفرنس|برگرفته از|مراجع|منابع و یادداشت[ ]?ها|منبع|مرجع|م[آا]خذ|منابع و م[آا]خذ|منابع و پانویسها|فهرست مراجع|لیست مراجع|فهرست ارجاع[ ]?ها|فهرست ارجاع|[rR]eferences)\s*\=/g, '= منابع =') | |||
.replace(/\=\s*(?:مطالعه بیشتر|بیشتر بخوانی[مد])\s*\=/g, '= برای مطالعهٔ بیشتر =') | |||
.replace(/^\={3,}\s*(جستارهای وابسته|پانویس|منابع)\s*\={3,}$/g, '== $1 =='); | |||
} | } | ||
function wikiUrlMinifier(text) { | function wikiUrlMinifier(text) { | ||
خط ۷۰۳: | خط ۶۸۱: | ||
try { | try { | ||
x = decodeURIComponent(unescape(x)); | x = decodeURIComponent(unescape(x)); | ||
} catch (e) {mw.notify(e); } | } catch (e) { mw.notify(e); } | ||
} | } | ||
return x; | return x; | ||
}, | }, | ||
[patterns.globalExceptionTag, patterns.decodeUriBlacklist, patterns.refname] | [patterns.globalExceptionTag, patterns.decodeUriBlacklist, patterns.refname, patterns.urlArchive] | ||
); | ); | ||
}) | }) | ||
خط ۷۱۴: | خط ۶۹۲: | ||
.replace(/\[(https?\:)(?=\/\/(?:[\w\-]+)\.(?:m\.)?(wiki(pedia|media|data|source|news|oyage|quote)|wiktionary)\.org\/[^\s\]]*)/g, '[') | .replace(/\[(https?\:)(?=\/\/(?:[\w\-]+)\.(?:m\.)?(wiki(pedia|media|data|source|news|oyage|quote)|wiktionary)\.org\/[^\s\]]*)/g, '[') | ||
.replace(/[\[\=](?:https?\:|)\/\/[\w\-]{2,}\.(?:m\.)?wikipedia\.org\/w(?:iki)?\/([^\n?]*?)[\]\|]/g, function (x) { | .replace(/[\[\=](?:https?\:|)\/\/[\w\-]{2,}\.(?:m\.)?wikipedia\.org\/w(?:iki)?\/([^\n?]*?)[\]\|]/g, function (x) { | ||
x = x.replace(/\[(?:https?\:|)\/\/([\w\-]{2,})\.(?:m\.)?wikipedia\.org\/w(?:iki)?\/(.*?) (.*?)\]/g,'[[:$1:$2|$3]]') | x = x.replace(/\[(?:https?\:|)\/\/([\w\-]{2,})\.(?:m\.)?wikipedia\.org\/w(?:iki)?\/(.*?) (.*?)\]/g, '[[:$1:$2|$3]]') | ||
x = x.replace(/\[(?:https?\:|)\/\/([\w\-]{2,})\.(?:m\.)?wikipedia\.org\/w(?:iki)?\/(.*?)\]/g,'[[:$1:$2]]') | x = x.replace(/\[(?:https?\:|)\/\/([\w\-]{2,})\.(?:m\.)?wikipedia\.org\/w(?:iki)?\/(.*?)\]/g, '[[:$1:$2]]') | ||
//x = x.replace(/\=(?:https?\:|)\/\/([\w\-]{2,})\.(?:m\.)?wikipedia\.org\/w(?:iki)?\/(.*?)\|/g,'=[[:$1:$2]]|') // در الگو یادکرد مشکل ایجاد میکند | //x = x.replace(/\=(?:https?\:|)\/\/([\w\-]{2,})\.(?:m\.)?wikipedia\.org\/w(?:iki)?\/(.*?)\|/g,'=[[:$1:$2]]|') // در الگو یادکرد مشکل ایجاد میکند | ||
x = x.replace(/\[\[\:fa\:/g,'[[').replace(/\%20/g,' ').replace(/٪۲۰/g,' ').replace(/\[\[[a-zA-Z\'0-9 ]+\|/g,'[[') | x = x.replace(/\[\[\:fa\:/g, '[[').replace(/\%20/g, ' ').replace(/٪۲۰/g, ' ').replace(/\[\[[a-zA-Z\'0-9 ]+\|/g, '[[') | ||
x = x.replace(/\[\[.*?\]\]/g, function (y) { | x = x.replace(/\[\[.*?\]\]/g, function (y) { | ||
y = y.replace(/\_/g,' ') | y = y.replace(/\_/g, ' ') | ||
return y | return y | ||
}) | }) | ||
خط ۷۲۵: | خط ۷۰۳: | ||
}).replace(/\[{2}([^\|]+)\|\1\]{2}/gi, '[[$1]]'); | }).replace(/\[{2}([^\|]+)\|\1\]{2}/gi, '[[$1]]'); | ||
} | } | ||
function SubSectionLeveling (text) { | function SubSectionLeveling(text) { | ||
// تنظیم سطح زیربخشها | // تنظیم سطح زیربخشها | ||
text=text.replace(/^(\={2,}) *(.*?) *(\={2,})/mg, '$1 $2 $3') | text = text.replace(/^(\={2,}) *(.*?) *(\={2,})/mg, '$1 $2 $3') | ||
if ((mw.config.get('wgNamespaceNumber') === 0 && mw.config.get("wgEditMessage")==='editing')||mw.config.get('wgPageName') ==="ویکیپدیا:ویکیپروژه_ابزارها/آزمایش_واحد") { | if ((mw.config.get('wgNamespaceNumber') === 0 && mw.config.get("wgEditMessage") === 'editing') || mw.config.get('wgPageName') === "ویکیپدیا:ویکیپروژه_ابزارها/آزمایش_واحد") { | ||
//مقالهای که فقط زیربخش سطح ۱ دارد | //مقالهای که فقط زیربخش سطح ۱ دارد | ||
if (text.replace(/\=\=/g,'')===text){ | if (text.replace(/\=\=/g, '') === text) { | ||
var text2 = text.replace(new RegExp('^\=([^\=\r\n]+)\=$', 'gm'), "== $1 ==") | var text2 = text.replace(new RegExp('^\=([^\=\r\n]+)\=$', 'gm'), "== $1 ==") | ||
if (text!==text2){ | if (text !== text2) { | ||
text=text2.replace(/\n\= /g,'\n= ').replace(/ \=\n/g,' =\n') | text = text2.replace(/\n\= /g, '\n= ').replace(/ \=\n/g, ' =\n') | ||
}; | }; | ||
}; | }; | ||
//مقالهای که فقط زیربخش سطح ۳ یا ۴ دارد | //مقالهای که فقط زیربخش سطح ۳ یا ۴ دارد | ||
var text_test=text.replace(/^\=+ (منابع|جستارهای وابسته|پیوند به بیرون|پانویس|نگارخانه) \=+\n/gm,'') | var text_test = text.replace(/^\=+ (منابع|جستارهای وابسته|پیوند به بیرون|پانویس|نگارخانه) \=+\n/gm, '') | ||
if (text_test.replace(/^\=\= /gm,'')===text_test){ | if (text_test.replace(/^\=\= /gm, '') === text_test) { | ||
if (text_test.replace(/^\=\=\= /gm,'')!==text_test){ | if (text_test.replace(/^\=\=\= /gm, '') !== text_test) { | ||
//سطح ۳ | //سطح ۳ | ||
text = text.replace(new RegExp('^\=\=\=([^\=\r\n]+)\=\=\=$', 'gm'), "== $1 ==") | text = text.replace(new RegExp('^\=\=\=([^\=\r\n]+)\=\=\=$', 'gm'), "== $1 ==") | ||
text = text.replace(new RegExp('^\=\=\=\=([^\=\r\n]+)\=\=\=\=$', 'gm'), "=== $1 ===") | text = text.replace(new RegExp('^\=\=\=\=([^\=\r\n]+)\=\=\=\=$', 'gm'), "=== $1 ===") | ||
} else if (text_test.replace(/^\=\=\=\= /gm,'')!==text_test) { | } else if (text_test.replace(/^\=\=\=\= /gm, '') !== text_test) { | ||
//سطح ۴ | //سطح ۴ | ||
text = text.replace(new RegExp('^\=\=\=\=([^\=\r\n]+)\=\=\=\=$', 'gm'), "== $1 ==") | text = text.replace(new RegExp('^\=\=\=\=([^\=\r\n]+)\=\=\=\=$', 'gm'), "== $1 ==") | ||
}else{ | } else { | ||
text=text.replace(/===/g,'==') | text = text.replace(/===/g, '==') | ||
}; | }; | ||
}; | }; | ||
text=text.replace(/== /g,'== ').replace(/ ==/g,' ==') | text = text.replace(/== /g, '== ').replace(/ ==/g, ' ==') | ||
}; | }; | ||
return text; | return text; | ||
خط ۷۶۷: | خط ۷۴۵: | ||
persianTools.toPersianDigits, | persianTools.toPersianDigits, | ||
[patterns.globalExceptionTag, patterns.url, patterns.argumentsBlacklist, patterns.mathTag, patterns.imagePixelSize, patterns.fileNames, patterns.ref, | [patterns.globalExceptionTag, patterns.url, patterns.argumentsBlacklist, patterns.mathTag, patterns.imagePixelSize, patterns.fileNames, patterns.ref, | ||
patterns.sourceTag, patterns.arabicDigitsEnglishContext, patterns.signatures, patterns.htmlEntity, patterns.diffLink, | |||
patterns.htmlAttributes, patterns.fileParameter, patterns.templateParameterName, patterns.ipSign, | |||
patterns.parenthesesAfterDigits, patterns.otherLanguagesInline, patterns.preTag, patterns.isbn, patterns.englishDate, | |||
patterns.parameter, patterns.color, patterns.templateEnglishName, patterns.linksOnEnglishContext, patterns.citation, patterns.refname, | |||
patterns.LtRTagEnclosed, patterns.boxVar, patterns.mediawikiFunctions, patterns.graphTemplate] | |||
); | ); | ||
text = replaceExcept( | text = replaceExcept( | ||
text, | text, | ||
decimalPointToPersian, | decimalPointToPersian, | ||
[patterns.catgories] | [patterns.catgories, patterns.graphTemplate] | ||
); | ); | ||
return text | return text | ||
خط ۷۹۱: | خط ۷۶۹: | ||
new RegExp( | new RegExp( | ||
'(^|[^' + persianTools.persianCharacters + '])(\\s|\u200c|_|)(' + x + ')(\\s|_)(' + y + ')(\\s|\u200c|_|)(' + | '(^|[^' + persianTools.persianCharacters + '])(\\s|\u200c|_|)(' + x + ')(\\s|_)(' + y + ')(\\s|\u200c|_|)(' + | ||
extensions + ')($|[^' + persianTools.persianCharacters + '])', | |||
'g' | 'g' | ||
), | ), | ||
خط ۸۳۴: | خط ۸۱۲: | ||
new RegExp( | new RegExp( | ||
'(^|[^' + persianTools.persianCharacters + ']|\\s|_)(' + i + ')(\\s|_)(' + | '(^|[^' + persianTools.persianCharacters + ']|\\s|_)(' + i + ')(\\s|_)(' + | ||
dictionary.firstNameComplex[i] + ')(\\s|_)($|[^' + persianTools.persianCharacters + ']|[^' + | |||
persianTools.persianCharacters + '])', | |||
'g' | 'g' | ||
), | ), | ||
خط ۸۶۲: | خط ۸۴۰: | ||
new RegExp( | new RegExp( | ||
'(^|[^' + persianTools.persianCharacters + '])(\\s|\\(|\u200c|_|)(' + i + ')(\\s|\\)|\u200c|_|)($|[^' + | '(^|[^' + persianTools.persianCharacters + '])(\\s|\\(|\u200c|_|)(' + i + ')(\\s|\\)|\u200c|_|)($|[^' + | ||
persianTools.persianCharacters + '])', | |||
'g' | 'g' | ||
), | ), | ||
خط ۸۷۰: | خط ۸۴۸: | ||
} | } | ||
var preword = "(^|\\s|_|«|»|\\[|\\(|\\<|\\>|\\')("; | |||
// کلماتی که آ دارند | // کلماتی که آ دارند | ||
text = text.replace( | text = text.replace( | ||
new RegExp( | new RegExp(preword + dictionary.wordsWithA + ")(ی|ئی|یی|ٔ|)(?= |«|»|\\.|،|_|\\]|\\s|\\:|\\)|\\<|\\>|؟|\\'|\\!|$)", 'g'), | ||
function (x) { return x.replace(/ا/i, 'آ'); } // 'i' is just to trick bidi algorithm on code view | function (x) { return x.replace(/ا/i, 'آ'); } // 'i' is just to trick bidi algorithm on code view | ||
); | ); | ||
خط ۸۸۹: | خط ۸۶۸: | ||
// همزه ضم | // همزه ضم | ||
text = text.replace( | text = text.replace( | ||
new RegExp( | new RegExp(preword + dictionary.HamzehZam + ")(ها|ها|ین|ان|ی|ئی|یی|ٔ|)(?= |«|»|\\.|،|_|\\s|\\]|\\:|\\)|\\<|\\>|؟|\\!|\\'|$)", 'g'), | ||
function (x) { return x.replace(/وء/, 'ؤ').replace(/و/i, 'ؤ'); } // 'i' is just to trick bidi algorithm on code view | function (x) { return x.replace(/وء/, 'ؤ').replace(/و/i, 'ؤ'); } // 'i' is just to trick bidi algorithm on code view | ||
); | ); | ||
//همزه نصب | //همزه نصب | ||
text = text.replace( | text = text.replace( | ||
new RegExp( | new RegExp(preword + dictionary.HamzehNasb + ")(ی|ئی|یی|ٔ|)(?= |«|»|\\.|،|_|\\s|\\]|\\:|\\)|\\<|\\>|؟|\\!|\\'|$)", 'g'), | ||
function (x) { return x.replace(/ا/i, 'أ'); } // 'i' is just to trick bidi algorithm on code view | function (x) { return x.replace(/ا/i, 'أ'); } // 'i' is just to trick bidi algorithm on code view | ||
); | ); | ||
خط ۹۰۱: | خط ۸۸۰: | ||
for (i in dictionary.HamzehAtInside) { | for (i in dictionary.HamzehAtInside) { | ||
text = text.replace(new RegExp( | text = text.replace(new RegExp( | ||
preword + i + ')(| )(' + dictionary.HamzehAtInside[i] + ")(?= |«|»|\\.|،|_|\\s|\\]|\\:|\\)|\\<|\\>|؟|\\!|\\'|$)", | |||
'g' | 'g' | ||
), '$1$2ء$4'); | ), '$1$2ء$4'); | ||
خط ۹۰۷: | خط ۸۸۶: | ||
// در مورد افزودن یا حذف همزهٔ پایانی اجماعی وجود ندارد. | // در مورد افزودن یا حذف همزهٔ پایانی اجماعی وجود ندارد. | ||
/* text = text.replace(new RegExp( | /* text = text.replace(new RegExp(preword + dictionary.HamzehAtEnd + ")(?= |«|»|\\.|،|_|\\s|\\]|\\:|\\)|\\<|\\>|؟|\\!|\\'|$)", 'g'),'$1$2ء'); */ | ||
//الف مقصوره | //الف مقصوره | ||
text = text.replace( | text = text.replace( | ||
new RegExp( | new RegExp(preword + dictionary.AlefMaghsooreh + ")(?= |«|»|\\.|،|_|\\s|\\]|\\:|\\)|\\<|\\>|؟|\\!|\\'|$)", 'g'), | ||
function (x) { return x.replace(/ا/i, 'ی'); } // 'i' is just to trick bidi algorithm on code view | function (x) { return x.replace(/ا/i, 'ی'); } // 'i' is just to trick bidi algorithm on code view | ||
); | ); | ||
// صفت+تر | // صفت+تر | ||
text = text.replace(new RegExp("(^|\\s|_|«|»|\\]|\\[|\\(|\\<|\\>|\\')(" + dictionary.adjective + ")( |_)تر(?= |«|»|\\.|\\[|\\]|،|_|\\s|\\:|\\)|\\<|\\>|؟|\\!|\\'|$)", 'g'),'$1$2\u200cتر'); | text = text.replace(new RegExp("(^|\\s|_|«|»|\\]|\\[|\\(|\\<|\\>|\\')(" + dictionary.adjective + ")( |_)تر(?= |«|»|\\.|\\[|\\]|،|_|\\s|\\:|\\)|\\<|\\>|؟|\\!|\\'|$)", 'g'), '$1$2\u200cتر'); | ||
// اسامی رنگها (بهعنوان صفت)+تر | // اسامی رنگها (بهعنوان صفت)+تر | ||
text = text.replace(new RegExp("(^|\\s|_|«|»|\\]|\\[|\\(|\\<|\\>|\\')(" + dictionary.colorsNames + ")( |_)تر(?= |«|»|\\.|\\[|\\]|،|_|\\s|\\:|\\)|\\<|\\>|؟|\\!|\\'|$)", 'g'),'$1$2\u200cتر'); | text = text.replace(new RegExp("(^|\\s|_|«|»|\\]|\\[|\\(|\\<|\\>|\\')(" + dictionary.colorsNames + ")( |_)تر(?= |«|»|\\.|\\[|\\]|،|_|\\s|\\:|\\)|\\<|\\>|؟|\\!|\\'|$)", 'g'), '$1$2\u200cتر'); | ||
text = text.replace(/به دست\u200cآورد/g, 'به دست آورد'); // Solving a bug! | text = text.replace(/به دست\u200cآورد/g, 'به دست آورد'); // Solving a bug! | ||
text = persianTools.normalizeZwnj(text); | text = persianTools.normalizeZwnj(text); | ||
خط ۹۳۸: | خط ۹۱۷: | ||
} | } | ||
function wikiApplyOrthography(text) { | function wikiApplyOrthography(text) { | ||
text=text //en:Wikipedia:HTML5 | text = text //en:Wikipedia:HTML5 | ||
//big | |||
.replace(/((?:\<big\>){5})([^<]+)((?:\<\/big\>){5})/g, '<span style="font-size: 56px;">$2</span>') | |||
.replace(/((?:\<big\>){4})([^<]+)((?:\<\/big\>){4})/g, '<span style="font-size: 38px;">$2</span>') | |||
.replace(/((?:\<big\>){3})([^<]+)((?:\<\/big\>){3})/g, '{{خیلی بزرگ|$2}}') | |||
.replace(/((?:\<big\>){2})([^<]+)((?:\<\/big\>){2})/g, '{{بزرگ|$2}}') | |||
.replace(/((?:\<big\>){1})([^<]+|[\s\S]+)((?:\<\/big\>){1})/g, '{{درشت|$2}}') | |||
//center | |||
.replace(/<center><gallery>([\S\s]+?)\<\/gallery><\/center>/g, '<gallery class="center">$1</gallery>') | |||
//.replace(/<center>([\S\s]+?)<\/center>/g,'{{وسط|$1}}') | |||
//empty tag | |||
.replace(/<span style="font-size: [^>]+"><\/span>/g, '') | |||
.replace(/{{(?:درشت|خیلی بزرگ|بزرگ|وسط)\|}}/g, '') | |||
//حذف برچسبهای خالی نرمافزار مدیاویکی | //حذف برچسبهای خالی نرمافزار مدیاویکی | ||
var tags = ['math', 'div', 'grammarly\\-btn','code', 'nowiki', 'pre', 'syntaxhighlight' ,'source', 's', 'noinclude', 'includeonly', 'big', 'small','gallery'];// has bug for sub , sup [[Special:Diff/19450140/19490903]] | var tags = ['math', 'div', 'grammarly\\-btn', 'code', 'nowiki', 'pre', 'syntaxhighlight', 'source', 's', 'noinclude', 'includeonly', 'big', 'small', 'gallery'];// has bug for sub , sup [[Special:Diff/19450140/19490903]] | ||
text = replaceExcept( | text = replaceExcept( | ||
text, | |||
function (text) { | |||
for (var i = 0; i < tags.length; ++i) { | |||
for (var b = 0; b < 5; ++b) {//خیلی از برچسبهای خالی تو در تو هستند مانند [[Special:PermaLink/19223877]] | |||
text = text.replace(new RegExp('\<' + tags[i] + '[^\>]*\>(\\n|\\s|\u200c)*?\<\\/' + tags[i] + '\>', 'g'), ''); | |||
} | |||
// remove the tags if they occurred multiple times consequently | |||
if (mw.config.get('wgNamespaceNumber') === 0 || mw.config.get('wgNamespaceNumber') === 4) { | |||
text = text.replace(new RegExp('(\<' + tags[i] + '\>){2,}', 'g'), '$1') | |||
.replace(new RegExp('(\<\\/' + tags[i] + '\>){2,}', 'g'), '$1'); | |||
} | |||
} | } | ||
if (mw.config.get('wgNamespaceNumber') === 0) { | |||
text = text.replace(/\<ref\>[\s\n]*\<\/ref\>/g, '').replace(/\<ref\>[\s\n]*\<ref\>/g, '<ref>').replace(/\<\/ref\>[\s\n]*\<\/ref\>/g, '</ref>').replace(/\<ref\/\>/g, '</ref>'); | |||
}; | |||
return text | |||
}, | |||
[patterns.insideHtmlComment] | |||
); | ); | ||
return replaceExcept( | return replaceExcept( | ||
خط ۹۸۵: | خط ۹۶۴: | ||
}); | }); | ||
} | } | ||
// probably should be exactly same above but for applyZwnj | // probably should be exactly same above but for applyZwnj | ||
function wikiApplyZwnj(text) { | function wikiApplyZwnj(text) { | ||
خط ۱٬۰۰۲: | خط ۹۸۱: | ||
function replaceEnMonth(text) { | function replaceEnMonth(text) { | ||
var enMonth = { | var enMonth = { | ||
'آگست':'اوت', | 'آگست': 'اوت', | ||
'آگوست':'اوت', | 'آگوست': 'اوت', | ||
'جولای':'ژوئیه', | 'جولای': 'ژوئیه', | ||
'مارچ':'مارس', | 'مارچ': 'مارس', | ||
'آپریل':'آوریل', | 'آپریل': 'آوریل', | ||
'فوریوری':'فوریه', | 'فوریوری': 'فوریه', | ||
'january': 'ژانویه', | 'january': 'ژانویه', | ||
'jan': 'ژانویه', | 'jan': 'ژانویه', | ||
خط ۱٬۰۴۰: | خط ۱٬۰۱۹: | ||
return text | return text | ||
}; | }; | ||
function autoFormatCleanDatesException (text) { | function autoFormatCleanDatesException(text) { | ||
return replaceExcept( | return replaceExcept( | ||
text, | text, | ||
خط ۱٬۰۴۸: | خط ۱٬۰۲۷: | ||
} | } | ||
function wikitranslateEnMonth(text) { | function wikitranslateEnMonth(text) { | ||
text=autoFormatCleanDatesException(text) | text = autoFormatCleanDatesException(text) | ||
return replaceExcept( | return replaceExcept( | ||
text, | text, | ||
خط ۱٬۰۵۴: | خط ۱٬۰۳۳: | ||
var enMonthRegex = '(آگست|آگوست|جولای|مارچ|آپریل|january|jan|february|feb|march|mar|april|apr|may|jun|june|july|august|aug|sep|sept|september|oct|october|nov|november|december|dec)'; | var enMonthRegex = '(آگست|آگوست|جولای|مارچ|آپریل|january|jan|february|feb|march|mar|april|apr|may|jun|june|july|august|aug|sep|sept|september|oct|october|nov|november|december|dec)'; | ||
return text.replace(new RegExp('([^a-zA-Z])(\^|\\||\\s|\\=|\\n|\\(|«|\\:)' + enMonthRegex + ' (\\d{1,2}|[۱۲۳۴۵۶۷۸۹۰]{1,2})\\, (\\d{3,4}|[۱۲۳۴۵۶۷۸۹۰]{3,4})(\\||\\s|\\n|\$|\\)|\\}|»)([\^a\-zA\-Z])', 'ig'), | return text.replace(new RegExp('([^a-zA-Z])(\^|\\||\\s|\\=|\\n|\\(|«|\\:)' + enMonthRegex + ' (\\d{1,2}|[۱۲۳۴۵۶۷۸۹۰]{1,2})\\, (\\d{3,4}|[۱۲۳۴۵۶۷۸۹۰]{3,4})(\\||\\s|\\n|\$|\\)|\\}|»)([\^a\-zA\-Z])', 'ig'), | ||
function (x) { | |||
x = x.replace(new RegExp('([\^a\-zA\-Z])(\^|\\||\\s|\\=|\\n|\\(|«|\\:)' + enMonthRegex + ' (\\d{1,2}|[۱۲۳۴۵۶۷۸۹۰]{1,2})\\, (\\d{3,4}|[۱۲۳۴۵۶۷۸۹۰]{3,4})(\\||\\s|\\n|\$|\\)|\\}||»)([^a-zA-Z])', 'ig'), | |||
'$1$2$4 $3 $5$6$7') | '$1$2$4 $3 $5$6$7') | ||
x = persianTools.toPersianDigits(x); | |||
x = replaceEnMonth(x); | |||
return x; | |||
}) | |||
.replace(new RegExp('([\^a\-zA\-Z])(\^|\\||\\s|\\=|\\n|\\(|«)((\\d{1,2}|[۱۲۳۴۵۶۷۸۹۰]{1,2}) |)' + enMonthRegex + ' (\\d{3,4}|[۱۲۳۴۵۶۷۸۹۰]{3,4})(\\||\\s|\\n|$|\\)|\\}|»|\\:)([\^a\-zA\-Z])', 'ig'), | .replace(new RegExp('([\^a\-zA\-Z])(\^|\\||\\s|\\=|\\n|\\(|«)((\\d{1,2}|[۱۲۳۴۵۶۷۸۹۰]{1,2}) |)' + enMonthRegex + ' (\\d{3,4}|[۱۲۳۴۵۶۷۸۹۰]{3,4})(\\||\\s|\\n|$|\\)|\\}|»|\\:)([\^a\-zA\-Z])', 'ig'), | ||
function(x) { | function (x) { | ||
x = persianTools.toPersianDigits(x); | x = persianTools.toPersianDigits(x); | ||
x = replaceEnMonth(x); | x = replaceEnMonth(x); | ||
خط ۱٬۰۷۱: | خط ۱٬۰۵۰: | ||
) | ) | ||
} | } | ||
var arabicDigits = '0123456789', persianDigits = '۰۱۲۳۴۵۶۷۸۹', arabicIndicDigits = '٠١٢٣٤٥٦٧٨٩'; | var arabicDigits = '0123456789', persianDigits = '۰۱۲۳۴۵۶۷۸۹', arabicIndicDigits = '٠١٢٣٤٥٦٧٨٩'; | ||
function robustToEnglishDigits(text) { | function robustToEnglishDigits(text) { | ||
var i = 0; | var i = 0; | ||
for (i = 0; i <= 9; i = i + 1) { | for (i = 0; i <= 9; i = i + 1) { | ||
text = text.replace(new RegExp('[' + persianDigits[i] + arabicIndicDigits[i]+']', 'g'), arabicDigits[i]); | text = text.replace(new RegExp('[' + persianDigits[i] + arabicIndicDigits[i] + ']', 'g'), arabicDigits[i]); | ||
} | } | ||
return text; | return text; | ||
} | } | ||
function toEnglishDigits(text) { | function toEnglishDigits(text) { | ||
text = text.replace(/[a-zA-Z]([\_\s\:\.\,\;\]\[\"\'\)\(\}\{\/\\ ]+|)([۱۲۳۴۵۶۷۸۹۰٪\.٫\-\—\–°÷×\+\,\s\_\:،»«؛]+)([\_\s\:\.\,\;\]\[\"\'\)\(\}\{\/\\\<\> ]+|)([a-zA-Z\>]|$)/g, function (x) { | text = text.replace(/[a-zA-Z]([\_\s\:\.\,\;\]\[\"\'\)\(\}\{\/\\ ]+|)([۱۲۳۴۵۶۷۸۹۰٪\.٫\-\—\–°÷×\+\,\s\_\:،»«؛]+)([\_\s\:\.\,\;\]\[\"\'\)\(\}\{\/\\\<\> ]+|)([a-zA-Z\>]|$)/g, function (x) { | ||
var i = 0; | var i = 0; | ||
for (i = 0; i <= 9; i = i + 1) { | for (i = 0; i <= 9; i = i + 1) { | ||
x = x.replace(new RegExp('[' + persianDigits[i] + arabicIndicDigits[i]+ ']', 'g'), arabicDigits[i]); | x = x.replace(new RegExp('[' + persianDigits[i] + arabicIndicDigits[i] + ']', 'g'), arabicDigits[i]); | ||
} | } | ||
return x.replace(/،/g,',').replace(/»/g,'"').replace(/«/g,'"').replace(/؛/g,';'); | return x.replace(/،/g, ',').replace(/»/g, '"').replace(/«/g, '"').replace(/؛/g, ';'); | ||
}); | }); | ||
// bug [[Special:Diff/17760890/17760898]] | // bug [[Special:Diff/17760890/17760898]] | ||
خط ۱٬۰۹۳: | خط ۱٬۰۷۲: | ||
var i = 0; | var i = 0; | ||
for (i = 0; i <= 9; i = i + 1) { | for (i = 0; i <= 9; i = i + 1) { | ||
x = x.replace(new RegExp('[' + persianDigits[i] + arabicIndicDigits[i]+ ']', 'g'), arabicDigits[i]); | x = x.replace(new RegExp('[' + persianDigits[i] + arabicIndicDigits[i] + ']', 'g'), arabicDigits[i]); | ||
} | } | ||
return x; | return x; | ||
خط ۱٬۰۹۹: | خط ۱٬۰۷۸: | ||
// ISBN, ISSN and PMID's numbers should in english | // ISBN, ISSN and PMID's numbers should in english | ||
text = text.replace(/\b(ISBN|ISSN|PMID|PubMed) *:? *([۱۲۳۴۵۶۷۸۹۰0-9–—−ـ_\-]+)([^۱۲۳۴۵۶۷۸۹۰0-9–—−ـ_\-]|$)/gi, function (x) { | text = text.replace(/\b(ISBN|ISSN|PMID|PubMed) *:? *([۱۲۳۴۵۶۷۸۹۰0-9–—−ـ_\-]+)([^۱۲۳۴۵۶۷۸۹۰0-9–—−ـ_\-]|$)/gi, function (x) { | ||
x=x.replace(/[–—−ـ_\-]+/g,'-') | x = x.replace(/[–—−ـ_\-]+/g, '-') | ||
var i = 0; | var i = 0; | ||
for (i = 0; i <= 9; i = i + 1) { | for (i = 0; i <= 9; i = i + 1) { | ||
x = x.replace(new RegExp('[' + persianDigits[i] + arabicIndicDigits[i]+ ']', 'g'), arabicDigits[i]); | x = x.replace(new RegExp('[' + persianDigits[i] + arabicIndicDigits[i] + ']', 'g'), arabicDigits[i]); | ||
} | } | ||
x = x.replace(/\b(ISBN|ISSN|PMID|PubMed) *:? *([۱۲۳۴۵۶۷۸۹۰\-0-9]+)([^۱۲۳۴۵۶۷۸۹۰\-0-9]|$)/gi,'$1 $2$3') | x = x.replace(/\b(ISBN|ISSN|PMID|PubMed) *:? *([۱۲۳۴۵۶۷۸۹۰\-0-9]+)([^۱۲۳۴۵۶۷۸۹۰\-0-9]|$)/gi, '$1 $2$3') | ||
x = x.replace('PubMed','PMID') | x = x.replace('PubMed', 'PMID') | ||
return x; | return x; | ||
}); | }); | ||
text = text.replace(/ISBN \-note/g,'ISBN-note'); | text = text.replace(/ISBN \-note/g, 'ISBN-note'); | ||
// تبدیل عددهای فارسی در عدد ترتیبی انگلیسی | // تبدیل عددهای فارسی در عدد ترتیبی انگلیسی | ||
text = text.replace(/(?:^|["\'\s_«\(\[\{])([۱۲۳۴۵۶۷۸۹۰]+)(st|nd|rd|th)[\s_\.,»"\'\)\]\}]/g, function (x) { | text = text.replace(/(?:^|["\'\s_«\(\[\{])([۱۲۳۴۵۶۷۸۹۰]+)(st|nd|rd|th)[\s_\.,»"\'\)\]\}]/g, function (x) { | ||
var i = 0; | var i = 0; | ||
for (i = 0; i <= 9; i = i + 1) { | for (i = 0; i <= 9; i = i + 1) { | ||
x = x.replace(new RegExp('[' + persianDigits[i]+ arabicIndicDigits[i] + ']', 'g'), arabicDigits[i]); | x = x.replace(new RegExp('[' + persianDigits[i] + arabicIndicDigits[i] + ']', 'g'), arabicDigits[i]); | ||
} | } | ||
return x; | return x; | ||
خط ۱٬۱۲۱: | خط ۱٬۱۰۰: | ||
.replace(new RegExp('([' + arabicDigits + '])٫(?=[' + arabicDigits + '])', 'g'), '$1.') // English decimal separator | .replace(new RegExp('([' + arabicDigits + '])٫(?=[' + arabicDigits + '])', 'g'), '$1.') // English decimal separator | ||
} | } | ||
function cleanTemplateBracesFromArticle (text) {// like [[Special:Diff/18828723]] | function cleanTemplateBracesFromArticle(text, alwaysRun) { // like [[Special:Diff/18828723]] | ||
if (mw.config.get('wgNamespaceNumber') !== 0 && !alwaysRun) { | |||
return text; | |||
} | |||
var i = 0 | |||
for (i = 0; i <= 5; i = i + 1) { | |||
text = text.replace(/\{\{\{[^\|\}]+\|([^\}]+)\}\}\}/g, '$1') | |||
.replace(/\{\{\{[^\|\}]+\| *\}\}\}/g, '') | |||
} | |||
return text.replace(/\{\{\#(?!invoke)/ig, '{{جا:#') | |||
.replace(/\{\{ *(PAGENAME|FULLPAGENAMEE|SITENAME|NAMESPACE) *\}\}/g, '{{جا:$1}}') | |||
.replace('{{ترتیبپیشفرض:}}', ''); | |||
} | } | ||
function decodeHTMLSymbolEntitiesCodes (text) { | function decodeHTMLSymbolEntitiesCodes(text) { | ||
//© > © | //© > © | ||
return replaceExcept( | return replaceExcept( | ||
text, | text, | ||
function decodeEntitiesCodes (text) { | function decodeEntitiesCodes(text) { | ||
for (var i in htmlEntityCodes) { | for (var i in htmlEntityCodes) { | ||
var entityInput = i; | var entityInput = i; | ||
var entityoutput = htmlEntityCodes[i]; | var entityoutput = htmlEntityCodes[i]; | ||
text=text.replace(new RegExp(entityInput, 'g'), entityoutput); | text = text.replace(new RegExp(entityInput, 'g'), entityoutput); | ||
} | } | ||
return text; | return text; | ||
خط ۱٬۱۵۱: | خط ۱٬۱۳۰: | ||
) | ) | ||
} | } | ||
function removeWikiSigne (text) { | function removeWikiSigne(text) { | ||
return replaceExcept( | return replaceExcept( | ||
text, | text, | ||
function (text) { | function (text) { | ||
text=text.replace(/\[\[([^\|\]]+)\|([^\]]+)\]\]/g, '$2'); | text = text.replace(/\[\[([^\|\]]+)\|([^\]]+)\]\]/g, '$2'); | ||
text=text.replace(/\[\[([^\|\]]+)\]\]/g, '$1'); | text = text.replace(/\[\[([^\|\]]+)\]\]/g, '$1'); | ||
return text; | return text; | ||
}, [patterns.globalExceptionTag, patterns.fileNames, patterns.fileParameter, | }, [patterns.globalExceptionTag, patterns.fileNames, patterns.fileParameter, | ||
patterns.mathTag, patterns.sourceTag, patterns.templateWithEnglishName, patterns.nowikiTag, patterns.preTag, | |||
patterns.insideHtmlComment] | |||
) | ) | ||
} | } | ||
function autoEdHTMLtoWikitextWikiTools (text) { | function autoEdHTMLtoWikitextWikiTools(text) { | ||
return replaceExcept( | return replaceExcept( | ||
text, | text, | ||
خط ۱٬۱۷۱: | خط ۱٬۱۵۰: | ||
} | } | ||
function superTool(text) { | function superTool(text) { | ||
text = decodeHTMLSymbolEntitiesCodes (text); | text = decodeHTMLSymbolEntitiesCodes(text); | ||
text = cleanTemplateBracesFromArticle (text); | text = cleanTemplateBracesFromArticle(text); | ||
text = persianWikiTools.wikiConvertToPersianCharacters(text); | text = persianWikiTools.wikiConvertToPersianCharacters(text); | ||
text = persianWikiTools.wikiApplyZwnj(text); | text = persianWikiTools.wikiApplyZwnj(text); | ||
خط ۱٬۱۸۴: | خط ۱٬۱۶۳: | ||
text = persianWikiTools.wikiPunctuation(text); | text = persianWikiTools.wikiPunctuation(text); | ||
text = persianWikiTools.wikiSubsection(text); | text = persianWikiTools.wikiSubsection(text); | ||
text = persianWikiTools.SubSectionLeveling (text) | text = persianWikiTools.SubSectionLeveling(text) | ||
//ابزارهای بیشتر برگرفته از ویکیپدیای انگلیسی [[Mediawiki:Gadget-Extra-Editbuttons-autoed.js]] | //ابزارهای بیشتر برگرفته از ویکیپدیای انگلیسی [[Mediawiki:Gadget-Extra-Editbuttons-autoed.js]] | ||
text = autoEd.autoEdISBN(text); | text = autoEd.autoEdISBN(text); | ||
خط ۱٬۱۹۶: | خط ۱٬۱۷۵: | ||
return text; | return text; | ||
} | } | ||
function superToolMove(text) { | function superToolMove(text) { | ||
text = ' ' + text + ' '; // بعضی از کدها اگر فاصله در انتها یا اول نباشد عمل نمیکنند مانند افزودن تنوین به کلمه بعدا | text = ' ' + text + ' '; // بعضی از کدها اگر فاصله در انتها یا اول نباشد عمل نمیکنند مانند افزودن تنوین به کلمه بعدا | ||
خط ۱٬۲۱۹: | خط ۱٬۱۹۸: | ||
wikiDictation: wikiDictation, | wikiDictation: wikiDictation, | ||
wikiPunctuation: wikiPunctuation, | wikiPunctuation: wikiPunctuation, | ||
wikiSubsection:wikiSubsection, | wikiSubsection: wikiSubsection, | ||
SubSectionLeveling:SubSectionLeveling, | SubSectionLeveling: SubSectionLeveling, | ||
wikiUrlMinifier: wikiUrlMinifier, | wikiUrlMinifier: wikiUrlMinifier, | ||
wikiTextDigitsToPersian: wikiTextDigitsToPersian, | wikiTextDigitsToPersian: wikiTextDigitsToPersian, | ||
خط ۱٬۲۲۸: | خط ۱٬۲۰۷: | ||
robustToEnglishDigits: robustToEnglishDigits, | robustToEnglishDigits: robustToEnglishDigits, | ||
toEnglishDigits: toEnglishDigits, | toEnglishDigits: toEnglishDigits, | ||
removeCheckDict:removeCheckDict | cleanTemplateBracesFromArticle: cleanTemplateBracesFromArticle, | ||
removeCheckDict: removeCheckDict | |||
}; | }; | ||
}()); | }()); |