הבדלים בין גרסאות בדף "מדיה ויקי:Gadget-Checkty.js"

מ
אין תקציר עריכה
(יצירת דף עם התוכן "// הוספת כפתור "בדיקה" שמבצע החלפות נפוצות של בוט ההחלפות וכן מתריע על בעיות סגנון ועיצוב...")
 
he.wikipedia>ערן
מ
שורה 46: שורה 46:
origText: null,
origText: null,
textbox: null,
textbox: null,
skipCheckty: false,
isSection: mw.util.getParamValue('section'),
isSection: mw.util.getParamValue('section'),
skip_dict: {},
formatReplacesConfigSafe:  [
formatReplacesConfigSafe:  [
{
{
שורה 56: שורה 58:
}, { //remove unseen character
}, { //remove unseen character
from: new RegExp('\u200e|\u200f|\u202d|\u202e|\u202c|\u202a|\u202b', 'g'), // lrm/rlm/lro/rlo/popdf invisible characters/lre/rle
from: new RegExp('\u200e|\u200f|\u202d|\u202e|\u202c|\u202a|\u202b', 'g'), // lrm/rlm/lro/rlo/popdf invisible characters/lre/rle
to: ""
to: "",
comment: 'הסרת תווים בלתי נראים'
}, {
}, {
from: / +$/mg,
from: / +$/mg,
שורה 64: שורה 67:
to: '[[$1$2]]',
to: '[[$1$2]]',
comment: 'פישוט קישור'
comment: 'פישוט קישור'
}, { // trim begining from redundant spaces
from: /^\s+/g,
to: '',
comment: 'הסרת רווחים מיותרים'
}],
}],
formatReplacesConfig: [{
formatReplacesConfig: [{
שורה 73: שורה 80:
}, { // proper spacing around , and .  
}, { // proper spacing around , and .  
from: /([א-ת]\]?\]?) ?([,\.]) ?(?=[א-ת]?\[?\[?[א-ת]{3})/g,
from: /([א-ת]\]?\]?) ?([,\.]) ?(?=[א-ת]?\[?\[?[א-ת]{3})/g,
to: "$1$2 "
to: "$1$2 ",
skippable: true
}, {
}, {
from: /([א-ת])\( ?([א-ת])/g,
from: /([א-ת])\( ?([א-ת])/g,
שורה 111: שורה 119:
this.textbox = t.length ? t[0] : null;
this.textbox = t.length ? t[0] : null;
if (!this.textbox || this.textbox.value.length === 0) return;
if (!this.textbox || this.textbox.value.length === 0) return;
// indication that skippable replacements should be ignored in the page
this.skipCheckty = this.textbox.value.match(/{{ללא[_ ]בוט\|\s*צ'קטי\s*}}/g);
if (!($('#checktyResults').length)) $('.editButtons').after('<div id="checktyResults"><div class="checktyResultsTitle">'+mw.msg( 'checkty-warnings-title' )+'</div></div>');
if (!($('#checktyResults').length)) $('.editButtons').after('<div id="checktyResults"><div class="checktyResultsTitle">'+mw.msg( 'checkty-warnings-title' )+'</div></div>');
//first call to remote functions than to local
//first call to remote functions than to local
שורה 385: שורה 395:
},
},
build_regexes: function (data, protect) {
build_regexes: function (data, protect) {
if (/\{\{\s*ללא_בוט\s*\}\}/.test(this.textbox.value)) {
if (/\{\{\s*ללא[_ ]בוט\s*\}\}/.test(this.textbox.value)) {
this.writeMsg('<div>'+mw.msg( 'checkty-no-replacements' )+'</div>', 'info');
this.writeMsg('<div>'+mw.msg( 'checkty-no-replacements' )+'</div>', 'info');
return;
return;
שורה 435: שורה 445:
process_page: function () {
process_page: function () {
var t = this.textbox.value,
var t = this.textbox.value,
skip_dict = {},
skip_ar = [],
skip_ar = [],
actual_replaced = [], // list of actual replcements for summary
actual_replaced = [], // list of actual replcements for summary
שורה 443: שורה 452:
for (i = 0; i < skipmatch.length; i++) {
for (i = 0; i < skipmatch.length; i++) {
var matches = skipmatch[i].match(/{{ללא[_ ]בוט\|\s*(\d+)\s*}}/), detailedSkip = '';
var matches = skipmatch[i].match(/{{ללא[_ ]בוט\|\s*(\d+)\s*}}/), detailedSkip = '';
skip_dict[parseInt(matches[1], 10)] = true;
chectTyTool.skip_dict[parseInt(matches[1], 10)] = true;
if (this.regexes[matches[1]]) {
if (this.regexes[matches[1]]) {
detailedSkip = ': ' + $.trim(this.regexes[matches[1]][0].toString());
detailedSkip = ': ' + $.trim(this.regexes[matches[1]][0].toString());
שורה 465: שורה 474:
}
}
for (i in this.regexes)
for (i in this.regexes)
if (!skip_dict[i] && !isNaN(i))
if (!chectTyTool.skip_dict[i] && !isNaN(i))
if (this.regexes[i][0].test(t)) {
if (this.regexes[i][0].test(t)) {
var before = t, tries=0, befText, afterText;
var before = t, tries=0, befText, afterText;
שורה 564: שורה 573:
// var emptyParametersRgx = /\n *\| *[^|=]+?= *(?=\n(?: *\||\}\}))/mg, emptyParametersMsg, emptyParametersBtn;
// var emptyParametersRgx = /\n *\| *[^|=]+?= *(?=\n(?: *\||\}\}))/mg, emptyParametersMsg, emptyParametersBtn;
$(this.formatReplacesConfigSafe).each(function (i, o) {
$(this.formatReplacesConfigSafe).each(function (i, o) {
newTxt = txt.replace(o.from, o.to);
newTxt = txt.replace(o.from, o.to);
if ( newTxt!=txt && o.comment) {
if ( newTxt!=txt && o.comment) {
שורה 581: שורה 591:
$(this.formatReplacesConfig).each(function (i, o) {
$(this.formatReplacesConfig).each(function (i, o) {
newTxt = txt.replace(o.from, o.to);
newTxt = txt.replace(o.from, o.to);
if (o.skippable && (chectTyTool.skipCheckty || this.isSection)) return; // skip this one respecting {ללא בוט}
if ( newTxt!=txt && o.comment) {
if ( newTxt!=txt && o.comment) {
chectTyTool.addSummary( o.comment );
chectTyTool.addSummary( o.comment );
שורה 1,059: שורה 1,070:
var wikitext = this.textbox.value,
var wikitext = this.textbox.value,
defaultDir = (/{{הערות שוליים *\| *יישור *= *שמאל}}/.exec( wikitext ))? 'ltr' : 'rtl',
defaultDir = (/{{הערות שוליים *\| *יישור *= *שמאל}}/.exec( wikitext ))? 'ltr' : 'rtl',
ltrRefRegex = /\{\{הערה\|(?!שם ?=)(?:1= *)?(?! *\[?https?:\/\/[^ ]+\]? *\}\})( *\[?[a-z][^א-ת{|]+?)\}\}/ig,
ltrRefRegex = /\{\{הערה\|(?:שם ?=[^|]*\|)?(?:1= *)?(?! *\[?https?:\/\/[^ ]+\]? *\}\})( *\[?[a-z][^א-ת{|]+?)\}\}/ig,
rtlRefRegex = /\{\{הערה\|(?!שם ?=)(?:1= *)?([א-ת][^a-z{|]+?|\[http:[^ ]+ [א-ת][^a-z{|]+?)\}\}/ig,
rtlRefRegex = /\{\{הערה\|(?!שם ?=)(?:1= *)?([א-ת][^a-z{|]+?|\[http:[^ ]+ [א-ת][^a-z{|]+?)\}\}/ig,
nonDefaultRefRegex = (defaultDir == 'rtl') ? ltrRefRegex : rtlRefRegex,
nonDefaultRefRegex = (defaultDir == 'rtl') ? ltrRefRegex : rtlRefRegex,
שורה 1,070: שורה 1,081:
var specificRefRgx = new RegExp('\\[\\[('+mw.util.escapeRegExp($(this).data('search'))+')(\\]\\]|\\|).+\\[\\[\\1(\\]\\]|\\|.+?\\]\\])', 'g'),
var specificRefRgx = new RegExp('\\[\\[('+mw.util.escapeRegExp($(this).data('search'))+')(\\]\\]|\\|).+\\[\\[\\1(\\]\\]|\\|.+?\\]\\])', 'g'),
wikitext = $('#wpTextbox1').val();
wikitext = $('#wpTextbox1').val();
wikitext = wikitext.replace($(this).data('search'), $(this).data('search').replace('}}', '|'+uncommonDir+'=כן}}'));
wikitext = wikitext.replace($(this).data('search'), $(this).data('search').replace('}}', '|כיוון='+uncommonDir+'}}'));
$('#wpTextbox1').val(wikitext);
$('#wpTextbox1').val(wikitext);
chectTyTool.addSummary('תיקון כיווניות הערת שוליים');
chectTyTool.addSummary(mw.msg('checkty-ref-dir-fix'));
e.preventDefault();
e.preventDefault();
});
});
שורה 1,310: שורה 1,321:
addAuthorityControl: function(v) {
addAuthorityControl: function(v) {
var t = this.textbox.value,
var t = this.textbox.value,
viafTemplate = /\{\{בקרת זהויות[\}|]/g,
acTemplate = /\{\{בקרת זהויות[\}|]/g,
bookAuthor = /== *(?:מ?ספרי[הו]|חיבורי[וה]) *==/;
artsTitle = /== *(?:מ?ספרי[הו]|מ?יצירותי[הו]|מ?חיבורי[הו]|פילמוגרפיה.*|(?:מבחר)? (?:כתבי)|דיסקוגרפיה|יצירות) *==/, //cheap hint for art occuption in text
if ( viafTemplate.exec( t ) ) return; // viaf already exist
artsCategory = /\[\[קטגוריה:(מוזיקאיות|מוזיקאים|זמרות|זמרים|סופרים|סופרות|ציירות|ציירים|במאי|רבנים|רבניות)(?!.+\*)/; //cheap hint for art occuption in category
if ( !bookAuthor.exec( t ) ) return; // no hint to be in viaf
if ( acTemplate.exec( t ) ) return; // AC already exist
if ( !artsTitle.exec( t ) && !artsCategory.exec( t ) ) return; // no hint will have authority control
this.getWikidataApi().get({
this.getWikidataApi().get({
action: 'wbgetentities',
action: 'wbgetentities',
שורה 1,322: שורה 1,334:
}).done(function(d){
}).done(function(d){
var hasAC = false,  
var hasAC = false,  
authControlProps = ['P214', 'P244', 'P213', 'P496', 'P227', 'P906', 'P269', 'P268', 'P651', 'P1053', 'P1015', 'P245', 'P1157'],
authControlProps = [ 'P3372', 'P864', 'P1907', 'P6804', 'P2558', 'P4186', 'P3293', 'P1015', 'P2092', 'P1890', 'P950', 'P268', 'P428', 'P651', 'P1273', 'P271', 'P1908', 'P1707', 'P2456', 'P2349', 'P6792', 'P227', 'P902', 'P1146', 'P396', 'P1736', 'P213', 'P347', 'P1248', 'P244', 'P886', 'P1368', 'P640', 'P434', 'P982', 'P1330', 'P966', 'P1004', 'P436', 'P1407', 'P435', 'P549', 'P1225', 'P1048', 'P349', 'P2041', 'P691', 'P409', 'P3348', 'P949', 'P5034', 'P1695', 'P1003', 'P1375', 'P1006', 'P496', 'P2750', 'P1053', 'P3065', 'P650', 'P350', 'P947', 'P906', 'P781', 'P3430', 'P269', 'P4012', 'P1323', 'P7314', 'P1693', 'P3544', 'P1694', 'P1362', 'P1315', 'P6213', 'P245', 'P1157', 'P8034', 'P214', 'P7859' ],
entityId, entity;
entityId, entity;
for (entityId in d.entities) { entity = d.entities[entityId]; };
for (entityId in d.entities) { entity = d.entities[entityId]; };
שורה 1,330: שורה 1,342:
if (hasAC) {
if (hasAC) {
chectTyTool.addAuthorityControlTemplate();
chectTyTool.addAuthorityControlTemplate();
}
if (entity.hasOwnProperty('claims') && entity.claims.hasOwnProperty('P214')) {
return;
}
}
chectTyTool.viafSearch(entity, entityId, hasAC);
chectTyTool.viafSearch(entity, entityId, hasAC);
שורה 1,338: שורה 1,347:
},
},
viafSearch: function(entity, entityId, hasAC){
viafSearch: function(entity, entityId, hasAC){
if (entity.hasOwnProperty('claims') && entity.claims.hasOwnProperty('P214')) {
return;
}
$.getJSON('https://www.viaf.org/viaf/AutoSuggest?callback=?&' + $.param({query: mw.config.get('wgTitle').replace(/ \([^()]+\)$/, '')})).done( function(d) {  
$.getJSON('https://www.viaf.org/viaf/AutoSuggest?callback=?&' + $.param({query: mw.config.get('wgTitle').replace(/ \([^()]+\)$/, '')})).done( function(d) {  
if (!d.result || d.result.length === 0) return;
if (!d.result || d.result.length === 0) return;
שורה 1,390: שורה 1,402:
newText;
newText;
if ( viafTemplate.exec( t ) ) return; // viaf already exist
if ( viafTemplate.exec( t ) ) return; // viaf already exist
newText = t.replace(/{{מיון רגיל:/, '{{בקרת זהויות}}\n{{מיון רגיל:');
newText = t.replace(/{{קצרמר/, '{{בקרת זהויות}}\n{{קצרמר'); // before stub
if (newText == t) newText = t.replace(/\[\[קטגוריה:/, '{{בקרת זהויות}}\n[[קטגוריה:');
if (newText == t) newText = t.replace(/{{מיון רגיל:/, '{{בקרת זהויות}}\n{{מיון רגיל:'); //before default sort
if (newText == t) newText = t.replace(/\[\[קטגוריה:/, '{{בקרת זהויות}}\n[[קטגוריה:'); // before categories
if (newText == t) newText = t += '\n{{בקרת זהויות}}';
if (newText == t) newText = t += '\n{{בקרת זהויות}}';
this.textbox.value = newText;
this.textbox.value = newText;
משתמש אלמוני