۷٬۰۶۳
ویرایش
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش |
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش |
||
(۳ نسخهٔ میانی ویرایش شده توسط ۲ کاربر نشان داده نشد) | |||
خط ۴۵: | خط ۴۵: | ||
//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, | ||
// space, ", \t, \n, {, |, }, ... they will interfere with wiki markup | // space, ", \t, \n, {, |, }, ... they will interfere with wiki markup | ||
decodeUriBlacklist: /(?:%20|%27|%5C|%5E|%60|%23|%25|%3C|%3E|%5B|%5D|%22|%09|%0A|%7B|%7C|%7D)/gi, | decodeUriBlacklist: /(?:%20|%27|%5C|%5E|%60|%23|%25|%3C|%3E|%5B|%5D|%22|%09|%0A|%7B|%7C|%7D|%C2|%A0)/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 | ||
خط ۶۲: | خط ۶۲: | ||
insideHtmlComment: /<\!\-\-[\s\S]*?\-\->/g, | insideHtmlComment: /<\!\-\-[\s\S]*?\-\->/g, | ||
linksOnEnglishContext: /[a-z][\:\,\. ]*\[\[[\da-z\-\, ]*/gi, | linksOnEnglishContext: /[a-z][\:\,\. ]*\[\[[\da-z\-\, ]*/gi, | ||
mapFrameTag: /<mapframe.*?>[\s\S]*?<\/mapframe>/g, | |||
mathTag: /<math.*?>[\s\S]*?<\/math>/g, | mathTag: /<math.*?>[\s\S]*?<\/math>/g, | ||
otherLanguagesInline: /\{\{(?:به .+?|پم|به انگلیسی|انگلیسی|عربی|متن عربی|عبارت عربی|حدیث|به عربی|به اردو|اردو|lang\-[au]r|پینگ|ping)[\s\S]*?\}\}/g, | otherLanguagesInline: /\{\{(?:به .+?|پم|به انگلیسی|انگلیسی|عربی|متن عربی|عبارت عربی|حدیث|به عربی|به اردو|اردو|lang\-[au]r|پینگ|ping)[\s\S]*?\}\}/g, | ||
خط ۷۳: | خط ۷۴: | ||
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, | 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: /\{\{[ \_]*(?:الگو|Template)?[\x00-\x7a~]*\|.*?\}\}/gi, | templateWithEnglishName: /\{\{[ \_]*(?:الگو|Template)?[\x00-\x7a~]*\|.*?\}\}/gi, | ||
خط ۸۱: | خط ۸۲: | ||
boxVar: /([a-zA-Z][۱۲۳۴۵۶۷۸۹۰]+) *\=/g, | boxVar: /([a-zA-Z][۱۲۳۴۵۶۷۸۹۰]+) *\=/g, | ||
url: /\/\/.*?(?=[\s\n\|\}\]<]|$)/gi, // بدون https?: هم ممکن است | url: /\/\/.*?(?=[\s\n\|\}\]<]|$)/gi, // بدون https?: هم ممکن است | ||
url2: /\/\/.*?(?:[\s\n\|\}\]<]|$)/gi, //برای مواردی که نیاز باشد ادامهٔ نشانی وب را دست نزند | |||
urlArchive: /\/\/web\.archive\.org[^\|\}\n\<\>]+/gi, | 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' + escapeRegExp(mw.config.get('wgTitle')).split(' ').join('\\s|\\s') + '\\s', 'g'), | ||
catgories: /\[\[(?:رده|[Cc]ategory)\:[^\]]+\]\]/gi | catgories: /\[\[(?:رده|[Cc]ategory)\:[^\]]+\]\]/gi, | ||
rfd: /\{\{نظرخواهی برای حذف.*\}\}/g | |||
}; | }; | ||
function escapeRegExp(string) { | |||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | |||
} | |||
function escapeRE(s) { | function escapeRE(s) { | ||
خط ۴۶۱: | خط ۴۶۸: | ||
return text; | return text; | ||
} | |||
function sortCategories(content, pageName) { | |||
return content.replace(/((?:\n\[\[رده:.+\]\])+)/, function (categories) { | |||
var sortedCategories = persianTools.persianSort(categories.trim().split('\n')); | |||
return '\n' + sortedCategories.map(function (line, i) { | |||
// Put a "| " on category with the same name as the page | |||
if (line.indexOf('[[رده:' + pageName + ']]') === 0) | |||
line = '[[رده:' + pageName + '| ]]'; | |||
// If it contains "| " put it at top | |||
if (line.indexOf('| ]]') !== -1) i = -1; | |||
return { index: i, content: line }; | |||
}).sort(function (x, y) { // sort based on their initial line index | |||
return x.index - y.index; | |||
}).map(function (x) { return x.content; }).join('\n'); | |||
}); | |||
} | } | ||
خط ۵۰۲: | خط ۵۲۷: | ||
function (text) { | function (text) { | ||
return persianTools.punctuation(text) | return persianTools.punctuation(text) | ||
.replace(/^([*#]+)([^*#\:\s])/mg, '$1 $2') // Adds a space after the # or * for lists | .replace(/^([*#]+;?)([^*#;\:\s])/mg, '$1 $2') // Adds a space after the # or * for lists | ||
.replace(/^([*#]+) {2,}( | .replace(/^([*#]+;?) {2,}(.)/mg, '$1 $2'); // Trim more that one space after the # or * for lists | ||
}, | }, | ||
[patterns.globalExceptionTag, patterns.mathTag, patterns.fileNames, patterns.url, patterns.wikilinkTargets, | [patterns.globalExceptionTag, patterns.mapFrameTag, patterns.mathTag, patterns.fileNames, patterns.url, patterns.wikilinkTargets, | ||
patterns.galleryTag, patterns.sourceTag, patterns.translatedUrl, patterns.parenthesesHa] | patterns.galleryTag, patterns.sourceTag, patterns.translatedUrl, patterns.parenthesesHa, patterns.insideHtmlComment] | ||
) | ) | ||
.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(/(\=+) \<(?: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, '{{$2}}') | .replace(/\{\{(\s*)(.*?)(\s*)\}\}/g, '{{$2}}') | ||
خط ۶۴۰: | خط ۶۶۳: | ||
.replace(/((?:^|\n\s)\=+\s+\=+(?:\s+|)\n)/g, "\n\n") | .replace(/((?:^|\n\s)\=+\s+\=+(?:\s+|)\n)/g, "\n\n") | ||
.replace(/\n{3,}/g, '\n\n') | .replace(/\n{3,}/g, '\n\n') | ||
.replace(/(\[{1,2})([^\[\]\n] | // فاصلههای اضافی را از داخل پیوند به بیرون منتقل کند تا اگر اضافه بودند در کدهای دیگر حذف شوند | ||
// غیرفعالسازی: عملکرد مشابه پایین هم وجود دارد | |||
// .replace(/\[\[(\s*)(.*?)(\s*)\]\]/g, '$1[[$2]]$3') | |||
.replace(/(\[{1,2})([^\[\]\n]*[^\[\]\n\|]) +(\]{1,2})/g, "$1$2$3") | |||
.replace(/(\[{1,2}) +([^\[\]\n]+)(\]{1,2})/g, "$1$2$3") | .replace(/(\[{1,2}) +([^\[\]\n]+)(\]{1,2})/g, "$1$2$3") | ||
//تبدیل بندهای ترتیبی به قالببندی ویکی [[Special:Permalink/19923598#تبدیل بندهای ترتیبی به قالببندی ویکی]] | //تبدیل بندهای ترتیبی به قالببندی ویکی [[Special:Permalink/19923598#تبدیل بندهای ترتیبی به قالببندی ویکی]] | ||
خط ۷۴۴: | خط ۷۷۰: | ||
text, | 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.mapFrameTag, patterns.mathTag, patterns.imagePixelSize, patterns.fileNames, patterns.ref, | ||
patterns.sourceTag, patterns.arabicDigitsEnglishContext, patterns.signatures, patterns.htmlEntity, patterns.diffLink, | patterns.sourceTag, patterns.arabicDigitsEnglishContext, patterns.signatures, patterns.htmlEntity, patterns.diffLink, | ||
patterns.htmlAttributes, patterns.fileParameter, patterns.templateParameterName, patterns.ipSign, | patterns.htmlAttributes, patterns.fileParameter, patterns.templateParameterName, patterns.ipSign, | ||
خط ۹۵۶: | خط ۹۸۲: | ||
text, | text, | ||
persianTools.applyOrthography, | persianTools.applyOrthography, | ||
[patterns.globalExceptionTag, patterns.fileNames, patterns.signatures, patterns.url, patterns.galleryTag, patterns.wikilinkTargets] | [patterns.globalExceptionTag, patterns.fileNames, patterns.signatures, patterns.url, patterns.galleryTag, patterns.wikilinkTargets, patterns.rfd] | ||
).replace(patterns.galleryTag, function (gallery) { | ).replace(patterns.galleryTag, function (gallery) { | ||
// apply `applyOrthography` on gallery descriptions separately | // apply `applyOrthography` on gallery descriptions separately | ||
خط ۱٬۰۲۳: | خط ۱٬۰۴۹: | ||
text, | text, | ||
autoFormatCleanDates, | autoFormatCleanDates, | ||
[patterns.globalExceptionTag, patterns.fileNames, patterns.galleryTag, patterns.mathTag, patterns.sourceTag, patterns.templateWithEnglishName, patterns.citation, patterns.argumentsBlacklist, patterns.ref] | [patterns.globalExceptionTag, patterns.fileNames, patterns.galleryTag, patterns.mapFrameTag, patterns.mathTag, patterns.sourceTag, patterns.templateWithEnglishName, patterns.citation, patterns.argumentsBlacklist, patterns.ref] | ||
) | ) | ||
} | } | ||
خط ۱٬۰۴۷: | خط ۱٬۰۷۳: | ||
} | } | ||
); | ); | ||
}, [patterns.globalExceptionTag, patterns.fileNames, patterns.ref, patterns.fileParameter, patterns.galleryTag, patterns.mathTag, patterns.sourceTag, patterns.templateWithEnglishName, patterns.citation, patterns.argumentsBlacklist] | }, [patterns.globalExceptionTag, patterns.fileNames, patterns.ref, patterns.fileParameter, patterns.galleryTag, patterns.mapFrameTag, patterns.mathTag, patterns.sourceTag, patterns.templateWithEnglishName, patterns.citation, patterns.argumentsBlacklist] | ||
) | ) | ||
} | } | ||
خط ۱٬۱۲۷: | خط ۱٬۱۵۳: | ||
return text; | return text; | ||
}, [patterns.globalExceptionTag, patterns.fileNames, patterns.ref, patterns.fileParameter, | }, [patterns.globalExceptionTag, patterns.fileNames, patterns.ref, patterns.fileParameter, | ||
patterns.galleryTag, patterns.mathTag, patterns.sourceTag, patterns.templateWithEnglishName, | patterns.galleryTag, patterns.mapFrameTag, patterns.mathTag, patterns.sourceTag, patterns.templateWithEnglishName, | ||
patterns.citation, patterns.url] | patterns.citation, patterns.url] | ||
) | ) | ||
خط ۱٬۱۳۹: | خط ۱٬۱۶۵: | ||
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.mapFrameTag, patterns.mathTag, patterns.sourceTag, patterns.templateWithEnglishName, patterns.nowikiTag, patterns.preTag, | ||
patterns.insideHtmlComment] | patterns.insideHtmlComment] | ||
) | ) | ||
خط ۱٬۱۴۷: | خط ۱٬۱۷۳: | ||
text, | text, | ||
autoEd.autoEdHTMLtoWikitext, | autoEd.autoEdHTMLtoWikitext, | ||
[patterns.fileParameter, patterns.mathTag, patterns.sourceTag] | [patterns.fileParameter, patterns.mapFrameTag, patterns.mathTag, patterns.sourceTag] | ||
) | ) | ||
} | } | ||
خط ۱٬۱۷۴: | خط ۱٬۲۰۰: | ||
text = persianWikiTools.addColumnToRefTemplate(text); | text = persianWikiTools.addColumnToRefTemplate(text); | ||
text = persianWikiTools.removeCheckDict(text); | text = persianWikiTools.removeCheckDict(text); | ||
text = persianWikiTools.sortCategories(text, mw.config.get('wgPageName').replace(/_/g, ' ')); | |||
return text; | return text; | ||
} | } | ||
خط ۱٬۱۸۷: | خط ۱٬۲۱۴: | ||
text = persianWikiTools.wikiPunctuation(text); | text = persianWikiTools.wikiPunctuation(text); | ||
return text.trim(); | return text.trim(); | ||
} | |||
// Puts the selceted text (trims spaces from start and end) in bdi tags | |||
// does not put the whole content in tags if no text is selected | |||
function putSelectionInBDI(text) { | |||
// if no text is selected, don't put the whole content inside the tags | |||
// can't return nothing because applyOnSelection() expects some text | |||
// and throws an error while no text is provided | |||
if (text == $('#wpTextbox1').val()) { | |||
return text; | |||
} else { | |||
// regExp to trim space from begining and end of the selected text, | |||
// and save them to be placed outside of tags | |||
var regExp = /(^\s*)|(\s*$)/gm; | |||
var startEndSpaces = text.match(regExp); | |||
// place selected spaces outside of tags | |||
// and remove them from the text inside | |||
var outText = startEndSpaces[0] + '<bdi>' + text.replace(regExp, '') + '</bdi>' + startEndSpaces[1]; | |||
return outText; | |||
} | |||
} | } | ||
خط ۱٬۲۰۹: | خط ۱٬۲۵۶: | ||
toEnglishDigits: toEnglishDigits, | toEnglishDigits: toEnglishDigits, | ||
cleanTemplateBracesFromArticle: cleanTemplateBracesFromArticle, | cleanTemplateBracesFromArticle: cleanTemplateBracesFromArticle, | ||
removeCheckDict: removeCheckDict | removeCheckDict: removeCheckDict, | ||
sortCategories: sortCategories, | |||
putSelectionInBDI : putSelectionInBDI | |||
}; | }; | ||
}()); | }()); |