// Log filter script, from ]
// Created by ] & amended ]
// Huwiki version/A magyar Wikipédia használatára átdolgozta: Tgr
/* <li> element Filter Script, version
* Should currently work on all known skins (with a #contentSub or #topbar)
*/
var LogFilter = window.LogFilter || {};
$.extend(LogFilter, {
msg: {
linkText: 'Szűrés',
linkTooltip: 'A lista szűrése reguláris kifejezésekkel',
instructionsGeneral: 'A lista szöveges változatát szűrheted →reguláris kifejezésekkel.',
instructionsRights: 'Regex filter the space-delimited list of rights.',
legend: '<li> tagekkel tagolt lista szűrése (javascript)',
optionAddedRights: 'added rights',
optionRemovedRights: 'removed rights',
optionAddedOrRemoved: 'added OR removed',
optionARS: 'added/removed/static',
regexLabel: ' Reguláris kifejezés: ',
invertLabel: 'Megfordítás ',
filterLabel: 'Szűrés',
highlightLabel: 'Kiemelés'
},
// rightRegexp: /^.*?User\:.*? from (.*?) to (.*?) \u200E.*?$/i, //the regex used to grab the Special:Log/rights changes
rightRegexp: /^.*?szerkesztő felhasználó jogait \(régi: (.*?); új: (.*?)\).*$/i,
enabledSpecialPages: ,
init: function() {
LogFilter.isRightsLog =
(document.location.href.indexOf('type=rights') != -1)
|| (mw.config.get('wgPageName').indexOf('/rights') != -1);
if (
mw.config.get('wgAction') == 'history'
|| $.inArray(mw.config.get('wgCanonicalSpecialPageName'), LogFilter.enabledSpecialPages) > -1
|| queryString('lifilter')
) {
$(LogFilter.filterLiButton);
}
},
filterLiButton: function() {
if ($('#p-cactions').length) {
mw.util.addPortletLink('p-cactions', '#', LogFilter.msg.linkText, 'ca-rxfilter', LogFilter.msg.linkTooltip);
$('#ca-rxfilter').click(LogFilter.filterLiForm);
if(LogFilter.AutoLoadLogsFilter || queryString('lifilter')) {
LogFilter.filterLiForm();
}
} else {
LogFilter.filterLiForm(); //not a portlet skin, so add the filter anyway.
}
},
filterLiForm: function() {
var instructions = (LogFilter.isRightsLog) ? LogFilter.msg.instructionsRights : LogFilter.msg.instructionsGeneral;
//generate the form
$('#ca-rxfilter').css('display', 'none');
var parent = $('#contentSub');
if (!parent.length) {
parent = $('#topbar');
}
if (!parent.length) {
return;
}
var fieldset = $('<fieldset>');
$('<p>').text(instructions).appendTo(fieldset);
$('<legend>').text(LogFilter.msg.legend).appendTo(fieldset);
if (LogFilter.isRightsLog) {
var select = $('<select>').attr({id: 'rfselect'}).appendTo(fieldset);
$.each([
LogFilter.msg.optionAddedRights,
LogFilter.msg.optionRemovedRights,
LogFilter.msg.optionAddedOrRemoved,
LogFilter.msg.optionARS
], function(i, text) {
$('<option>').val(i).text(text).appendTo(select);
});
}
$('<label>').attr('for', 'rfinput1').text(LogFilter.msg.regexLabel).appendTo(fieldset);
fieldset.append(' ');
$('<input>').attr({id: 'rfinput1', name: 'rfinput1', type: 'text'}).appendTo(fieldset);
$('<input>').attr({id: 'rfinput2', name: 'rfinput2', type: 'checkbox'}).appendTo(fieldset);
$('<label>').attr('for', 'rfinput2').text(LogFilter.msg.invertLabel).appendTo(fieldset);
$('<input>').attr({type: 'button', value: LogFilter.msg.filterLabel}).appendTo(fieldset).click(function() {
LogFilter.filterLi(false);
});
fieldset.append(' ');
$('<input>').attr({type: 'button', value: LogFilter.msg.highlightLabel}).appendTo(fieldset).click(function() {
LogFilter.filterLi(true);
});
$('<div>').attr({id: 'rfform'}).css({color: 'black'}).append(fieldset).appendTo(parent);
},
filterLi: function(highlight) {
//grab options from form
if (LogFilter.isRightsLog) {
var type = parseInt($('#rfselect').val());
}
var invert = $('#rfinput2').is(':checked');
var regexp = new RegExp($('#rfinput1').val(), 'ig');
//grab the list of all <li> in the content
var body = $('#bodyContent');
if (!body.length) {
body = $('body');
}
var lis = body.find('li');
if (!lis.length) {
return;
}
//iterate
var hidden = $();
lis.each(function(i, element) {
var li = $(element);
if (LogFilter.isRightsLog) {
var oldr = li.text().replace(LogFilter.rightRegexp, '$1').replace(/\, /g, ' ');
var newr = li.text().replace(LogFilter.rightRegexp, '$2').replace(/\, /g, ' ');
var oldrl = oldr.split(' ');
var newrl = newr.split(' ');
for (var j = 0; j < oldrl.length; j++) {
for (var k = 0; k < newrl.length; k++) {
if (oldrl == newrl) {
oldrl = newrl = '';
}
}
}
var remr = oldrl.join(' ');
var addr = newrl.join(' ');
switch(type) {
case 0: var look = addr; break;
case 1: var look = remr; break;
case 2: var look = remr + ' ' + addr; break;
case 3: var look = oldr + ' ' + newr; break;
}
} else {
//Any other list of <li> objects
var look = li.text();
}
var match = (look.search(regexp) != -1);
var selected = match ^ invert;
if (highlight) {
li.css('backgroundColor', selected ? '#ffff99' : '');
} else {
li.css('backgroundColor', '');
if (!selected) {
hidden = hidden.add(li);
}
}
});
lis.show();
hidden.hide();
}
});
LogFilter.init();
function queryString(p) {
var re = RegExp('' + p + '=(*)');
var matches;
if (matches = re.exec(document.location)) {
try {
return decodeURI(matches);
} catch (e) {
}
}
return null;
}