מדיה ויקי:Gadget-Checkty.js – הבדלי גרסאות

אין תקציר עריכה
אין תקציר עריכה
 
(27 גרסאות ביניים של משתמש אחר אחד אינן מוצגות)
שורה 29: שורה 29:
// 'checkty-empty-parameters-summary': 'ניקוי קוד',
// 'checkty-empty-parameters-summary': 'ניקוי קוד',
'checkty-main-articles-merge-summary': 'מיזוג הפניות לערכים מורחבים',
'checkty-main-articles-merge-summary': 'מיזוג הפניות לערכים מורחבים',
'checkty-missing-ref-section-add': 'נמצאו הערות שוליים בערך אך לא פרק מתאים. מומלץ להוסיף את הפרק לערך, וניתן להוסיף אותו אוטומטית במקום המשוער לכך.',
'checkty-missing-ref-section-added': 'פרק הערות שוליים הוסף.',
'checkty-missing-ref-section-autofix': 'הוספה אוטומטית',
'checkty-please-position-caret' : 'אנא מקמו את הסמן במקום בו יש להוסיף ',
'checkty-please-position-caret' : 'אנא מקמו את הסמן במקום בו יש להוסיף ',
'checkty-ref-dir-fix' : 'תיקון כיווניות להערת שוליים',
'checkty-ref-dir-fix' : 'תיקון כיווניות להערת שוליים',
שורה 44: שורה 47:
'checkty-language-check': 'בערך זה מופיע הביטוי "$1". ',
'checkty-language-check': 'בערך זה מופיע הביטוי "$1". ',
'checkty-wrong-use-discussion': 'דף זה עשוי להיות דף דיונים. אין לערוך תגובות של עורכים אחרים והשימוש בבדיקה של דף כזה אינו מומלץ. האם ברצונך להפעיל את הכלי למרות זאת?',
'checkty-wrong-use-discussion': 'דף זה עשוי להיות דף דיונים. אין לערוך תגובות של עורכים אחרים והשימוש בבדיקה של דף כזה אינו מומלץ. האם ברצונך להפעיל את הכלי למרות זאת?',
'checkty-vav-warning': 'כאשר ו עיצורית מופיעה באמצע מילה נהוג להכפילה. ייתכן שיש מופעים שדורשים תיקון.'
'checkty-vav-warning': 'כאשר ו עיצורית מופיעה באמצע מילה נהוג להכפילה. ייתכן שיש מופעים שדורשים תיקון.',
'checkty-inuse-warning': 'הדף כולל תבנית בעבודה. אנא הימנעו מעריכה של ערך בעבודה כאשר משתמשים אחרים עובדים עליו במקביל. האם ברצונכם להפעיל בדיקה אוטומטית בכל זאת?'
});
});


