MediaWiki talk:Gadget-rightsfilter.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search


lifilter[edit]

FYI, I've updated this to work on any page that has any <li> (and renamed it accordingly), and to work on demand via querystring as well. w:User:Splarka/lifilter.js. Splarka 06:10, 11 February 2008 (UTC)[reply]

Updated it again, to play nice on almost any page (via &lifilter=true url) and in any skin (in theory). Same link. Splarka 10:51, 24 February 2008 (UTC)[reply]


Typo and suggestion[edit]

Hello!

I've noticed there is a typo at this line:

if(wgAction == 'history' || wgCanonicalSpecialPageName == 'Search' || wgCanonicalSpecialPageName == 'Log'
|| wgCanonicalSpecialPageName == 'CheckUser' || wgCanonicalSpecialPageName == 'LinkSearch'
|| wgCanonicalSpecialPageName == 'Contributions' || wgCanonicalSpecialPageName == 'IPBlockList' || queryString('lifilter'))
addOnloadHook(filterLiButton)

When we go to Special:IPBlockList, the variable wgCanonicalSpecialPageName has the value "Ipblocklist", with 'pb' instead of 'PB'.

Could you correct this? Helder 17:48, 29 October 2009 (UTC)

By the way, is it possible to "submit" the filter when the user press ENTER? Currently it is needed to click at the "Filter" button... I think this could be useful. Helder 17:48, 29 October 2009 (UTC)
By the way (2), I've made a translation of the messages to Portuguese, if you want to add it here... ;) Helder 17:56, 29 October 2009 (UTC)
✓ Done, first request done, for the other ones someone with more JavaScript knowledge is necessary. --The Evil IP address (talk) 22:17, 30 October 2009 (UTC)[reply]
Would it be possible to have the script filtering after the user press ENTER? Helder 21:06, 19 May 2010 (UTC)
✓ Done. Don't forget to reload your browser's cache. Lupo 07:12, 20 May 2010 (UTC)[reply]

Localization[edit]

Hi!

Could anyone please make the script localizable?

We already have the Portuguese translation ('pt' and 'pt-br') which could be incorpored in commons version too. Helder 20:22, 27 December 2010 (UTC)

By the way, in the translated version, the line became too long horizontally:

Could someone add a linebreak in the text of variable "instructions"?
Another option would be to move the text of that variable to the caption:
$legend.text('Filter <li> list: ' + instructions );
Helder 20:42, 27 December 2010 (UTC)

I would also be glad, if the gadget could be localized. It is also offered as a gadget in de.wikipedia. --Leyo 16:45, 21 September 2012 (UTC)[reply]

Then please translate the following:
		'de': {
			'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'
		}
-- Rillke(q?) 13:48, 26 September 2012 (UTC)[reply]
I must have missed the edits in August 2011, sorry. I added the de version myself. --Leyo 15:12, 26 September 2012 (UTC)[reply]
The fallback for de-at, de-ch and de-formal does not currently work. What can be done without repeating the whole thing for all of them? --Leyo 15:18, 26 September 2012 (UTC)[reply]

Missing parenthesis[edit]

{{editprotected}}

Hi!

