User:Yamaha5/lifilter.js

/** * Log filter script * * Created by Splarka * Amended by b:User:Mike.lifeguard & User:Lupo * Partially rewritten by DieBuche * *  element Filter Script, version [0.2] * Should currently work on all known skins (with a #contentSub or #topbar) * * mw.util.getUrl( mw.config.get( 'wgPageName' ) ) + '?' + * 'withJS=MediaWiki:Gadget-rightsfilter.js&lifilter=1&lifilterexpr=TEST&lifiltercase&lifilterhilight&lifilterinv' */ // Guard against double inclusions if ( typeof filterLists === 'undefined' ) { window.filterLists = { i18n: { 'en': { 'filter-portlet-text': 'Filter', 'filter-portlet-description': 'Open interactive log entry regex filter thingy', 'filter-gadget-page': 'MediaWiki:Gadget-rightsfilter.js', 'filter-rights-list-instructions': 'Regex filter the space-delimited list of rights.', 'filter-other-list-instructions': 'Regex filter the plain text representation of this list.', 'filter-legend': 'Filter  list', 'filter-option-added': 'Added rights', 'filter-option-removed': 'Removed rights', 'filter-option-added-or-removed': 'Added OR removed', 'filter-option-added-removed-static': 'Added/removed/static', 'filter-regex-label': 'Regex string:', 'filter-invert-label': 'Invert', 'filter-case-label': 'Case insensitive', 'filter-filter-button': 'Filter', 'filter-highlight-button': 'Highlight', 'filter-link-text': 'Link to this filtered list' },	       'fa': { 'filter-portlet-text': 'فیلتر با عبارت باقاعده', 'filter-portlet-description': 'ابزار فیلتر کردن سیاهه به وسیله عبارت‌ باقاعده', 'filter-gadget-page': 'MediaWiki:Gadget-rightsfilter.js', 'filter-rights-list-instructions': 'عبارت باقاعده برای سیاهه اختیارات', 'filter-other-list-instructions': 'عبارت باقاعده متن‌ زیر را فیلتر می‌کند. ',			'filter-legend': 'فیلترکردن فهرست‌های دارای  به کمک عبارت باقاعده', 'filter-option-added': 'افزودن اختیارات', 'filter-option-removed': 'حذف اختیارات', 'filter-option-added-or-removed': 'افزودن یا حذف', 'filter-option-added-removed-static': 'افزوده/حذف‌شده/وضعیت', 'filter-regex-label': "متن عبارات باقاعده:", 'filter-invert-label': 'معکوس ', 'filter-case-label': 'موارد حساس ', 'filter-filter-button': 'فیلتر', 'filter-highlight-button': 'پررنگ کردن', 'filter-link-text': 'پیوند به فهرست‌ فیلتر شده' }	},	rightsLogOnly: (document.location.href.indexOf( 'type=rights' ) !== -1 || document.location.href.indexOf( 'Log/rights' ) !== -1), lastClicked: false, load: function { var portletlink, int = filterLists.i18n.en;

// Define language fallbacks filterLists.i18n['pt-br'] = filterLists.i18n.pt;

// Replace default English interface by translation if available $.extend( true, int, filterLists.i18n[ mw.config.get( 'wgUserLanguage' ) ] );

// Define interface messages mw.messages.set( int );

// Create portlet link portletlink = mw.util.addPortletLink(			'p-cactions',			'#',			mw.msg( 'filter-portlet-text' ),			'ca-rxfilter',			mw.msg( 'filter-portlet-description' )		); // Bind click handler $(portletlink).click( function( e ) {			e.preventDefault;			filterLists.buildForm;		}); // Display form direclty ? if ( window.AutoLoadLogsFilter || mw.util.getParamValue( 'lifilter' ) || mw.util.getParamValue( 'lifilterexpr' ) ) { filterLists.buildForm; }	},

getURL: function( showPopUp ) { var	data = { withJS: mw.msg( 'filter-gadget-page' ), lifilter: '1', lifilterexpr: $( '#rfRegex' ).val },			url = window.location.href; if ( !$( '#rfCase' ).attr( 'checked' ) ) { data.lifiltercase = '1'; }		if ( this.lastClicked == '1' ) { data.lifilterhilight = '1'; }		if ( $( '#rfInvert' ).attr( 'checked' ) ) { data.lifilterinv = '1'; }		url += ( url.indexOf( '?' ) !== -1 ? '&' : '?' ) + $.param( data ); if ( showPopUp ) { prompt( '', url ); } else { return url; }	},

