MediaWiki:Gadget-rightsfilter.js
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/** * Log filter script * * Created by [[w:User:Splarka|Splarka]] * Amended by [[b:User:Mike.lifeguard]] & [[User:Lupo]] * Partially rewritten by DieBuche * * <li> element Filter Script, version [0.2] * Should currently work on all known skins (with a #contentSub or #topbar) * * mw.util.wikiGetlink( 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 <li> 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' }, }, 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 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 = $( '<fieldset id="rightsFilter"></fieldset>' ).text( instructions ); $legend = $( '<legend></legend>' ).text( mw.msg( 'filter-legend' ) ); $fieldSet.append( $legend ); fieldsetHtml = ''; if ( this.rightsLogOnly ) { fieldsetHtml += '<select id=rfSelect>'; fieldsetHtml += '<option>' + mw.html.escape(mw.msg( 'filter-option-added' )) + '</option>'; fieldsetHtml += '<option>' + mw.html.escape(mw.msg( 'filter-option-removed' )) + '</option>'; fieldsetHtml += '<option>' + mw.html.escape(mw.msg( 'filter-option-added-or-removed' )) + '</option>'; fieldsetHtml += '<option>' + mw.html.escape(mw.msg( 'filter-option-added-removed-static' )) + '</option>'; fieldsetHtml += '</select>'; } fieldsetHtml += '<label for="rfRegex">' + mw.html.escape(mw.msg( 'filter-regex-label' )) + '</label><input id="rfRegex">'; fieldsetHtml += '<input id="rfInvert" type="checkbox"><label for="rfInvert">' + mw.html.escape(mw.msg( 'filter-invert-label' )) + '</label>'; fieldsetHtml += '<input id="rfCase" type="checkbox"><label for="rfCase">' + mw.html.escape(mw.msg( 'filter-case-label' )) + '</label>'; fieldsetHtml += '<button type="button" value="0">' + mw.html.escape(mw.msg( 'filter-filter-button' )) + '</button>'; fieldsetHtml += '<button type="button" value="1">' + mw.html.escape(mw.msg( 'filter-highlight-button' )) + '</button>'; fieldsetHtml += '<br/><a href="javascript:filterLists.getURL(true)">' + mw.html.escape(mw.msg( 'filter-link-text' )) + '</a>'; // 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 <li> 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(/^(Contributions|LinkSearch|Log|Newpages|Recentchanges|Listredirects|Listusers|Nuke|Whatlinkshere)$/i) ) ) { filterLists.load(); } }); } // end if guard