It seems to be missing some parenthesis around this code:

	if (wgAction == 'history' || wgCanonicalSpecialPageName && 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) || getParamValue('lifilter')) {

It should be

	if (wgAction == 'history' || (wgCanonicalSpecialPageName && 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)) || getParamValue('lifilter')) {

Could someone add them, please? Helder 14:00, 9 January 2011 (UTC)

✓ Done http://commons.wikimedia.org/wiki/?diff=53522120Krinkletalk 20:10, 23 April 2011 (UTC)[reply]

JS Errors[edit]

{{editprotected|technical=yes}} The script is generating the error

trailing \ in regular expression
http://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-rightsfilter.js&action=raw&ctype=text/javascript&283-19
Line 85

when I start to fill in the form with the regex "\d", because it try to use "\" as a regex.

I think if the code of filterLi() or

$('#rightsFilter input').bind('keyup change', function () {
	filterLists.filterLi();
});

validated the input to see if it is a valid regular expression this error wouldn't happen.

Could someone fix it? Helder 14:35, 9 January 2011 (UTC)

Backward compatibilities[edit]

{{editprotected|technical=yes}} Hi!

I would like to know if it is really wanted that this edit breaks old links in which there was no 'lifilter' parameter needed to activate the form when clicking in the links. For example:

Could it check for the presence of any of the accepted parameters to decide if the form should be shown (instead of checking by &lifilter=1)? Helder 15:04, 9 January 2011 (UTC)

 Not done This has been open for 6 months - let's admit it isn't going to be fulfilled. I suggest following it up by posting at COM:VP or approaching a user directly who might be able to help. Rd232 (talk) 10:55, 20 July 2011 (UTC)[reply]

Links to filtered lists[edit]

Hi!

Could some admin replicate this update to the original script? It adds a link which the user can use to get a url to the filtered list, making it easier to share specific sublists of logs and other pages. Helder 21:07, 16 May 2011 (UTC)

Update[edit]

{{editprotected}}

Hello! Could someone apply these changes to the script? The new version includes fixes to the problems mentioned in the sections above (i18n, bug fixes, backward compatibility, button to get links to filtered lists ). Feel free to add other translations as well. Helder 04:15, 13 August 2011 (UTC)

✓ Done. Also made an additional edit:
  • Whitespace consistency
    • separate conditions and the condition-wrapper with a space from the "if" keyword
    • no space between the function and the callee (whether or not with arguments). This makes it easy to see if something is a function or a block.
  • Double quotes/single quotes
  • HTML escaping!
    • jQuery.fn.append is appending HTML, not text. Input has to be escaped before hand (or use .text() if possible) with mw.html.escape().
    • When creating a new element, insert text with .text() instead of .append().
    • Including cases like $( foo ).append( '<option>' + mw.msg( 'bar' ) + '</option>' );,
      those should be $( foo ).append( '<option>' + mw.html.escape( mw.msg( 'bar' ) ) + '</option>' );
      or perhaps: $( foo ).append( $('<option>').text( mw.msg( 'bar' ) ) );.
      From MediaWiki 1.18 onwards, the following has become possible as well: $( foo ).append( '<option>' + mw.message( 'bar' ).escaped() + '</option>' );.
      But some kind of escaping is required.
  • Removing unneeded parenthesis.
  • Using strict comparison (tripple equals)
  • Combining HTML fragments into a string before dom-manipulation (eg. combining a bunch of ‎<option> tags in 1 string and calling .append() only once, instead of parsing HTML many times and appending the element to another element many times)
  • Some other minor performance improvements and good practices catched by JSHint.
Krinkletalk 12:02, 13 August 2011 (UTC)[reply]
Followup:
  • There is a small typo in the code: 'filter-othe-list-instructions' should be 'filter-other-list-instructions'.
  • It seems necessary to change the parameters in the gadgets-definition from [ResourceLoader] to [ResourceLoader|dependencies=mediawiki.util], to avoid problems when mw.util.getParamValue and mw.util.addPortletLink are used.
  • The <br> tag was in the Portuguese translation intentionally (see #Localization), but I think it is better to move it to a place such as $fieldSet, where it would be added to all translations.
Thanks for improving the script.
PS: what about adding translations for 'nl' and 'de'? ;-) Helder 12:37, 13 August 2011 (UTC)
Typo in message key fixed, dependencies added (this bug is fixed in MediaWiki 1.19 btw, but is not backportable to MediaWiki 1.17). I didn't add the ‎<br> though, the code has changed since the question at #Localization was asked. The line break is no longer needed since we have a separate ‎<fieldset> and ‎<legend> now. –Krinkletalk 14:18, 13 August 2011 (UTC)[reply]

Galician translation[edit]

{{editprotected}} Please add the following translation to the gadget:

		'gl': {
			'filter-portlet-text': 'Filtro',
			'filter-portlet-description': 'Abrir un filtro interactivo baseado en expresións regulares',
			'filter-gadget-page': 'MediaWiki:Gadget-rightsfilter.js',
			'filter-rights-list-instructions': 'Filtra a lista de dereitos, separados por espazos, mediante unha expresión regular.',
			'filter-other-list-instructions': 'Filtra a representación desta lista, en texto sen formato, mediante unha expresión regular.',
			'filter-legend': 'Filtro para listas <li>',
			'filter-option-added': 'Dereitos engadidos',
			'filter-option-removed': 'Dereitos eliminados',
			'filter-option-added-or-removed': 'Engadido OU eliminado',
			'filter-option-added-removed-static': 'Engadido/eliminado/estático',
			'filter-regex-label': 'Cadea de expresión regular:',
			'filter-invert-label': 'Inverter',
			'filter-case-label': 'Sen distinción entre maiúsculas e minúsculas',
			'filter-filter-button': 'Filtrar',
			'filter-highlight-button': 'Resaltar',
			'filter-link-text': 'Ligazón cara a esta lista filtrada'
		}

Thanks! --Toliño Fala aquí comigo 12:16, 25 August 2011 (UTC)[reply]

✓ Done --Mormegil (talk) 11:04, 26 August 2011 (UTC)[reply]

blank missing[edit]

A blank is missing in Regex filter the plain text representation of this list.Regex string:, i.e. between the two variables. --Leyo 21:02, 26 August 2011 (UTC)[reply]

This seems to be the same problem reported above, and it seems to be fixed in the current version. Could you update your cache and see if the problem persists? Helder 20:09, 29 August 2011 (UTC)
Purging the cache does not change anything for me. --Leyo 20:17, 29 August 2011 (UTC)[reply]
For me, there's no blank after the period either (FF 3.6.4, monobook and vector). And as far as I can see, there's no reason why there should be one with the current script. The script should probably use fieldsetHtml += '&nbsp;<label for="rfRegex">' ... instead of fieldsetHtml += '<label for="rfRegex">' ... to force a blank between the filter-legend and the filter-regex-label texts. Lupo 20:43, 29 August 2011 (UTC)[reply]

fa.wiki[edit]

please add this text for farsi

		'fa': {
			'filter-portlet-text': 'پالایه',
			'filter-portlet-description': 'بازکردن سیاهه ورودی پالایه عبارات باقائده',
			'filter-gadget-page': 'MediaWiki:Gadget-rightsfilter.js',
			'filter-rights-list-instructions': 'فهرست قوائد بدون فاصله‌ٔ عبارات باقائده.',
			'filter-other-list-instructions': 'فهرست قوائد بدون فاصله‌ٔ عبارات باقائده به صورت متنی.',
			'filter-legend': 'فهرست <li> پالایه',
			'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': 'پیوند به فهرست این پالایه'
		},

Reza1615 (talk) 21:25, 14 February 2013 (UTC)[reply]

✓ 'Done' ■ MMXX talk 21:16, 17 February 2013 (UTC)[reply]

Spanish traslantion[edit]

{{Edit request}}

		'es': {
			'filter-portlet-text': 'Filtro',
			'filter-portlet-description': 'Abrir un filtro interactivo basado en expresiones regulares',
			'filter-gadget-page': 'MediaWiki:Gadget-rightsfilter.js',
			'filter-rights-list-instructions': 'Filtra la lista de derechos, separados por espacios, mediante una expresión regular.',
			'filter-other-list-instructions': 'Filtra la representación de esta lista, en texto sin formato, mediante una expresión regular.',
			'filter-legend': 'Filtro para listas <li>',
			'filter-option-added': 'Derechos añadidos',
			'filter-option-removed': 'Derechos eliminados',
			'filter-option-added-or-removed': 'Añadido O eliminado',
			'filter-option-added-removed-static': 'Añadido/eliminado/estático',
			'filter-regex-label': 'Cadena de expresión regular:',
			'filter-invert-label': 'Invertir',
			'filter-case-label': 'Sin distinción entre mayúsculas y minúsculas',
			'filter-filter-button': 'Filtrar',
			'filter-highlight-button': 'Resaltar',
			'filter-link-text': 'Enlace a esta lista filtrada'
		},

Please add this translation --Vivaelcelta {talk  · contributions} 21:41, 15 March 2013 (UTC)[reply]

✓ Done -- Rillke(q?) 20:51, 5 April 2013 (UTC)[reply]

Performance improvement[edit]

{{Editprotected}}

Hi!

Could someone make this update to the script? Helder 17:48, 11 February 2014 (UTC)

✓ Done, thank you. -- Rillke(q?) 07:02, 26 February 2014 (UTC)[reply]

Latvian translation[edit]

{{Editprotected}}

		'lv': {
			'filter-portlet-text': 'Filtrs',
			'filter-portlet-description': 'Atvērt interaktīvu filtrēšanas logu',
			'filter-gadget-page': 'MediaWiki:Gadget-rightsfilter.js',
			'filter-rights-list-instructions': 'Regex filter the space-delimited list of rights.',
			'filter-other-list-instructions': 'Filtrēt vienkāršu tekstu.',
			'filter-legend': 'Filtrēt <li> sarakstu',
			'filter-option-added': 'Pievienotās tiesības',
			'filter-option-removed': 'Noņemtās tiesības',
			'filter-option-added-or-removed': 'Pievienots VAI noņemts',
			'filter-option-added-removed-static': 'Pievienots/noņemts/statisks',
			'filter-regex-label': 'Simbolu virkne:',
			'filter-invert-label': 'Izvēlēties pretēji',
			'filter-case-label': 'Bez reģistrjutības',
			'filter-filter-button': 'Filtrēt',
			'filter-highlight-button': 'Izcelt',
			'filter-link-text': 'Saite uz šo filtrēto sarakstu'
		},

Please add this translation. --Edgars2007 (talk) 11:25, 11 August 2014 (UTC)[reply]

✓ Done -- thanks for helping to localize Commons. -- Rillke(q?) 17:11, 11 August 2014 (UTC)[reply]

JQMIGRATE warning[edit]

Loading the page https://commons.wikimedia.org/w/index.php?title=Special:ListUsers&lifilter=1&debug=1 causes the following: JQMIGRATE: jQuery.fn.attr('checked') may use property instead of attribute. Helder 02:07, 14 August 2014 (UTC)[reply]

✓ Done (although I shouldn't be able right now) -- Rillke(q?) 08:38, 14 August 2014 (UTC)[reply]

Legacy JavaScript[edit]

Hello! This script has been detected as using deprecated parameters that need to be replaced with the updated version. Examples include addOnloadHook() needs to be replaced with $(); all wgGlobalVariables need to be properly gotten with mw.config.get( 'wgGlobalVariable' ); and addPortletLink needs to be called with mw.util.addPortletLink. Please see MW:ResourceLoader/Legacy JavaScript for details. Thank you. — {{U|Technical 13}} (etc) 21:55, 18 January 2015 (UTC)[reply]

Hello Technical 13 -- this post with its generic message is incredibly unhelpful. Neither does the this script contain wg globals, or addOnloadHook, nor addPortletLink. And the cited phabricator number in the edit summary is unhelpful too, linking to a generic ticket requesting configuration changes. -- Rillke(q?) 09:55, 19 January 2015 (UTC)[reply]
  • No worries Rillke. This is a page that came up in a search for pages containing "addOnloadHook" with a suffix of ".js" - By the looks of this talk page, that may have already been resolved. As such, I've removed the edit request template and taken it out of the special cat. Looking over the script, it still fails to meet the coding conventions, but that is in no way script breaking. Thanks pinging me to look it over! — {{U|Technical 13}} (etc) 14:50, 19 January 2015 (UTC)[reply]
  • @Technical 13: As long as there is no automated checking for coding conventions it makes absolutely no sense to enforce them or we can shut down community scripts entirely. Feel free to improve Commons:JavaScript styleguide and please do a more careful search; e.g. utilizing a database dump or dump all messages from API and parse the JavaScripts so you can exclude strings and comments. Thanks & Best -- Rillke(q?) 15:36, 19 January 2015 (UTC)[reply]
    • As I mentioned on my talk page (I'm getting lost in all this discussion fragmentation), the script ran exactly as intended and tagged the talk pages of all scripts where addOnloadHook was used in the script or mentioned on the talk page so that those pages could be gone over to look for other deprecations mentioned in the documentation. There were about 800 pages on this wiki and enwp has nearly 8,000 I need to get tagged before long. Anything more specific than the general message I included would have been even more confusing to the majority of users. I expected to get a lot of please help me messages on my talk page, and they are coming in on various wiki's I've run through to tag. — {{U|Technical 13}} (etc) 16:27, 19 January 2015 (UTC)[reply]
      • Specific messages on what to improve always make sense. Compile a list of deprecations, download a DB dump, parse the JavaScripts and compile messages for each page individually consisting of line numbers and the thing that is deprecated instead of this attempt of a catch-all whatever. Puzzled -- Rillke(q?) 16:32, 19 January 2015 (UTC)[reply]

Fix for enhanced recent changes[edit]

I really like this script, but it does not work for the enhanced recent changes, so I fixed it:
Replace

		listItems = $( '#bodyContent' ).find( 'li' );

with

		if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Recentchanges' ) {
			//enhanced recentchanges
			listItems = $( '#bodyContent' ).find( '.mw-enhanced-rc' );
		} else {
			//Any other list of <li> objects
			listItems = $( '#bodyContent' ).find( 'li' );
		}

Maybe not the best solution, but it works for me.--Baumgeist (talk) 09:45, 3 October 2016 (UTC)[reply]

Plus, you might want to replace
		fieldsetHtml += '<label for="rfRegex">' + mw.html.escape(mw.msg( 'filter-regex-label' )) + '</label><input id="rfRegex">';

with

		fieldsetHtml += '<label for="rfRegex">' + mw.html.escape(mw.msg( 'filter-regex-label' )) + '</label><input id="rfRegex" size="35">';

Makes using a regex for filtering much more comfortable.--Baumgeist (talk) 10:15, 3 October 2016 (UTC)[reply]

Not compatible with New filters for edit review[edit]

  1. Go to Special:Preferences#mw-prefsection-betafeatures
  2. Enable "New filters for edit review"
  3. Go to Special:Watchlist, with "lifilter=1" in the URL
Expected result
the fields for the filter is visible, because the URL includes "lifilter=1"
Actual result
the filter is not visible.

Helder 19:46, 12 January 2018 (UTC)[reply]

Looks like when the preference "Use non-JavaScript interface" is enabled, MediaWiki removes the element #contentSub which this gadget relies on. Helder 21:39, 16 January 2021 (UTC)[reply]

Gadget filters the wrong lists[edit]

Since gerrit:473144 was merged (for phab:T205581), the filter does not work as expected on w:pt:Special:Contributions/Salebot. It filters the lists ( diff | hist ) for each edit, instead of filtering the list of edits. Helder 13:04, 16 November 2018 (UTC)[reply]

zh-hans translation[edit]

{{Ep}}

'zh-hans': {
			'filter-portlet-text': '过滤',
			'filter-portlet-description': '打开交互式日志正则过滤器',
			'filter-gadget-page': 'MediaWiki:Gadget-rightsfilter.js',
			'filter-rights-list-instructions': '正则表达式过滤以空格分隔的权限列表。',
			'filter-other-list-instructions': '正则表达式过滤本列表的纯文本样式。',
			'filter-legend': '过滤<li>列表',
			'filter-option-added': '添加权限',
			'filter-option-removed': '删除权限',
			'filter-option-added-or-removed': '添加或删除权限',
			'filter-option-added-removed-static': 'Added/removed/static',
			'filter-regex-label': '正则表达式:',
			'filter-invert-label': '反选',
			'filter-case-label': '大小写敏感',
			'filter-filter-button': '过滤',
			'filter-highlight-button': '高亮',
			'filter-link-text': '分享链接'
		}
As I don't no what Added/removed/static means, I just leave it here. Thanks. Stang 14:54, 1 December 2021 (UTC)[reply]
✓ Done, but I commented out the untranslated line – as far as I can tell, the gadget code should be able to handle that. --Lucas Werkmeister (talk) 20:35, 1 December 2021 (UTC)[reply]