buildForm: function { var	value, casing, inverted, fieldsetHtml, $pageTop, $fieldSet, $legend, $sel, instructions = this.rightsLogOnly ? mw.msg( 'filter-rights-list-instructions' ) : mw.msg( 'filter-other-list-instructions' );

$( '#ca-rxfilter' ).hide; $pageTop = $( '#contentSub, #topbar' ); if ( !$pageTop.length ) { return; }

// Set up config value = mw.util.getParamValue( 'lifilterexpr' ); casing = mw.util.getParamValue( 'lifiltercase' ) == '1'; inverted = mw.util.getParamValue( 'lifilterinv' ) == '1';

// Generate the form $fieldSet = $( ' ' ).text( instructions ); $legend = $( ' ' ).text( mw.msg( 'filter-legend' ) ); $fieldSet.append( $legend ); fieldsetHtml = '';

if ( this.rightsLogOnly ) { fieldsetHtml += ''; fieldsetHtml += ' ' + mw.html.escape(mw.msg( 'filter-option-added' )) + ' '; fieldsetHtml += ' ' + mw.html.escape(mw.msg( 'filter-option-removed' )) + ' '; fieldsetHtml += ' ' + mw.html.escape(mw.msg( 'filter-option-added-or-removed' )) + ' '; fieldsetHtml += ' ' + mw.html.escape(mw.msg( 'filter-option-added-removed-static' )) + ' '; fieldsetHtml += ' '; }		fieldsetHtml += '' + mw.html.escape(mw.msg( 'filter-regex-label' )) + ' '; fieldsetHtml += '' + mw.html.escape(mw.msg( 'filter-invert-label' )) + ' ';

fieldsetHtml += '' + mw.html.escape(mw.msg( 'filter-case-label' )) + ' '; fieldsetHtml += '' + mw.html.escape(mw.msg( 'filter-filter-button' )) + ' '; fieldsetHtml += '' + mw.html.escape(mw.msg( 'filter-highlight-button' )) + ' '; fieldsetHtml += ' ' + mw.html.escape(mw.msg( 'filter-link-text' )) + '';

// Inject the html into the fieldset $fieldSet.append( fieldsetHtml );

$pageTop.after( $fieldSet );

// Set passed values $( '#rfRegex ' ).val( value ); $( '#rfCase' ).attr( 'checked', !casing ); $( '#rfInvert' ).attr( 'checked', inverted ); $( '#rfRegex' ).focus;

// Bind click and change handlers $( '#rightsFilter' ).find( 'input' ).bind( 'keyup change', function(e) {			filterLists.filterLi;		}); $fieldSet.find( 'button' ).click( function(e) {			filterLists.lastClicked = $(this).val;			filterLists.filterLi;		});

if ( value ) { this.filterLi( mw.util.getParamValue( 'lifilterhilight' ) == '1' ); }	},

filterLi: function(hilight) { var type, invert, search, flags, rx, listItems, rightrx;

// Grab options from form if ( this.rightsLogOnly ) { type = $( '#rfSelect' ).attr( 'selectedIndex' ); }		invert = $( '#rfInvert' ).attr( 'checked' ); search = $( '#rfRegex' ).val; flags = $( '#rfCase' ).attr( 'checked' ) ? 'ig' : 'g'; hilight = ( hilight || this.lastClicked == '1' ) ? true : false;

try{ rx = new RegExp( search, flags ); } catch (err){ mw.log( err ); }

// Grab the list of all  in the content listItems = $( '#bodyContent' ).find( 'li' ); if ( !listItems.length ) { return; }

// The regex used to grab the Special:Log/rights changes rightrx = /^.*?User\:.*? from (.*?) to (.*?) \u200E.*?$/i;

// Iterate listItems.each(function {			var look, oldr, newr, oldrl, newrl, remr, addr,				$this = $(this);

if ( this.rightsLogOnly ) { // Special:Log/rights oldr = $this.text.replace(rightrx, '$1' ); newr = $this.text.replace(rightrx, '$2' ); oldrl = oldr.split( ', ' ); newrl = newr.split( ', ' ); for ( var j = 0; j < oldrl.length; j++ ) { for ( var k = 0; k < newrl.length; k++ ) { if ( oldrl[j] == newrl[k] ) { oldrl[j] = ''; newrl[k] = ''; }					}				}				remr = oldrl.join; addr = newrl.join; switch (type) { case 0: look = addr; break; case 1: look = remr; break; case 2: look = remr + ' ' + addr; break; case 3: look = oldr + ' ' + newr; break; }			} else { //Any other list of <li> objects look = $this.text; }			$this.show; $this.css( 'background-color', '' ); if ( ( look.search( rx ) !== -1 && !invert ) || ( look.search( rx ) === -1 && invert ) ) { if ( hilight ) { $this.css( 'background-color', '#ffff99' ); }			} else { if ( !hilight ) { $this.hide; }			}		});	} };

// When to enable all this $( document ).ready( function {	if ( mw.config.get( 'wgAction' ) === 'history' || mw.util.getParamValue( 'lifilter' ) || (			mw.config.get( 'wgCanonicalSpecialPageName' )			&& mw.config.get( 'wgCanonicalSpecialPageName' ).match(/^(Activeusers|CheckUser|Contributions|Ipblocklist|LinkSearch|Log|Search|(Uncategoriz|Unus|Want)ed(categori|templat)es|Wantedfiles|(Short|Long|Ancient|Uncategorized|Unwatched|Wanted|Protected|Deadend|Lonely|New)pages|Fewestrevisions|Withoutinterwiki|(Double|Broken)Redirects|Protectedtitles|CrossNamespaceLinks|Recentchanges|Categories|Disambiguations|Listredirects|GlobalUsers|GlobalBlockList|Listusers|Watchlist|Most(linked|revisions|categories)|Nuke|Whatlinkshere)$/i)		) ) {		filterLists.load;	}

});

} // end if guard