שורה 50: שורה 54:
try {
try {
// proper spacing around , and . using negative lookahead and lookbehind (ES2018) to acronyms (b.b.c)
// proper spacing around , and . using negative lookahead and lookbehind (ES2018) to acronyms (b.b.c)
return new RegExp('(?<!\\.[א-ת]*)([א-ת]\\]?\\]?) ?([,\\.]) ?(?=[א-ת]?\\[?\\[?[א-ת]{3})(?![א-ת]*\\.[א-ת])','g');
return new RegExp('(?<!\\.[א-ת]*)([א-ת]\\]?\\]?"?) ?([,\\.]) ?(?=[א-ת]?\\[?\\[?[א-ת]{3})(?![א-ת]*\\.[א-ת])','g');
} catch(e) {
} catch(e) {
console.log('Checkty - browser doesnt support negative lookhead or lookbehind (ES2018)');
console.log('Checkty - browser doesnt support negative lookhead or lookbehind (ES2018)');
שורה 76: שורה 80:
to: "",
to: "",
comment: 'הסרת תווים בלתי נראים'
comment: 'הסרת תווים בלתי נראים'
}, {
}, { // trim spaces in end of line
from: / +$/mg,
from: / +$/mg,
to: ''
to: ''
שורה 83: שורה 87:
to: '[[$1$2]]',
to: '[[$1$2]]',
comment: 'פישוט קישור'
comment: 'פישוט קישור'
}, { // trim begining from redundant spaces
}, { // trim beginning from redundant spaces
from: /^\s+/g,
from: /^\s+/g,
to: '',
to: '',
comment: 'הסרת רווחים מיותרים'
comment: 'הסרת רווחים מיותרים'
}, { // trim redundant spaces from category links
from: /\[\[קטגוריה: */g,
to: '[[קטגוריה:'
}],
}],
formatReplacesConfig: [{
formatReplacesConfig: [{ // piped link has identical text before and after the pipe
from: /\[\[(.*?)\|\1([a-zא-ת]*)\]\]/g,
from: /\[\[(.*?)\|\1([.,a-zא-ת]*)\]\]/g,
to: '[[$1]]$2'
to: '[[$1]]$2'
}, {
}, {
שורה 124: שורה 131:
from: /,\]\]/g,
from: /,\]\]/g,
to: ']],'
to: ']],'
},
{ // section between two headings without content
from: /\n==[^=\n]+?==\n*(\n==[^=\n]+?==\n)/g,
to: '$1',
comment: 'הסרת כותרות ריקות'
}],
}],
regexes: [],
regexes: [],
ignoreRegexes: [],
ignoreRegexes: [],
verifyRun: function () {
var self = this, runExcute = true,
inUseTemplatesRgx = /\{\{בעבודה[ \}\|]/;
if (!this.textbox || this.textbox.value.length === 0) return;
// this tool is not indented to be used in discussion pages
if ( mw.config.get('wgNamespaceNumber') % 2 == 1 || ( mw.config.get('wgNamespaceNumber') != 0  &&  /\(IST\)/.exec(this.textbox.value ) )) {
runExcute = false;
OO.ui.confirm(mw.msg('checkty-wrong-use-discussion')).done( function( confirmed ) { if ( confirmed ) self.execute(); });
}
// this tool is not intended to be used while other people are working on the same page
if( inUseTemplatesRgx.exec(this.textbox.value) ) {
runExcute = false;
OO.ui.confirm( mw.msg( 'checkty-inuse-warning' ) ).done( function( confirmed ) { if ( confirmed ) self.execute(); });
}
if (runExcute) this.execute();
},
run: function () {
run: function () {
if (this != chectTyTool) {
if (this != chectTyTool) {
שורה 134: שורה 164:
var t = $('#wpTextbox1');
var t = $('#wpTextbox1');
this.textbox = t.length ? t[0] : null;
this.textbox = t.length ? t[0] : null;
if (!this.textbox || this.textbox.value.length === 0) return;


// this tool is not indented to be used in discussion pages
this.verifyRun();
if ( mw.config.get('wgNamespaceNumber') % 2 == 1 || ( mw.config.get('wgNamespaceNumber') != 0  &&  /\(IST\)/.exec(this.textbox.value ) )) {
},
if (!prompt(mw.msg('checkty-wrong-use-discussion'))) return;
execute: function() {
}
// indication that skippable replacements should be ignored in the page
// indication that skippable replacements should be ignored in the page
this.skipCheckty = this.textbox.value.match(/{{ללא[_ ]בוט\|\s*צ'קטי\s*}}/g);
this.skipCheckty = this.textbox.value.match(/{{ללא[_ ]בוט\|\s*צ'קטי\s*}}/g);
שורה 298: שורה 326:
nakedLinks: function() {
nakedLinks: function() {
var t = this.textbox.value,
var t = this.textbox.value,
nakeRegex=/\[(http[^ ]+?)\]|\{\{הערה *\| *(?:1 *= *)?(https?:\/\/[^ }|]+)\}\}/g,
nakeRegex=/\[(http[^ ]+?)\]|\{\{הערה *\| *(?:1 *= *)?(https?:\/\/[^ }|]+)\}\}|<ref(?: [^/>]*)?>(https?:\/\/[^ }|]+?)<\/ref>/g,
nakeErrors=[], m, self= this;
nakeErrors=[], m, self= this;
while (m = nakeRegex.exec(t)) {
while (m = nakeRegex.exec(t)) {
var nakedUrl = m[1] || m[2],
var nakedUrl = m[1] || m[2] || m[3],
fixNakedLink = $( '<a href="#">' + mw.msg( 'checkty-naked-link-fix' )+'</a>' ).data( { 'search': nakedUrl, 'inRef': m[2] }).click( function ( e ) {  
fixNakedLink = $( '<a href="#">' + mw.msg( 'checkty-naked-link-fix' )+'</a>' ).data( { 'search': nakedUrl, 'inRefTemplate': m[2], 'inRef': m[3] }).click( function ( e ) {  
var searchUrl = $(this).data( 'search' ),
var searchUrl = $(this).data( 'search' ),
inRef = $(this).data('inRef'),
inRef = $(this).data('inRef'),
inRefTemplate = $(this).data('inRefTemplate'),
citoidTemplatesPromise = new mw.Api().loadMessagesIfMissing( [ 'citoid-template-type-map.json' ] );
citoidTemplatesPromise = new mw.Api().loadMessagesIfMissing( [ 'citoid-template-type-map.json' ] );
        // Common case: pasting a URI into this field. Citoid expects
        // Common case: pasting a URI into this field. Citoid expects
שורה 352: שורה 381:
var template = '{{'+CiteTemplates[d[0].itemType]+'|' + params.join('|')+'}}',
var template = '{{'+CiteTemplates[d[0].itemType]+'|' + params.join('|')+'}}',
wikitext = self.textbox.value;
wikitext = self.textbox.value;
if ( inRef ) {
if ( inRefTemplate ) {
wikitext = wikitext.replace(new RegExp('\\{\\{הערה *\\| *(?:1 *= *)?'+mw.util.escapeRegExp(searchUrl)+'\\}\\}', 'g'), '{{הערה|' + template + '}}');
wikitext = wikitext.replace(new RegExp('\\{\\{הערה *\\| *(?:1 *= *)?'+mw.util.escapeRegExp(searchUrl)+'\\}\\}', 'g'), '{{הערה|' + template + '}}');
} else if ( inRef ) {
wikitext = wikitext.replace(new RegExp('(<ref[^>]*>)'+mw.util.escapeRegExp(searchUrl)+'(</ref>)', 'g'), '$1' + template + '$2');
} else {
} else {
// this is more context sensitive - sometimes we may or may not want to wrap with ref
// this is more context sensitive - sometimes we may or may not want to wrap with ref
שורה 398: שורה 429:
this.mergeRefs();
this.mergeRefs();
this.refDirSuggest();
this.refDirSuggest();
if (!this.isSection) {
this.refSection();
}
},
},
writeMsg: function (msg, icon) {
writeMsg: function (msg, icon) {
שורה 635: שורה 669:
vavCheck: function () {
vavCheck: function () {
var text = this.textbox.value,
var text = this.textbox.value,
vavRegex = /ה\[\[ו[^ו][א-ת ]+\]\]/g, self = this;
vavRegex = /[כלבמשה]\[\[ו[^ו][א-ת ]+\]\]/g, self = this;
if (!vavRegex.exec( text )) return;
if (!vavRegex.exec( text )) return;
var vavWarning = $('<div>').text( mw.msg( 'checkty-vav-warning' ) ).append(this.createSearchLink(vavRegex));
var vavWarning = $('<div>').text( mw.msg( 'checkty-vav-warning' ) ).append(this.createSearchLink(vavRegex));
שורה 813: שורה 847:
text: this.textbox.value
text: this.textbox.value
} ).done( function( data ) {
} ).done( function( data ) {
if ( data && data.parse && data.parse.text && $(  data.parse.text['*'] ).find( 'a.image img' ).filter(function() {  
if ( data && data.parse && data.parse.text && $(  data.parse.text['*'] ).find( 'a.image img' ).filter(function() {  
var width = $(this).attr('width');
var width = $(this).attr('width');
if (isNaN(width)) width = $(this).width();
if (isNaN(width)) width = $(this).width();
שורה 820: שורה 854:
} ).length === 0 ) {
} ).length === 0 ) {
var fistURL = that.fistURL({
var fistURL = that.fistURL({
datatype: 'articles',
s: articleName
data: articleName
});
});
var msg = $('<div>', {
var msg = $('<div>', {
text: 'בדף זה אין תמונות. ניתן לחפש תמונות חופשיות ממקורות שונים. '
text: 'בדף זה אין תמונות. ניתן לחפש תמונות באתר חב"ד אינפו. '
}).append($('<a>', {
}).append($('<a>', {
href: decodeURI(fistURL),
href: decodeURI(fistURL),
שורה 913: שורה 946:
},
},
fistURL: function (p) {
fistURL: function (p) {
return 'https://chabad.info/?s=' + $.param(p);
return 'https://chabad.info/?' + $.param(p).replaceAll('_', '+');
},
},
languageCheck: function (checks) { //style and language check
languageCheck: function (checks) { //style and language check
שורה 961: שורה 994:
var splittedWarn = genrealWarningWords[i].split("//");
var splittedWarn = genrealWarningWords[i].split("//");
if ( splittedWarn.length !== 2 ) continue;
if ( splittedWarn.length !== 2 ) continue;
checks.push({
try {
'test': new RegExp( splittedWarn[0], 'i' ),
checks.push({
'remark': splittedWarn[1]
'test': new RegExp( splittedWarn[0], 'i' ),
});
'remark': splittedWarn[1]
});
}
catch(e)
{
/* negative lookbehind and similar advanced regex
will be skipped in browser which don't support it */
console.log('Skippted automatic check ' + i );
console.log(splittedWarn);
}
}
}
chectTyTool.languageCheck(checks);
chectTyTool.languageCheck(checks);
שורה 1,069: שורה 1,111:
if (k === i) continue; // skip same name
if (k === i) continue; // skip same name
if (refsContent[k].content == refsContent[i].content) { // two refs with same content but different name
if (refsContent[k].content == refsContent[i].content) { // two refs with same content but different name
var oldRefName = new RegExp('<ref name="'+mw.util.escapeRegExp(i)+'" */>', 'g');
mergedRefsNames.push(i);
mergedRefsNames.push(i);
shortRef = chectTyTool.named_comment + k + '}}';
shortRef = chectTyTool.named_comment + k + '}}';
wikitext = wikitext.replace(refsContent[i].text, shortRef);
wikitext = wikitext.replace(refsContent[i].text, shortRef);
// TODO: possibly need to replace short refs of the other name
wikitext = wikitext.replace(oldRefName, shortRef);
}
}
}
}
שורה 1,151: שורה 1,194:
var searchRef = this.createSearchLink(m[1]);
var searchRef = this.createSearchLink(m[1]);
this.writeMsg($('<div>').append(['נמצאה הערת שוליים ללא הגדרת כיווניות "'+m[1]+'" [',searchRef, '&nbsp;-&nbsp;', fixRefDirLink, ']']), 'alert');
this.writeMsg($('<div>').append(['נמצאה הערת שוליים ללא הגדרת כיווניות "'+m[1]+'" [',searchRef, '&nbsp;-&nbsp;', fixRefDirLink, ']']), 'alert');
}
},
refSection: function(fix) {
var wikitext = this.textbox.value, newText = wikitext, self = this,
refRE = /<ref>|\{\{הערה\|/g,
refSectionRE = /\{\{הערות[ _]שוליים|<references[ >]/g,
hasRef = refRE.exec(wikitext) != null,
hasRefSection  = refSectionRE.exec(wikitext) != null;
if (hasRefSection) return; //not missing
if (!hasRef) return; // not needed
if (fix) { //  fix only when when explictly asked
var autoRefSection = '\n{{הערות שוליים}}\n'
var lastItems = [/(\n{{בקרת זהויות)/, /(\n{{קצרמר)/,/\n({{הבהרה (?:רפואית|הלכתית|משפטית))/,/(\n{{מיון רגיל:)/, /(\n\[\[קטגוריה:)/];
for (var i=0; (i < lastItems.length) && (wikitext == newText); i++ )  newText = wikitext.replace(lastItems[i], autoRefSection + '$1');
if ( wikitext === newText ) newText = wikitext + autoRefSection;
this.textbox.value = newText;
this.addSummary('פרק הערות שוליים');
this.writeMsg($('<div>'+mw.msg( 'checkty-missing-ref-section-added' )+'</div>'), 'info');
} else {
this.writeMsg($('<div>'+mw.msg( 'checkty-missing-ref-section-add' )+'</div>').append($('<a href="#">'+mw.msg( 'checkty-missing-ref-section-autofix' )+'</a>').click(function(){ self.refSection(true); return false; })), 'info');
}
}
},
},
שורה 1,467: שורה 1,531:
var t = this.textbox.value,
var t = this.textbox.value,
viafTemplate = /\{\{בקרת זהויות[\}|]/g,
viafTemplate = /\{\{בקרת זהויות[\}|]/g,
acTemplate = '{{' + 'בקרת זהויות}}',
newText;
newText;
if ( viafTemplate.exec( t ) ) return; // viaf already exist
if ( viafTemplate.exec( t ) ) return; // viaf already exist
newText = t.replace(/{{קצרמר/, '{{בקרת זהויות}}\n{{קצרמר'); // before stub
newText = t.replace(/{{קצרמר/, acTemplate + '\n{{קצרמר'); // before stub
if (newText == t) newText = t.replace(/{{מיון רגיל:/, '{{בקרת זהויות}}\n{{מיון רגיל:'); //before default sort
if (newText == t) newText = t.replace(/{{מיון רגיל:/, acTemplate + '\n{{מיון רגיל:'); //before default sort
if (newText == t) newText = t.replace(/\[\[קטגוריה:/, '{{בקרת זהויות}}\n[[קטגוריה:'); // before categories
if (newText == t) newText = t.replace(/\[\[קטגוריה:/, acTemplate + '\n[[קטגוריה:'); // before categories
if (newText == t) newText = t += '\n{{בקרת זהויות}}';
if (newText == t) newText = t + '\n' + acTemplate;
this.textbox.value = newText;
this.textbox.value = newText;
this.addSummary('בקרת זהויות');
this.addSummary('בקרת זהויות');