Обсуждение MediaWiki:Gadget-search-extraTooltips.js (KQvr';yuny MediaWiki&Gadget-search-extraTooltipsQjs)

Перейти к навигации Перейти к поиску

Improving the DWIM Gadget

[править код]

Привет

Sorry for writing in English. Пожалуйста, помогите перевести на ваш язык.

I saw that this gadget has been adapted from the Hebrew version. I believe it could be improved by removing the statement that lowercases the letter being mapped. In the Hebrew version, all Hebrew letters map to Latin letters, so lowercasing the Latin characters makes sense. In the Russian version, some Russian letters map to punctuation. Calling toLowerCase() on “:” does not give you “;”. It makes sense to fully map the relevant characters and not take the lowercase shortcut.

Examples like жэхэ/Жэхэ/ЖЭХЭ show the problem. If you type жэхэ on the wrong keyboard layout, you get ;'[' —which the Gadget can handle:

If you capitalize the first letter (tying to type Жэхэ), you get :'[' —which doesn’t work, because the first character (:) isn’t lowercased to (;) and so it is ignored:

If you try to type it in all caps (trying to type ЖЭХЭ), you get :"{" —which the gadget cannot do anything with:

The solution is to change the mapping to include uppercase characters and all relevant punctuation (line 1), remove the toLowerCase() call (line 4), and adjust the mapping math to 70/140 (line 6).

I’ve also included the [name=search] selector in the list of $searchBoxes, (line 11) which will also enable the gadget for search on the main input box on the Special:Search (Служебная:Поиск) page.

		var hes = "qwertyuiop[]asdfghjkl;'zxcvbnm,./`QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>?~#^йцукенгшщзхъфывапролджэячсмитьбю.ёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,Ё№:",
			hebeng = function ( str ) {
				return ( str || '' ).replace( /./g, function( c ) {
					var ic = hes.indexOf( c );

					return ic + 1 ? hes.charAt( ( ic + 70 ) % 140 ) : c;
				} );
			};
			
		var $searchBoxes = $(
			'#searchInput, #searchInput2, #powerSearchText, #searchText, [name=search]'
		);

I hope these changes can be made to improve the DWIM gadget. Спасибо! TJones (WMF) (обс.) 20:58, 20 ноября 2018 (UTC)[ответить]

+ За/Support/Pro. This is worked more corretly (checked in the Участник:Kaganer/Gadget-Dwim.js). --Kaganer (обс.) 12:30, 21 ноября 2018 (UTC)[ответить]
@Iniquity: - предлагаю внести предложенное изменение. --Kaganer (обс.) 12:31, 21 ноября 2018 (UTC)[ответить]
Thanks Джек! TJones (WMF) (обс.) 16:28, 21 ноября 2018 (UTC)[ответить]
@Джек: I don't think that's an error, though it is not necessarily what you want. When you type :"NA, the parser tries to get an exact match on a title, and if that fails, it normalizes the text, which in this case would be to just NA. It does the same thing for :"ЖЭ—it ignores the :" part. There are more than 10 results for NA, so it doesn't add any wrong-layout results. (Thanks for removing setTimeout, too! That looks like a better way to do it.) TJones (WMF) (обс.) 18:37, 21 ноября 2018 (UTC)[ответить]
I agree! Even if it is not an error, it is still a flaw, as you originally said. Detecting that case is harder, though. I think someone could type "NA on purpose, as part of "NASA", for example. Why would they use quotes? I don't know, but people sometimes do stuff we can't figure out. TJones (WMF) (обс.) 19:04, 21 ноября 2018 (UTC)[ответить]
@Джек: That's weird. I no longer get any wrong-layout suggestions in the main search box on the Special:Search page. Is it possible you had two scripts enabled at once? I don't have anything else enabled on Russian Wikipedia. Either way, thanks for keeping an eye on it! TJones (WMF) (обс.) 16:41, 22 ноября 2018 (UTC)[ответить]
  • > I no longer get any wrong-layout suggestions in the main search box on the Special:Search page.
    Yes, I had to switch those off.
    > Is it possible you had two scripts enabled at once?
    Nope, I don't think so. ...And these suggestion boxes looked differently. Note that the search bar above the content area and the search bar on Special:Search page look differently, and if you try to run the script on Special:Search as well, you would get the suggestion box that looks like the search bar suggestion box. — Джек (обс.) 16:43, 22 ноября 2018 (UTC)[ответить]

@Джек: Нужно ещё в верхний комментарий приписать, что код дополнен by User:TJones (WMF), в т.ч. добавлена работа в основном поле поиска на странице Special:Search --Kaganer (обс.) 21:05, 21 ноября 2018 (UTC)[ответить]

Почему он отсутствует в настройках?

[править код]

А почему гаджет отсутствует в настройках? И через кнопку "Включить" на его странице описания не включается, пришлось прямо подключать через common.js... →ʙᴏʀᴏᴅᴜɴ 18:55, 21 ноября 2018 (UTC)[ответить]